Skip to content

Commit 2ca0e9e

Browse files
bors[bot]kjeremy
andauthored
Merge #5327
5327: Mark fixes from check as preferred r=matklad a=kjeremy This allows us to run the auto fix command from vscode to automatically fix diagnostics in the file. They are also distinguished in the UI. Co-authored-by: Jeremy Kolb <[email protected]>
2 parents 9b5ac1d + d7cd88b commit 2ca0e9e

File tree

9 files changed

+20
-0
lines changed

9 files changed

+20
-0
lines changed

crates/rust-analyzer/src/diagnostics/to_proto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ fn map_rust_child_diagnostic(
118118
changes: Some(edit_map),
119119
document_changes: None,
120120
}),
121+
is_preferred: Some(true),
121122
})
122123
}
123124
}

crates/rust-analyzer/src/handlers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ fn handle_fixes(
770770
group: None,
771771
kind: Some(CodeActionKind::QUICKFIX),
772772
edit: Some(edit),
773+
is_preferred: Some(false),
773774
};
774775
res.push(action);
775776
}

crates/rust-analyzer/src/lsp_ext.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ impl Request for CodeActionRequest {
243243
}
244244

245245
#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
246+
#[serde(rename_all = "camelCase")]
246247
pub struct CodeAction {
247248
pub title: String,
248249
#[serde(skip_serializing_if = "Option::is_none")]
@@ -256,6 +257,8 @@ pub struct CodeAction {
256257
// pub command: Option<lsp_types::Command>,
257258
#[serde(skip_serializing_if = "Option::is_none")]
258259
pub edit: Option<SnippetWorkspaceEdit>,
260+
#[serde(skip_serializing_if = "Option::is_none")]
261+
pub is_preferred: Option<bool>,
259262
}
260263

261264
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]

crates/rust-analyzer/src/to_proto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ pub(crate) fn unresolved_code_action(
689689
group: assist.group.filter(|_| snap.config.client_caps.code_action_group).map(|gr| gr.0),
690690
kind: Some(code_action_kind(assist.id.1)),
691691
edit: None,
692+
is_preferred: None,
692693
};
693694
Ok(res)
694695
}

crates/rust-analyzer/test_data/rustc_unused_variable.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
document_changes: None,
6666
},
6767
),
68+
is_preferred: Some(
69+
true,
70+
),
6871
},
6972
],
7073
},

crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
document_changes: None,
6666
},
6767
),
68+
is_preferred: Some(
69+
true,
70+
),
6871
},
6972
],
7073
},

crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
document_changes: None,
6666
},
6767
),
68+
is_preferred: Some(
69+
true,
70+
),
6871
},
6972
],
7073
},

crates/rust-analyzer/test_data/snap_multi_line_fix.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
document_changes: None,
9494
},
9595
),
96+
is_preferred: Some(
97+
true,
98+
),
9699
},
97100
],
98101
},

crates/rust-analyzer/tests/heavy_tests/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ fn main() {}
284284
}
285285
]
286286
},
287+
"isPreferred": false,
287288
"kind": "quickfix",
288289
"title": "Create module"
289290
}]),
@@ -355,6 +356,7 @@ fn main() {{}}
355356
}
356357
]
357358
},
359+
"isPreferred": false,
358360
"kind": "quickfix",
359361
"title": "Create module"
360362
}]),

0 commit comments

Comments
 (0)