Skip to content

Commit

Permalink
fix(lsp): code actions capabilities (#3971)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Sep 18, 2024
1 parent ad1a744 commit 756dd38
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- Fix [#3923](https://github.com/biomejs/biome/issues/3923). Now the `.editorconfig` is correctly parsed by the LSP, and the options are correctly applied to files when formatting is triggered.
Plus, the Biome LSP now watches for any change to the `.editorconfig`, and updates the formatting settings.

- Reduced the number of log files generated by the LSP server. Now the maximum number of logs saved on disk is **seven**. Contributed by @ematipico
- Fix the code actions capabilities available in the LSP Biome server. Before, the LSP was using the default capabilities, which resulted in pulling code actions even when they were disabled by the editor.

This means that the code actions are pulled by the client **only** when the editor enables `quickfix.biome`, `source.organizeImports.biome` and `source.fixAll.biome`.

Now, if you enable `organizeImports.enabled: true` in the `biome.json`, and then you configure your editor with the following code action `source.organizeImports.biome: false`, the editor **won't** sort the imports.

Contributed by @ematipico

### Formatter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use biome_graphql_syntax::GraphqlDirective;
use biome_rowan::AstNode;

declare_lint_rule! {
/// Require specifying the reason argument when using @deprecated directive
/// Require specifying the reason argument when using `@deprecated` directive
///
/// This rule checks the parameter of @deprecated directive for the use of reason argument,
/// This rule checks the parameter of `@deprecated` directive for the use of reason argument,
/// suggesting user to add it in case the argument is missing.
///
/// ## Examples
Expand Down
24 changes: 21 additions & 3 deletions crates/biome_lsp/src/capabilities.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::converters::{negotiated_encoding, PositionEncoding, WideEncoding};
use tower_lsp::lsp_types::{
ClientCapabilities, CodeActionProviderCapability, DocumentOnTypeFormattingOptions, OneOf,
PositionEncodingKind, ServerCapabilities, TextDocumentSyncCapability, TextDocumentSyncKind,
ClientCapabilities, CodeActionKind, CodeActionOptions, CodeActionProviderCapability,
DocumentOnTypeFormattingOptions, OneOf, PositionEncodingKind, ServerCapabilities,
TextDocumentSyncCapability, TextDocumentSyncKind,
};

/// The capabilities to send from server as part of [`InitializeResult`]
Expand Down Expand Up @@ -50,6 +51,23 @@ pub(crate) fn server_capabilities(capabilities: &ClientCapabilities) -> ServerCa
}
});

let code_action_provider = capabilities
.text_document
.as_ref()
.and_then(|text_document| text_document.code_action.as_ref())
.and_then(|code_action| code_action.code_action_literal_support.as_ref())
.map(|_| {
CodeActionOptions {
code_action_kinds: Some(vec![
CodeActionKind::from("quickfix.biome"),
CodeActionKind::from("source.fixAll.biome"),
CodeActionKind::from("source.organizeImports.biome"),
]),
..Default::default()
}
.into()
})
.or(Some(CodeActionProviderCapability::Simple(true)));
ServerCapabilities {
position_encoding: Some(match negotiated_encoding(capabilities) {
PositionEncoding::Utf8 => PositionEncodingKind::UTF8,
Expand All @@ -64,7 +82,7 @@ pub(crate) fn server_capabilities(capabilities: &ClientCapabilities) -> ServerCa
document_formatting_provider: supports_formatter_dynamic_registration,
document_range_formatting_provider: supports_range_formatter_dynamic_registration,
document_on_type_formatting_provider: supports_on_type_formatter_dynamic_registration,
code_action_provider: Some(CodeActionProviderCapability::Simple(true)),
code_action_provider,
rename_provider: None,
..Default::default()
}
Expand Down

0 comments on commit 756dd38

Please sign in to comment.