mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-15 22:54:00 +00:00
Don't emit a quickfix for placeholder suggestions
This commit is contained in:
parent
1d2bd0e379
commit
36342b4b29
2 changed files with 13 additions and 67 deletions
|
@ -296,70 +296,6 @@
|
||||||
tags: None,
|
tags: None,
|
||||||
data: None,
|
data: None,
|
||||||
},
|
},
|
||||||
fix: Some(
|
fix: None,
|
||||||
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,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//! `cargo check` json format to the LSP diagnostic format.
|
//! `cargo check` json format to the LSP diagnostic format.
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use flycheck::{DiagnosticLevel, DiagnosticSpan};
|
use flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use stdx::format_to;
|
use stdx::format_to;
|
||||||
use vfs::{AbsPath, AbsPathBuf};
|
use vfs::{AbsPath, AbsPathBuf};
|
||||||
|
@ -159,7 +159,17 @@ fn map_rust_child_diagnostic(
|
||||||
}
|
}
|
||||||
let location = location(config, workspace_root, span);
|
let location = location(config, workspace_root, span);
|
||||||
let edit = lsp_types::TextEdit::new(location.range, suggested_replacement.clone());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue