Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #12075 - jonas-schievink:less-aggressive-quickfixes, r=jonas-schievink
fix: Don't emit a quickfix for placeholder suggestions from rustc/clippy Fixes https://github.com/rust-lang/rust-analyzer/issues/12069
bors 2022-04-25
parent 60c4f07 · parent 36342b4 · commit 6869491
-rw-r--r--crates/rust-analyzer/src/diagnostics/test_data/clippy_pass_by_ref.txt66
-rw-r--r--crates/rust-analyzer/src/diagnostics/to_proto.rs14
2 files changed, 13 insertions, 67 deletions
diff --git a/crates/rust-analyzer/src/diagnostics/test_data/clippy_pass_by_ref.txt b/crates/rust-analyzer/src/diagnostics/test_data/clippy_pass_by_ref.txt
index 41c509452a..c3b540e31f 100644
--- a/crates/rust-analyzer/src/diagnostics/test_data/clippy_pass_by_ref.txt
+++ b/crates/rust-analyzer/src/diagnostics/test_data/clippy_pass_by_ref.txt
@@ -296,70 +296,6 @@
tags: None,
data: None,
},
- fix: Some(
- Fix {
- ranges: [
- Range {
- start: Position {
- line: 41,
- character: 23,
- },
- end: Position {
- line: 41,
- character: 28,
- },
- },
- ],
- action: CodeAction {
- title: "consider passing by value instead: `self`",
- group: None,
- kind: Some(
- CodeActionKind(
- "quickfix",
- ),
- ),
- command: None,
- edit: Some(
- SnippetWorkspaceEdit {
- changes: Some(
- {
- Url {
- scheme: "file",
- cannot_be_a_base: false,
- username: "",
- password: None,
- host: None,
- port: None,
- path: "/test/compiler/mir/tagset.rs",
- query: None,
- fragment: None,
- }: [
- TextEdit {
- range: Range {
- start: Position {
- line: 41,
- character: 23,
- },
- end: Position {
- line: 41,
- character: 28,
- },
- },
- new_text: "self",
- },
- ],
- },
- ),
- document_changes: None,
- change_annotations: None,
- },
- ),
- is_preferred: Some(
- true,
- ),
- data: None,
- },
- },
- ),
+ fix: None,
},
]
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs
index e9a192cdfb..4b78055656 100644
--- a/crates/rust-analyzer/src/diagnostics/to_proto.rs
+++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs
@@ -2,7 +2,7 @@
//! `cargo check` json format to the LSP diagnostic format.
use std::collections::HashMap;
-use flycheck::{DiagnosticLevel, DiagnosticSpan};
+use flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan};
use itertools::Itertools;
use stdx::format_to;
use vfs::{AbsPath, AbsPathBuf};
@@ -159,7 +159,17 @@ fn map_rust_child_diagnostic(
}
let location = location(config, workspace_root, span);
let edit = lsp_types::TextEdit::new(location.range, suggested_replacement.clone());
- edit_map.entry(location.uri).or_default().push(edit);
+
+ // Only actually emit a quickfix if the suggestion is "valid enough".
+ // We accept both "MaybeIncorrect" and "MachineApplicable". "MaybeIncorrect" means that
+ // the suggestion is *complete* (contains no placeholders where code needs to be
+ // inserted), but might not be what the user wants, or might need minor adjustments.
+ if matches!(
+ span.suggestion_applicability,
+ None | Some(Applicability::MaybeIncorrect | Applicability::MachineApplicable)
+ ) {
+ edit_map.entry(location.uri).or_default().push(edit);
+ }
}
}