Skip to content

Commit 6869491

Browse files
committed
Auto merge of rust-lang#12075 - jonas-schievink:less-aggressive-quickfixes, r=jonas-schievink
fix: Don't emit a quickfix for placeholder suggestions from rustc/clippy Fixes rust-lang/rust-analyzer#12069
2 parents 60c4f07 + 36342b4 commit 6869491

File tree

2 files changed

+13
-67
lines changed

2 files changed

+13
-67
lines changed

crates/rust-analyzer/src/diagnostics/test_data/clippy_pass_by_ref.txt

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -296,70 +296,6 @@
296296
tags: None,
297297
data: None,
298298
},
299-
fix: Some(
300-
Fix {
301-
ranges: [
302-
Range {
303-
start: Position {
304-
line: 41,
305-
character: 23,
306-
},
307-
end: Position {
308-
line: 41,
309-
character: 28,
310-
},
311-
},
312-
],
313-
action: CodeAction {
314-
title: "consider passing by value instead: `self`",
315-
group: None,
316-
kind: Some(
317-
CodeActionKind(
318-
"quickfix",
319-
),
320-
),
321-
command: None,
322-
edit: Some(
323-
SnippetWorkspaceEdit {
324-
changes: Some(
325-
{
326-
Url {
327-
scheme: "file",
328-
cannot_be_a_base: false,
329-
username: "",
330-
password: None,
331-
host: None,
332-
port: None,
333-
path: "/test/compiler/mir/tagset.rs",
334-
query: None,
335-
fragment: None,
336-
}: [
337-
TextEdit {
338-
range: Range {
339-
start: Position {
340-
line: 41,
341-
character: 23,
342-
},
343-
end: Position {
344-
line: 41,
345-
character: 28,
346-
},
347-
},
348-
new_text: "self",
349-
},
350-
],
351-
},
352-
),
353-
document_changes: None,
354-
change_annotations: None,
355-
},
356-
),
357-
is_preferred: Some(
358-
true,
359-
),
360-
data: None,
361-
},
362-
},
363-
),
299+
fix: None,
364300
},
365301
]

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! `cargo check` json format to the LSP diagnostic format.
33
use std::collections::HashMap;
44

5-
use flycheck::{DiagnosticLevel, DiagnosticSpan};
5+
use flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan};
66
use itertools::Itertools;
77
use stdx::format_to;
88
use vfs::{AbsPath, AbsPathBuf};
@@ -159,7 +159,17 @@ fn map_rust_child_diagnostic(
159159
}
160160
let location = location(config, workspace_root, span);
161161
let edit = lsp_types::TextEdit::new(location.range, suggested_replacement.clone());
162-
edit_map.entry(location.uri).or_default().push(edit);
162+
163+
// Only actually emit a quickfix if the suggestion is "valid enough".
164+
// We accept both "MaybeIncorrect" and "MachineApplicable". "MaybeIncorrect" means that
165+
// the suggestion is *complete* (contains no placeholders where code needs to be
166+
// inserted), but might not be what the user wants, or might need minor adjustments.
167+
if matches!(
168+
span.suggestion_applicability,
169+
None | Some(Applicability::MaybeIncorrect | Applicability::MachineApplicable)
170+
) {
171+
edit_map.entry(location.uri).or_default().push(edit);
172+
}
163173
}
164174
}
165175

0 commit comments

Comments
 (0)