Skip to content

Commit 96da53f

Browse files
committed
Only include machine-applicable suggestions
1 parent 655b4f1 commit 96da53f

File tree

2 files changed

+26
-40
lines changed

2 files changed

+26
-40
lines changed

crates/ra_cargo_watch/src/conv.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! This module provides the functionality needed to convert diagnostics from
22
//! `cargo check` json format to the LSP diagnostic format.
33
use cargo_metadata::diagnostic::{
4-
Diagnostic as RustDiagnostic, DiagnosticLevel, DiagnosticSpan, DiagnosticSpanMacroExpansion,
4+
Applicability, Diagnostic as RustDiagnostic, DiagnosticLevel, DiagnosticSpan,
5+
DiagnosticSpanMacroExpansion,
56
};
67
use lsp_types::{
78
CodeAction, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag,
@@ -136,10 +137,13 @@ fn map_rust_child_diagnostic(
136137

137138
let mut edit_map: HashMap<Url, Vec<TextEdit>> = HashMap::new();
138139
for &span in &spans {
139-
if let Some(suggested_replacement) = &span.suggested_replacement {
140-
let location = map_span_to_location(span, workspace_root);
141-
let edit = TextEdit::new(location.range, suggested_replacement.clone());
142-
edit_map.entry(location.uri).or_default().push(edit);
140+
match (&span.suggestion_applicability, &span.suggested_replacement) {
141+
(Some(Applicability::MachineApplicable), Some(suggested_replacement)) => {
142+
let location = map_span_to_location(span, workspace_root);
143+
let edit = TextEdit::new(location.range, suggested_replacement.clone());
144+
edit_map.entry(location.uri).or_default().push(edit);
145+
}
146+
_ => {}
143147
}
144148
}
145149

crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_clippy_pass_by_ref.snap

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -58,44 +58,26 @@ expression: diag
5858
},
5959
message: "lint level defined here",
6060
},
61+
DiagnosticRelatedInformation {
62+
location: Location {
63+
uri: "file:///test/compiler/mir/tagset.rs",
64+
range: Range {
65+
start: Position {
66+
line: 41,
67+
character: 23,
68+
},
69+
end: Position {
70+
line: 41,
71+
character: 28,
72+
},
73+
},
74+
},
75+
message: "consider passing by value instead",
76+
},
6177
],
6278
),
6379
tags: None,
6480
},
65-
fixes: [
66-
CodeAction {
67-
title: "consider passing by value instead",
68-
kind: Some(
69-
"quickfix",
70-
),
71-
diagnostics: None,
72-
edit: Some(
73-
WorkspaceEdit {
74-
changes: Some(
75-
{
76-
"file:///test/compiler/mir/tagset.rs": [
77-
TextEdit {
78-
range: Range {
79-
start: Position {
80-
line: 41,
81-
character: 23,
82-
},
83-
end: Position {
84-
line: 41,
85-
character: 28,
86-
},
87-
},
88-
new_text: "self",
89-
},
90-
],
91-
},
92-
),
93-
document_changes: None,
94-
},
95-
),
96-
command: None,
97-
is_preferred: None,
98-
},
99-
],
81+
fixes: [],
10082
},
10183
]

0 commit comments

Comments
 (0)