From d7cd88b1a2169e50140730db4bd451350367e5ff Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Sat, 11 Jul 2020 19:12:42 -0400 Subject: Mark machine applicable fixes as preferred This allows us to run the auto fix command from vscode to automatically fix all diagnostics in the file. They are also distinguished in the UI. --- crates/rust-analyzer/src/diagnostics/to_proto.rs | 1 + crates/rust-analyzer/src/handlers.rs | 1 + crates/rust-analyzer/src/lsp_ext.rs | 3 +++ crates/rust-analyzer/src/to_proto.rs | 1 + crates/rust-analyzer/test_data/rustc_unused_variable.txt | 3 +++ crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt | 3 +++ crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt | 3 +++ crates/rust-analyzer/test_data/snap_multi_line_fix.txt | 3 +++ crates/rust-analyzer/tests/heavy_tests/main.rs | 2 ++ 9 files changed, 20 insertions(+) diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs index 7be3ef984..97f331352 100644 --- a/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs @@ -118,6 +118,7 @@ fn map_rust_child_diagnostic( changes: Some(edit_map), document_changes: None, }), + is_preferred: Some(true), }) } } diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index d28c700f1..42f21289a 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -775,6 +775,7 @@ fn handle_fixes( group: None, kind: Some(CodeActionKind::QUICKFIX), edit: Some(edit), + is_preferred: Some(false), }; res.push(action); } diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index e216966a9..13ebb18fb 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs @@ -243,6 +243,7 @@ impl Request for CodeActionRequest { } #[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] pub struct CodeAction { pub title: String, #[serde(skip_serializing_if = "Option::is_none")] @@ -256,6 +257,8 @@ pub struct CodeAction { // pub command: Option, #[serde(skip_serializing_if = "Option::is_none")] pub edit: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub is_preferred: Option, } #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 2fcae9ca3..e60537fcd 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -652,6 +652,7 @@ pub(crate) fn unresolved_code_action( group: assist.group.filter(|_| snap.config.client_caps.code_action_group).map(|gr| gr.0), kind: Some(code_action_kind(assist.id.1)), edit: None, + is_preferred: None, }; Ok(res) } diff --git a/crates/rust-analyzer/test_data/rustc_unused_variable.txt b/crates/rust-analyzer/test_data/rustc_unused_variable.txt index 084632757..74d91bc77 100644 --- a/crates/rust-analyzer/test_data/rustc_unused_variable.txt +++ b/crates/rust-analyzer/test_data/rustc_unused_variable.txt @@ -65,6 +65,9 @@ document_changes: None, }, ), + is_preferred: Some( + true, + ), }, ], }, diff --git a/crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt b/crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt index d637923c5..8a420c949 100644 --- a/crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt +++ b/crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt @@ -65,6 +65,9 @@ document_changes: None, }, ), + is_preferred: Some( + true, + ), }, ], }, diff --git a/crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt b/crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt index 6b48f16ed..79910660b 100644 --- a/crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt +++ b/crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt @@ -65,6 +65,9 @@ document_changes: None, }, ), + is_preferred: Some( + true, + ), }, ], }, diff --git a/crates/rust-analyzer/test_data/snap_multi_line_fix.txt b/crates/rust-analyzer/test_data/snap_multi_line_fix.txt index 2c4cbea16..4f811ab64 100644 --- a/crates/rust-analyzer/test_data/snap_multi_line_fix.txt +++ b/crates/rust-analyzer/test_data/snap_multi_line_fix.txt @@ -93,6 +93,9 @@ document_changes: None, }, ), + is_preferred: Some( + true, + ), }, ], }, diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs index 7b908d30c..f12e5a37f 100644 --- a/crates/rust-analyzer/tests/heavy_tests/main.rs +++ b/crates/rust-analyzer/tests/heavy_tests/main.rs @@ -284,6 +284,7 @@ fn main() {} } ] }, + "isPreferred": false, "kind": "quickfix", "title": "Create module" }]), @@ -355,6 +356,7 @@ fn main() {{}} } ] }, + "isPreferred": false, "kind": "quickfix", "title": "Create module" }]), -- cgit v1.2.3