Skip to content

Commit

Permalink
fix(lsp): unify code actions capabilities (#4122)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitallium authored Oct 17, 2024
1 parent 30a016b commit 1303f99
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
7 changes: 7 additions & 0 deletions crates/biome_lsp/src/capabilities.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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()
}
Expand Down
13 changes: 1 addition & 12 deletions crates/biome_lsp/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
24 changes: 6 additions & 18 deletions crates/biome_lsp/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 1303f99

Please sign in to comment.