about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-01-03 14:47:18 +0000
committerbors <bors@rust-lang.org>2023-01-03 14:47:18 +0000
commita97c71f92d574cb5104e3e1246eb9038d1a214a2 (patch)
tree5188e2011c7340c81f02270cffa2d8d476d1cc73
parent0b14cd96711579816eb0abbf2a352b90c9a64531 (diff)
parentb6bb1e9ae777d54da910885cc1437f7660d987a4 (diff)
downloadrust-a97c71f92d574cb5104e3e1246eb9038d1a214a2.tar.gz
rust-a97c71f92d574cb5104e3e1246eb9038d1a214a2.zip
Auto merge of #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.
-rw-r--r--crates/rust-analyzer/src/diagnostics/to_proto.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs
index d1ee99af3ec..80be43fe80a 100644
--- a/crates/rust-analyzer/src/diagnostics/to_proto.rs
+++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs
@@ -191,6 +191,7 @@ fn map_rust_child_diagnostic(
 
     let mut edit_map: HashMap<lsp_types::Url, Vec<lsp_types::TextEdit>> = HashMap::new();
     let mut suggested_replacements = Vec::new();
+    let mut is_preferred = true;
     for &span in &spans {
         if let Some(suggested_replacement) = &span.suggested_replacement {
             if !suggested_replacement.is_empty() {
@@ -209,6 +210,8 @@ fn map_rust_child_diagnostic(
             ) {
                 edit_map.entry(location.uri).or_default().push(edit);
             }
+            is_preferred &=
+                matches!(span.suggestion_applicability, Some(Applicability::MachineApplicable));
         }
     }
 
@@ -251,7 +254,7 @@ fn map_rust_child_diagnostic(
                         document_changes: None,
                         change_annotations: None,
                     }),
-                    is_preferred: Some(true),
+                    is_preferred: Some(is_preferred),
                     data: None,
                     command: None,
                 },