Don't emit a quickfix for placeholder suggestions

This commit is contained in:
Jonas Schievink 2022-04-25 15:21:30 +02:00
parent 1d2bd0e379
commit 36342b4b29
2 changed files with 13 additions and 67 deletions

View File

@ -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,
},
]

View File

@ -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);
}
}
}