3681: Only include machine-applicable suggestions r=kiljacken a=lnicola

Fixes #3676
Fixes #3633
Fixes #3391 

r? @kiljacken

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
bors[bot] 2020-03-23 11:41:32 +00:00 committed by GitHub
commit c7a2052e73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 40 deletions

View File

@ -1,7 +1,8 @@
//! This module provides the functionality needed to convert diagnostics from
//! `cargo check` json format to the LSP diagnostic format.
use cargo_metadata::diagnostic::{
Diagnostic as RustDiagnostic, DiagnosticLevel, DiagnosticSpan, DiagnosticSpanMacroExpansion,
Applicability, Diagnostic as RustDiagnostic, DiagnosticLevel, DiagnosticSpan,
DiagnosticSpanMacroExpansion,
};
use lsp_types::{
CodeAction, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag,
@ -136,10 +137,13 @@ fn map_rust_child_diagnostic(
let mut edit_map: HashMap<Url, Vec<TextEdit>> = HashMap::new();
for &span in &spans {
if let Some(suggested_replacement) = &span.suggested_replacement {
let location = map_span_to_location(span, workspace_root);
let edit = TextEdit::new(location.range, suggested_replacement.clone());
edit_map.entry(location.uri).or_default().push(edit);
match (&span.suggestion_applicability, &span.suggested_replacement) {
(Some(Applicability::MachineApplicable), Some(suggested_replacement)) => {
let location = map_span_to_location(span, workspace_root);
let edit = TextEdit::new(location.range, suggested_replacement.clone());
edit_map.entry(location.uri).or_default().push(edit);
}
_ => {}
}
}

View File

@ -58,44 +58,26 @@ expression: diag
},
message: "lint level defined here",
},
DiagnosticRelatedInformation {
location: Location {
uri: "file:///test/compiler/mir/tagset.rs",
range: Range {
start: Position {
line: 41,
character: 23,
},
end: Position {
line: 41,
character: 28,
},
},
},
message: "consider passing by value instead",
},
],
),
tags: None,
},
fixes: [
CodeAction {
title: "consider passing by value instead",
kind: Some(
"quickfix",
),
diagnostics: None,
edit: Some(
WorkspaceEdit {
changes: Some(
{
"file:///test/compiler/mir/tagset.rs": [
TextEdit {
range: Range {
start: Position {
line: 41,
character: 23,
},
end: Position {
line: 41,
character: 28,
},
},
new_text: "self",
},
],
},
),
document_changes: None,
},
),
command: None,
is_preferred: None,
},
],
fixes: [],
},
]