diff --git a/apps/oxlint/src/lsp/code_actions.rs b/apps/oxlint/src/lsp/code_actions.rs index 60b21c0f8d0c1..d20321674e94c 100644 --- a/apps/oxlint/src/lsp/code_actions.rs +++ b/apps/oxlint/src/lsp/code_actions.rs @@ -2,7 +2,7 @@ use oxc_linter::FixKind; use tower_lsp_server::ls_types::{CodeAction, CodeActionKind, TextEdit, Uri, WorkspaceEdit}; use tracing::debug; -use crate::lsp::error_with_position::{FixedContent, LinterCodeAction}; +use crate::lsp::error_with_position::{FixedContent, FixedContentKind, LinterCodeAction}; pub const CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC: CodeActionKind = CodeActionKind::new("source.fixAll.oxc"); @@ -34,11 +34,19 @@ fn fix_content_to_code_action( pub fn apply_fix_code_actions(action: LinterCodeAction, uri: &Uri) -> Vec { let mut code_actions = vec![]; - // only the first code action is preferred - let mut preferred = true; + let mut preferred_possible = true; for fixed in action.fixed_content { + // only rule fixes and unused directive fixes can be preferred, ignore fixes are not preferred. + let preferred = preferred_possible + && matches!( + fixed.lsp_kind, + FixedContentKind::LintRule | FixedContentKind::UnusedDirective + ); + if preferred { + // only the first fix can be preferred, if there are multiple fixes available. + preferred_possible = false; + } let action = fix_content_to_code_action(fixed, uri.clone(), preferred); - preferred = false; code_actions.push(action); } diff --git a/apps/oxlint/src/lsp/error_with_position.rs b/apps/oxlint/src/lsp/error_with_position.rs index 6ba335bbe9b5f..6ebbc5160dc5c 100644 --- a/apps/oxlint/src/lsp/error_with_position.rs +++ b/apps/oxlint/src/lsp/error_with_position.rs @@ -30,12 +30,11 @@ pub struct FixedContent { pub code: String, pub range: Range, pub kind: FixKind, - #[expect(dead_code)] - lsp_kind: FixedContentKind, + pub lsp_kind: FixedContentKind, } -#[derive(Debug, Clone)] -enum FixedContentKind { +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum FixedContentKind { LintRule, IgnoreLintRuleLine, IgnoreLintRuleSection, diff --git a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_cross_module@dep-a.ts.snap b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_cross_module@dep-a.ts.snap index ed8ad74d1f06c..8edad88f859d3 100644 --- a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_cross_module@dep-a.ts.snap +++ b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_cross_module@dep-a.ts.snap @@ -21,7 +21,7 @@ tags: None ########### Code Actions/Commands CodeAction: Title: Disable import/no-cycle for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position { diff --git a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_cross_module_extended_config@dep-a.ts.snap b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_cross_module_extended_config@dep-a.ts.snap index aa33feb8a7e79..dd83909e929ad 100644 --- a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_cross_module_extended_config@dep-a.ts.snap +++ b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_cross_module_extended_config@dep-a.ts.snap @@ -21,7 +21,7 @@ tags: None ########### Code Actions/Commands CodeAction: Title: Disable import/no-cycle for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position { diff --git a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_cross_module_nested_config@dep-a.ts_folder__folder-dep-a.ts.snap b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_cross_module_nested_config@dep-a.ts_folder__folder-dep-a.ts.snap index 6e8f98be1a0a6..edee751b77d7b 100644 --- a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_cross_module_nested_config@dep-a.ts_folder__folder-dep-a.ts.snap +++ b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_cross_module_nested_config@dep-a.ts_folder__folder-dep-a.ts.snap @@ -31,7 +31,7 @@ tags: None ########### Code Actions/Commands CodeAction: Title: Disable import/no-cycle for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position { diff --git a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_deny_no_console@hello_world.js.snap b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_deny_no_console@hello_world.js.snap index 7870fc0e95a91..de99a4f2a6c13 100644 --- a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_deny_no_console@hello_world.js.snap +++ b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_deny_no_console@hello_world.js.snap @@ -21,7 +21,7 @@ tags: None ########### Code Actions/Commands CodeAction: Title: Disable no-console for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position { diff --git a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_frameworks@astro__debugger.astro_vue__debugger.vue_svelte__debugger.svelte_nextjs__[[..rest]]__debugger.ts.snap b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_frameworks@astro__debugger.astro_vue__debugger.vue_svelte__debugger.svelte_nextjs__[[..rest]]__debugger.ts.snap index d7d6d12a9314a..eb39cdfe1eb33 100644 --- a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_frameworks@astro__debugger.astro_vue__debugger.vue_svelte__debugger.svelte_nextjs__[[..rest]]__debugger.ts.snap +++ b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_frameworks@astro__debugger.astro_vue__debugger.vue_svelte__debugger.svelte_nextjs__[[..rest]]__debugger.ts.snap @@ -591,7 +591,7 @@ TextEdit: TextEdit { CodeAction: Title: Disable no-unassigned-vars for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position { @@ -627,7 +627,7 @@ TextEdit: TextEdit { CodeAction: Title: Disable no-unassigned-vars for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position { diff --git a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_issue_9958@issue.ts.snap b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_issue_9958@issue.ts.snap index 53da5767ab9b1..9dd8b841d9324 100644 --- a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_issue_9958@issue.ts.snap +++ b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_issue_9958@issue.ts.snap @@ -46,7 +46,7 @@ tags: None ########### Code Actions/Commands CodeAction: Title: Disable no-extra-boolean-cast for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position { @@ -82,7 +82,7 @@ TextEdit: TextEdit { CodeAction: Title: Disable typescript/no-non-null-asserted-optional-chain for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position { diff --git a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_regexp_feature@index.ts.snap b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_regexp_feature@index.ts.snap index e407aac48e3a0..00886953f7cb2 100644 --- a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_regexp_feature@index.ts.snap +++ b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_regexp_feature@index.ts.snap @@ -32,7 +32,7 @@ tags: None ########### Code Actions/Commands CodeAction: Title: Disable no-control-regex for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position { diff --git a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_ts_path_alias@deep__src__dep-a.ts.snap b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_ts_path_alias@deep__src__dep-a.ts.snap index d7850537d02fc..790f8d33c5669 100644 --- a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_ts_path_alias@deep__src__dep-a.ts.snap +++ b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_ts_path_alias@deep__src__dep-a.ts.snap @@ -21,7 +21,7 @@ tags: None ########### Code Actions/Commands CodeAction: Title: Disable import/no-cycle for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position { diff --git a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_tsgolint@no-floating-promises__index.ts.snap b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_tsgolint@no-floating-promises__index.ts.snap index da55b1e4d2521..fa153aef0174c 100644 --- a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_tsgolint@no-floating-promises__index.ts.snap +++ b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_tsgolint@no-floating-promises__index.ts.snap @@ -76,7 +76,7 @@ tags: None ########### Code Actions/Commands CodeAction: Title: Disable no-unused-expressions for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position { @@ -400,7 +400,7 @@ TextEdit: TextEdit { CodeAction: Title: Disable typescript/no-floating-promises for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position { diff --git a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_tsgolint_unused_disabled_directives@test.ts.snap b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_tsgolint_unused_disabled_directives@test.ts.snap index 61e17bf2ae614..d88a2097603de 100644 --- a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_tsgolint_unused_disabled_directives@test.ts.snap +++ b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_tsgolint_unused_disabled_directives@test.ts.snap @@ -32,7 +32,7 @@ tags: None ########### Code Actions/Commands CodeAction: Title: Disable typescript/no-floating-promises for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position { @@ -68,7 +68,7 @@ TextEdit: TextEdit { CodeAction: Title: Disable typescript/no-floating-promises for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position { diff --git a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_unused_disabled_directives@test.js.snap b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_unused_disabled_directives@test.js.snap index f97ecbdd57db6..50d03e33e9c4f 100644 --- a/apps/oxlint/src/lsp/snapshots/fixtures_lsp_unused_disabled_directives@test.js.snap +++ b/apps/oxlint/src/lsp/snapshots/fixtures_lsp_unused_disabled_directives@test.js.snap @@ -59,7 +59,7 @@ tags: None ########### Code Actions/Commands CodeAction: Title: Disable no-console for this line -Is Preferred: Some(true) +Is Preferred: Some(false) TextEdit: TextEdit { range: Range { start: Position {