diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e8d53d4248a..b10b13a1f18b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -255,6 +255,10 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b - Fix a case where CSS files weren't correctly linted using the default configuration. Contributed by @ematipico +#### Bug fixes + +- Fix [#4116](https://github.com/biomejs/biome/issues/4116). Unify LSP code action kinds. Contributed by @vitallium + ### Formatter #### Bug fixes diff --git a/crates/biome_analyze/src/lib.rs b/crates/biome_analyze/src/lib.rs index 69f48c157168..dbcd7168fb8d 100644 --- a/crates/biome_analyze/src/lib.rs +++ b/crates/biome_analyze/src/lib.rs @@ -25,7 +25,7 @@ pub use biome_diagnostics::category_concat; pub use crate::categories::{ ActionCategory, RefactorKind, RuleCategories, RuleCategoriesBuilder, RuleCategory, - SourceActionKind, + SourceActionKind, SUPPRESSION_ACTION_CATEGORY, }; pub use crate::diagnostics::{AnalyzerDiagnostic, RuleError, SuppressionDiagnostic}; pub use crate::matcher::{InspectMatcher, MatchQueryParams, QueryMatcher, RuleKey, SignalEntry}; diff --git a/crates/biome_lsp/src/capabilities.rs b/crates/biome_lsp/src/capabilities.rs index 899f25ef68ba..e9c559d49a60 100644 --- a/crates/biome_lsp/src/capabilities.rs +++ b/crates/biome_lsp/src/capabilities.rs @@ -1,4 +1,5 @@ use crate::converters::{negotiated_encoding, PositionEncoding, WideEncoding}; +use biome_analyze::SUPPRESSION_ACTION_CATEGORY; use tower_lsp::lsp_types::{ ClientCapabilities, CodeActionKind, CodeActionOptions, CodeActionProviderCapability, DocumentOnTypeFormattingOptions, OneOf, PositionEncodingKind, ServerCapabilities, @@ -60,8 +61,14 @@ pub(crate) fn server_capabilities(capabilities: &ClientCapabilities) -> ServerCa CodeActionOptions { code_action_kinds: Some(vec![ CodeActionKind::from("quickfix.biome"), + // quickfix.suppressRule + CodeActionKind::from(SUPPRESSION_ACTION_CATEGORY), CodeActionKind::from("source.fixAll.biome"), CodeActionKind::from("source.organizeImports.biome"), + CodeActionKind::from("refactor.biome"), + CodeActionKind::from("refactor.extract.biome"), + CodeActionKind::from("refactor.inline.biome"), + CodeActionKind::from("refactor.rewrite.biome"), ]), ..Default::default() } diff --git a/crates/biome_lsp/src/utils.rs b/crates/biome_lsp/src/utils.rs index 76798529fa29..7d9fb52ce598 100644 --- a/crates/biome_lsp/src/utils.rs +++ b/crates/biome_lsp/src/utils.rs @@ -128,18 +128,7 @@ pub(crate) fn code_fix_to_lsp( }) .unwrap_or_default(); - let kind = action.category.to_str(); - let mut kind = kind.into_owned(); - - if !matches!(action.category, ActionCategory::Source(_)) { - if let Some((group, rule)) = action.rule_name { - kind.push('.'); - kind.push_str(group.as_ref()); - kind.push('.'); - kind.push_str(rule.as_ref()); - } - } - + let kind = action.category.to_str().into_owned(); let suggestion = action.suggestion; let mut changes = HashMap::new(); diff --git a/crates/biome_lsp/tests/server.rs b/crates/biome_lsp/tests/server.rs index efd4f9ebb7c3..8ed0acbd37c5 100644 --- a/crates/biome_lsp/tests/server.rs +++ b/crates/biome_lsp/tests/server.rs @@ -922,9 +922,7 @@ async fn pull_quick_fixes() -> Result<()> { let expected_code_action = lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction { title: String::from("Replace -0 with 0"), - kind: Some(lsp::CodeActionKind::new( - "quickfix.biome.suspicious.noCompareNegZero", - )), + kind: Some(lsp::CodeActionKind::new("quickfix.biome")), diagnostics: Some(vec![fixable_diagnostic(0)?]), edit: Some(lsp::WorkspaceEdit { changes: Some(changes), @@ -959,9 +957,7 @@ async fn pull_quick_fixes() -> Result<()> { let expected_suppression_action = lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction { title: String::from("Suppress rule lint/suspicious/noCompareNegZero"), - kind: Some(lsp::CodeActionKind::new( - "quickfix.suppressRule.biome.suspicious.noCompareNegZero", - )), + kind: Some(lsp::CodeActionKind::new("quickfix.suppressRule.biome")), diagnostics: Some(vec![fixable_diagnostic(0)?]), edit: Some(lsp::WorkspaceEdit { changes: Some(suppression_changes), @@ -1135,9 +1131,7 @@ async fn pull_biome_quick_fixes() -> Result<()> { let expected_code_action = lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction { title: String::from("Replace -0 with 0"), - kind: Some(lsp::CodeActionKind::new( - "quickfix.biome.suspicious.noCompareNegZero", - )), + kind: Some(lsp::CodeActionKind::new("quickfix.biome")), diagnostics: Some(vec![fixable_diagnostic(0)?]), edit: Some(lsp::WorkspaceEdit { changes: Some(changes), @@ -1252,9 +1246,7 @@ async fn pull_quick_fixes_include_unsafe() -> Result<()> { let expected_code_action = lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction { title: String::from("Use ==="), - kind: Some(lsp::CodeActionKind::new( - "quickfix.biome.suspicious.noDoubleEquals", - )), + kind: Some(lsp::CodeActionKind::new("quickfix.biome")), diagnostics: Some(vec![unsafe_fixable.clone()]), edit: Some(lsp::WorkspaceEdit { changes: Some(changes), @@ -1289,9 +1281,7 @@ async fn pull_quick_fixes_include_unsafe() -> Result<()> { let expected_suppression_action = lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction { title: String::from("Suppress rule lint/suspicious/noDoubleEquals"), - kind: Some(lsp::CodeActionKind::new( - "quickfix.suppressRule.biome.suspicious.noDoubleEquals", - )), + kind: Some(lsp::CodeActionKind::new("quickfix.suppressRule.biome")), diagnostics: Some(vec![unsafe_fixable]), edit: Some(lsp::WorkspaceEdit { changes: Some(suppression_changes), @@ -1922,9 +1912,7 @@ async fn pull_refactors() -> Result<()> { let _expected_action = lsp::CodeActionOrCommand::CodeAction(lsp::CodeAction { title: String::from("Inline variable"), - kind: Some(lsp::CodeActionKind::new( - "refactor.inline.biome.correctness.inlineVariable", - )), + kind: Some(lsp::CodeActionKind::new("refactor.inline.biome")), diagnostics: None, edit: Some(lsp::WorkspaceEdit { changes: Some(changes),