Skip to content

Commit 1303f99

Browse files
authored
fix(lsp): unify code actions capabilities (#4122)
1 parent 30a016b commit 1303f99

File tree

5 files changed

+19
-31
lines changed

5 files changed

+19
-31
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
255255

256256
- Fix a case where CSS files weren't correctly linted using the default configuration. Contributed by @ematipico
257257

258+
#### Bug fixes
259+
260+
- Fix [#4116](https://github.com/biomejs/biome/issues/4116). Unify LSP code action kinds. Contributed by @vitallium
261+
258262
### Formatter
259263

260264
#### Bug fixes

crates/biome_analyze/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub use biome_diagnostics::category_concat;
2525

2626
pub use crate::categories::{
2727
ActionCategory, RefactorKind, RuleCategories, RuleCategoriesBuilder, RuleCategory,
28-
SourceActionKind,
28+
SourceActionKind, SUPPRESSION_ACTION_CATEGORY,
2929
};
3030
pub use crate::diagnostics::{AnalyzerDiagnostic, RuleError, SuppressionDiagnostic};
3131
pub use crate::matcher::{InspectMatcher, MatchQueryParams, QueryMatcher, RuleKey, SignalEntry};

crates/biome_lsp/src/capabilities.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::converters::{negotiated_encoding, PositionEncoding, WideEncoding};
2+
use biome_analyze::SUPPRESSION_ACTION_CATEGORY;
23
use tower_lsp::lsp_types::{
34
ClientCapabilities, CodeActionKind, CodeActionOptions, CodeActionProviderCapability,
45
DocumentOnTypeFormattingOptions, OneOf, PositionEncodingKind, ServerCapabilities,
@@ -60,8 +61,14 @@ pub(crate) fn server_capabilities(capabilities: &ClientCapabilities) -> ServerCa
6061
CodeActionOptions {
6162
code_action_kinds: Some(vec![
6263
CodeActionKind::from("quickfix.biome"),
64+
// quickfix.suppressRule
65+
CodeActionKind::from(SUPPRESSION_ACTION_CATEGORY),
6366
CodeActionKind::from("source.fixAll.biome"),
6467
CodeActionKind::from("source.organizeImports.biome"),
68+
CodeActionKind::from("refactor.biome"),
69+
CodeActionKind::from("refactor.extract.biome"),
70+
CodeActionKind::from("refactor.inline.biome"),
71+
CodeActionKind::from("refactor.rewrite.biome"),
6572
]),
6673
..Default::default()
6774
}

crates/biome_lsp/src/utils.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,7 @@ pub(crate) fn code_fix_to_lsp(
128128
})
129129
.unwrap_or_default();
130130

131-
let kind = action.category.to_str();
132-
let mut kind = kind.into_owned();
133-
134-
if !matches!(action.category, ActionCategory::Source(_)) {
135-
if let Some((group, rule)) = action.rule_name {
136-
kind.push('.');
137-
kind.push_str(group.as_ref());
138-
kind.push('.');
139-
kind.push_str(rule.as_ref());
140-
}
141-
}
142-
131+
let kind = action.category.to_str().into_owned();
143132
let suggestion = action.suggestion;
144133

145134
let mut changes = HashMap::new();

crates/biome_lsp/tests/server.rs

+6-18
Original file line numberDiff line numberDiff line change
@@ -922,9 +922,7 @@ async fn pull_quick_fixes() -> Result<()> {
922922

923923
let expected_code_action = lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction {
924924
title: String::from("Replace -0 with 0"),
925-
kind: Some(lsp::CodeActionKind::new(
926-
"quickfix.biome.suspicious.noCompareNegZero",
927-
)),
925+
kind: Some(lsp::CodeActionKind::new("quickfix.biome")),
928926
diagnostics: Some(vec![fixable_diagnostic(0)?]),
929927
edit: Some(lsp::WorkspaceEdit {
930928
changes: Some(changes),
@@ -959,9 +957,7 @@ async fn pull_quick_fixes() -> Result<()> {
959957

960958
let expected_suppression_action = lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction {
961959
title: String::from("Suppress rule lint/suspicious/noCompareNegZero"),
962-
kind: Some(lsp::CodeActionKind::new(
963-
"quickfix.suppressRule.biome.suspicious.noCompareNegZero",
964-
)),
960+
kind: Some(lsp::CodeActionKind::new("quickfix.suppressRule.biome")),
965961
diagnostics: Some(vec![fixable_diagnostic(0)?]),
966962
edit: Some(lsp::WorkspaceEdit {
967963
changes: Some(suppression_changes),
@@ -1135,9 +1131,7 @@ async fn pull_biome_quick_fixes() -> Result<()> {
11351131

11361132
let expected_code_action = lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction {
11371133
title: String::from("Replace -0 with 0"),
1138-
kind: Some(lsp::CodeActionKind::new(
1139-
"quickfix.biome.suspicious.noCompareNegZero",
1140-
)),
1134+
kind: Some(lsp::CodeActionKind::new("quickfix.biome")),
11411135
diagnostics: Some(vec![fixable_diagnostic(0)?]),
11421136
edit: Some(lsp::WorkspaceEdit {
11431137
changes: Some(changes),
@@ -1252,9 +1246,7 @@ async fn pull_quick_fixes_include_unsafe() -> Result<()> {
12521246

12531247
let expected_code_action = lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction {
12541248
title: String::from("Use ==="),
1255-
kind: Some(lsp::CodeActionKind::new(
1256-
"quickfix.biome.suspicious.noDoubleEquals",
1257-
)),
1249+
kind: Some(lsp::CodeActionKind::new("quickfix.biome")),
12581250
diagnostics: Some(vec![unsafe_fixable.clone()]),
12591251
edit: Some(lsp::WorkspaceEdit {
12601252
changes: Some(changes),
@@ -1289,9 +1281,7 @@ async fn pull_quick_fixes_include_unsafe() -> Result<()> {
12891281

12901282
let expected_suppression_action = lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction {
12911283
title: String::from("Suppress rule lint/suspicious/noDoubleEquals"),
1292-
kind: Some(lsp::CodeActionKind::new(
1293-
"quickfix.suppressRule.biome.suspicious.noDoubleEquals",
1294-
)),
1284+
kind: Some(lsp::CodeActionKind::new("quickfix.suppressRule.biome")),
12951285
diagnostics: Some(vec![unsafe_fixable]),
12961286
edit: Some(lsp::WorkspaceEdit {
12971287
changes: Some(suppression_changes),
@@ -1922,9 +1912,7 @@ async fn pull_refactors() -> Result<()> {
19221912

19231913
let _expected_action = lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction {
19241914
title: String::from("Inline variable"),
1925-
kind: Some(lsp::CodeActionKind::new(
1926-
"refactor.inline.biome.correctness.inlineVariable",
1927-
)),
1915+
kind: Some(lsp::CodeActionKind::new("refactor.inline.biome")),
19281916
diagnostics: None,
19291917
edit: Some(lsp::WorkspaceEdit {
19301918
changes: Some(changes),

0 commit comments

Comments
 (0)