Only include machine-applicable suggestions
This commit is contained in:
parent
655b4f16f0
commit
96da53fc56
2 changed files with 26 additions and 40 deletions
|
|
@ -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);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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: [],
|
||||
},
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue