File tree Expand file tree Collapse file tree 2 files changed +13
-67
lines changed
crates/rust-analyzer/src/diagnostics Expand file tree Collapse file tree 2 files changed +13
-67
lines changed Original file line number Diff line number Diff line change 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]
Original file line number Diff line number Diff line change 22//! `cargo check` json format to the LSP diagnostic format.
33use std:: collections:: HashMap ;
44
5- use flycheck:: { DiagnosticLevel , DiagnosticSpan } ;
5+ use flycheck:: { Applicability , DiagnosticLevel , DiagnosticSpan } ;
66use itertools:: Itertools ;
77use stdx:: format_to;
88use 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
You can’t perform that action at this time.
0 commit comments