Skip to content

fix: Don't emit a quickfix for placeholder suggestions from rustc/clippy #12075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
]
14 changes: 12 additions & 2 deletions crates/rust-analyzer/src/diagnostics/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
}
}
}

Expand Down