Skip to content
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
16 changes: 12 additions & 4 deletions apps/oxlint/src/lsp/code_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -34,11 +34,19 @@ fn fix_content_to_code_action(
pub fn apply_fix_code_actions(action: LinterCodeAction, uri: &Uri) -> Vec<CodeAction> {
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);
}

Expand Down
7 changes: 3 additions & 4 deletions apps/oxlint/src/lsp/error_with_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading