Skip to content

Commit a97c71f

Browse files
committed
Auto merge of rust-lang#13887 - Veykril:rustc-diag-preferred, r=Veykril
Only set machine-applicable rustc diagnostics as preferred If they aren't machine applicable, then they might not be what the user wants, disrupting the workflow. Example being: ![image](https://user-images.githubusercontent.com/3757771/210380233-ae25aa04-954e-4634-8dd1-4377cc2bd837.png) Prior to the PR this the diagnostic quickfix was at the top, but usually isn't what the user wants.
2 parents 0b14cd9 + b6bb1e9 commit a97c71f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

crates/rust-analyzer/src/diagnostics/to_proto.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ fn map_rust_child_diagnostic(
191191

192192
let mut edit_map: HashMap<lsp_types::Url, Vec<lsp_types::TextEdit>> = HashMap::new();
193193
let mut suggested_replacements = Vec::new();
194+
let mut is_preferred = true;
194195
for &span in &spans {
195196
if let Some(suggested_replacement) = &span.suggested_replacement {
196197
if !suggested_replacement.is_empty() {
@@ -209,6 +210,8 @@ fn map_rust_child_diagnostic(
209210
) {
210211
edit_map.entry(location.uri).or_default().push(edit);
211212
}
213+
is_preferred &=
214+
matches!(span.suggestion_applicability, Some(Applicability::MachineApplicable));
212215
}
213216
}
214217

@@ -251,7 +254,7 @@ fn map_rust_child_diagnostic(
251254
document_changes: None,
252255
change_annotations: None,
253256
}),
254-
is_preferred: Some(true),
257+
is_preferred: Some(is_preferred),
255258
data: None,
256259
command: None,
257260
},

0 commit comments

Comments
 (0)