Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lsp): unify code actions capabilities #4122

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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"),
Comment on lines +68 to +71
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably these code actions are not available at all? Happy to remove them in this case.

]),
..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