Skip to content

Commit

Permalink
code action breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Oct 21, 2024
1 parent 9d67ec2 commit a8be40c
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 7 deletions.
35 changes: 35 additions & 0 deletions .changeset/the_action_quickfixsuppressrule_is_removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
cli: major
---

# Remove the code action `quickfix.suppressRule`

The code action `quickfix.suppressRule` was removed in favour of two new code actions:

- `quickfix.suppressRule.inline.biome`: a code action that adds a suppression comment for each violation.
- `quickfix.suppressRule.topLevel.biome`: a code action that adds a suppression comment at the top of the file which suppresses a rule for the whole file.


Given the following code
```js
let foo = "one";
debugger
```

The code action `quickfix.suppressRule.inline.biome` will result in the following code:
```js
// biome-ignore lint/style/useConst: <explanation>
let foo = "one";
// biome-ignore lint/suspicious/noDebugger: <explanation>
debugger
```

The code action `quickfix.suppressRule.topLevel.biome`, instead, will result in the following code:
```js
/** biome-ignore lint/suspicious/noDebugger: <explanation> */
/** biome-ignore lint/style/useConst: <explanation> */

let foo = "one";
debugger;
```

1 change: 0 additions & 1 deletion crates/biome_analyze/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub enum RuleCategory {
}

/// Actions that suppress rules should start with this string
pub const SUPPRESSION_ACTION_CATEGORY: &str = "quickfix.suppressRule";
pub const SUPPRESSION_INLINE_ACTION_CATEGORY: &str = "quickfix.suppressRule.inline";
pub const SUPPRESSION_TOP_LEVEL_ACTION_CATEGORY: &str = "quickfix.suppressRule.topLevel";

Expand Down
3 changes: 2 additions & 1 deletion crates/biome_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ pub use biome_diagnostics::category_concat;

pub use crate::categories::{
ActionCategory, OtherActionCategory, RefactorKind, RuleCategories, RuleCategoriesBuilder,
RuleCategory, SourceActionKind, SUPPRESSION_ACTION_CATEGORY,
RuleCategory, SourceActionKind, SUPPRESSION_INLINE_ACTION_CATEGORY,
SUPPRESSION_TOP_LEVEL_ACTION_CATEGORY,
};
pub use crate::diagnostics::{AnalyzerDiagnostic, AnalyzerSuppressionDiagnostic, RuleError};
pub use crate::matcher::{InspectMatcher, MatchQueryParams, QueryMatcher, RuleKey, SignalEntry};
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_js_analyze/src/suppression_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl SuppressionAction for JsSuppressionAction {
(TriviaPieceKind::Newline, "\n"),
]);

mutation.replace_token_transfer_trivia(token, new_token);
mutation.replace_token_discard_trivia(token, new_token);
}

fn find_token_for_inline_suppression(
Expand Down
5 changes: 3 additions & 2 deletions crates/biome_lsp/src/capabilities.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::converters::{negotiated_encoding, PositionEncoding, WideEncoding};
use biome_analyze::SUPPRESSION_ACTION_CATEGORY;
use biome_analyze::{SUPPRESSION_INLINE_ACTION_CATEGORY, SUPPRESSION_TOP_LEVEL_ACTION_CATEGORY};
use tower_lsp::lsp_types::{
ClientCapabilities, CodeActionKind, CodeActionOptions, CodeActionProviderCapability,
DocumentOnTypeFormattingOptions, OneOf, PositionEncodingKind, ServerCapabilities,
Expand Down Expand Up @@ -62,7 +62,8 @@ pub(crate) fn server_capabilities(capabilities: &ClientCapabilities) -> ServerCa
code_action_kinds: Some(vec![
CodeActionKind::from("quickfix.biome"),
// quickfix.suppressRule
CodeActionKind::from(SUPPRESSION_ACTION_CATEGORY),
CodeActionKind::from(SUPPRESSION_TOP_LEVEL_ACTION_CATEGORY),
CodeActionKind::from(SUPPRESSION_INLINE_ACTION_CATEGORY),
CodeActionKind::from("source.fixAll.biome"),
CodeActionKind::from("source.organizeImports.biome"),
CodeActionKind::from("refactor.biome"),
Expand Down
21 changes: 20 additions & 1 deletion crates/biome_lsp/src/handlers/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use crate::diagnostics::LspError;
use crate::session::Session;
use crate::utils;
use anyhow::{Context, Result};
use biome_analyze::{ActionCategory, RuleCategoriesBuilder, SourceActionKind};
use biome_analyze::{
ActionCategory, RuleCategoriesBuilder, SourceActionKind, SUPPRESSION_INLINE_ACTION_CATEGORY,
};
use biome_diagnostics::Applicability;
use biome_fs::BiomePath;
use biome_rowan::{TextRange, TextSize};
Expand Down Expand Up @@ -170,6 +172,23 @@ pub(crate) fn code_actions(
return None;
}

// Filter out suppressions if the linter isn't supported
if (action.category.matches(SUPPRESSION_INLINE_ACTION_CATEGORY)
|| action.category.matches(SUPPRESSION_INLINE_ACTION_CATEGORY))
&& !file_features.supports_lint()
{
return None;
}

// Filter out the suppressions if the client is requesting a fix all signal.
// Fix all should apply only the safe changes.
if has_fix_all
&& (action.category.matches(SUPPRESSION_INLINE_ACTION_CATEGORY)
|| action.category.matches(SUPPRESSION_INLINE_ACTION_CATEGORY))
{
return None;
}

// Filter out the refactor.* actions when assists are disabled
if action.category.matches("source") && !file_features.supports_assists() {
return None;
Expand Down
3 changes: 2 additions & 1 deletion crates/biome_service/src/file_handlers/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ pub(crate) fn code_actions(params: CodeActionsParams) -> PullActionsResult {
} = params;
debug_span!("Code actions JavaScript", range =? range, path =? path).in_scope(move || {
let tree = parse.tree();
trace_span!("Parsed file", tree =? tree).in_scope(move || {
trace_span!("Parsed file").in_scope(move || {
let analyzer_options = workspace.analyzer_options::<JsLanguage>(path, &language);
let mut actions = Vec::new();
let (enabled_rules, disabled_rules) =
Expand Down Expand Up @@ -582,6 +582,7 @@ pub(crate) fn code_actions(params: CodeActionsParams) -> PullActionsResult {
manifest,
|signal| {
actions.extend(signal.actions().into_code_action_iter().map(|item| {
trace!("Pulled action category {:?}", item.category);
CodeAction {
category: item.category.clone(),
rule_name: item
Expand Down

0 comments on commit a8be40c

Please sign in to comment.