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
24 changes: 17 additions & 7 deletions apps/oxlint/src/lsp/server_linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ impl ToolBuilder for ServerLinterBuilder {
if !code_action_kinds.contains(&CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC) {
code_action_kinds.push(CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC);
}
if !code_action_kinds.contains(&CodeActionKind::SOURCE_FIX_ALL) {
code_action_kinds.push(CodeActionKind::SOURCE_FIX_ALL);
}

// override code action kinds if the code action provider is already set
capabilities.code_action_provider =
Expand Down Expand Up @@ -517,10 +520,13 @@ impl Tool for ServerLinter {

let actions =
actions.into_iter().filter(|r| r.range == *range || range_overlaps(*range, r.range));
let is_source_fix_all_oxc = only_code_action_kinds
.is_some_and(|only| only.contains(&CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC));
// if `source.fixAll.oxc` or `source.fixAll` is requested, return a single code action that applies all fixes
let is_source_fix_all = only_code_action_kinds.is_some_and(|only| {
only.contains(&CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC)
|| only.contains(&CodeActionKind::SOURCE_FIX_ALL)
});

if is_source_fix_all_oxc {
if is_source_fix_all {
return apply_all_fix_code_action(actions, uri.clone())
.map_or(vec![], |code_actions| {
vec![CodeActionOrCommand::CodeAction(code_actions)]
Expand Down Expand Up @@ -697,7 +703,8 @@ mod tests_builder {
let code_action_kinds = options.code_action_kinds.as_ref().unwrap();
assert!(code_action_kinds.contains(&CodeActionKind::QUICKFIX));
assert!(code_action_kinds.contains(&CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC));
assert_eq!(code_action_kinds.len(), 2);
assert!(code_action_kinds.contains(&CodeActionKind::SOURCE_FIX_ALL));
assert_eq!(code_action_kinds.len(), 3);
}
_ => panic!("Expected code action provider options"),
}
Expand Down Expand Up @@ -728,7 +735,8 @@ mod tests_builder {
assert!(code_action_kinds.contains(&CodeActionKind::REFACTOR));
assert!(code_action_kinds.contains(&CodeActionKind::QUICKFIX));
assert!(code_action_kinds.contains(&CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC));
assert_eq!(code_action_kinds.len(), 3);
assert!(code_action_kinds.contains(&CodeActionKind::SOURCE_FIX_ALL));
assert_eq!(code_action_kinds.len(), 4);
assert_eq!(options.resolve_provider, Some(true));
}
_ => panic!("Expected code action provider options"),
Expand All @@ -754,7 +762,8 @@ mod tests_builder {
let code_action_kinds = options.code_action_kinds.as_ref().unwrap();
assert!(code_action_kinds.contains(&CodeActionKind::QUICKFIX));
assert!(code_action_kinds.contains(&CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC));
assert_eq!(code_action_kinds.len(), 2);
assert!(code_action_kinds.contains(&CodeActionKind::SOURCE_FIX_ALL));
assert_eq!(code_action_kinds.len(), 3);
}
_ => panic!("Expected code action provider options"),
}
Expand All @@ -776,7 +785,8 @@ mod tests_builder {
let code_action_kinds = options.code_action_kinds.as_ref().unwrap();
assert!(code_action_kinds.contains(&CodeActionKind::QUICKFIX));
assert!(code_action_kinds.contains(&CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC));
assert_eq!(code_action_kinds.len(), 2);
assert!(code_action_kinds.contains(&CodeActionKind::SOURCE_FIX_ALL));
assert_eq!(code_action_kinds.len(), 3);
}
_ => panic!("Expected code action provider options"),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,22 @@ TextEdit: TextEdit {
},
new_text: "// oxlint-disable no-debugger\n",
}


########### Fix All Action
CodeAction:
Title: quick fix
Is Preferred: Some(true)
TextEdit: TextEdit {
range: Range {
start: Position {
line: 1,
character: 0,
},
end: Position {
line: 1,
character: 9,
},
},
new_text: "",
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ TextEdit: TextEdit {
},
new_text: "// oxlint-disable import/no-cycle\n",
}


########### Fix All Action
None
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ TextEdit: TextEdit {
},
new_text: "// oxlint-disable import/no-cycle\n",
}


########### Fix All Action
None
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ File URI: file://<variable>/fixtures/lsp/cross_module_nested_config/dep-a.ts

########### Code Actions/Commands

########### Fix All Action
None
##########
Linted file: fixtures/lsp/cross_module_nested_config/folder/folder-dep-a.ts
----------
Expand Down Expand Up @@ -61,3 +63,7 @@ TextEdit: TextEdit {
},
new_text: "// oxlint-disable import/no-cycle\n",
}


########### Fix All Action
None
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ TextEdit: TextEdit {
},
new_text: "// oxlint-disable no-console\n",
}


########### Fix All Action
None
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,64 @@ TextEdit: TextEdit {
}


########### Fix All Action
CodeAction:
Title: quick fix
Is Preferred: Some(true)
TextEdit: TextEdit {
range: Range {
start: Position {
line: 1,
character: 0,
},
end: Position {
line: 1,
character: 8,
},
},
new_text: "",
}
TextEdit: TextEdit {
range: Range {
start: Position {
line: 10,
character: 2,
},
end: Position {
line: 10,
character: 10,
},
},
new_text: "",
}
TextEdit: TextEdit {
range: Range {
start: Position {
line: 14,
character: 2,
},
end: Position {
line: 14,
character: 10,
},
},
new_text: "",
}
TextEdit: TextEdit {
range: Range {
start: Position {
line: 18,
character: 2,
},
end: Position {
line: 18,
character: 10,
},
},
new_text: "",
}


##########
Linted file: fixtures/lsp/frameworks/vue/debugger.vue
----------
Expand Down Expand Up @@ -405,6 +463,38 @@ TextEdit: TextEdit {
}


########### Fix All Action
CodeAction:
Title: quick fix
Is Preferred: Some(true)
TextEdit: TextEdit {
range: Range {
start: Position {
line: 4,
character: 8,
},
end: Position {
line: 4,
character: 17,
},
},
new_text: "",
}
TextEdit: TextEdit {
range: Range {
start: Position {
line: 8,
character: 4,
},
end: Position {
line: 8,
character: 13,
},
},
new_text: "",
}


##########
Linted file: fixtures/lsp/frameworks/svelte/debugger.svelte
----------
Expand Down Expand Up @@ -571,6 +661,25 @@ TextEdit: TextEdit {
}


########### Fix All Action
CodeAction:
Title: quick fix
Is Preferred: Some(true)
TextEdit: TextEdit {
range: Range {
start: Position {
line: 1,
character: 1,
},
end: Position {
line: 1,
character: 10,
},
},
new_text: "",
}


##########
Linted file: fixtures/lsp/frameworks/nextjs/[[..rest]]/debugger.ts
----------
Expand Down Expand Up @@ -641,3 +750,22 @@ TextEdit: TextEdit {
},
new_text: "// oxlint-disable no-debugger\n",
}


########### Fix All Action
CodeAction:
Title: quick fix
Is Preferred: Some(true)
TextEdit: TextEdit {
range: Range {
start: Position {
line: 0,
character: 0,
},
end: Position {
line: 0,
character: 9,
},
},
new_text: "",
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ File URI: file://<variable>/fixtures/lsp/ignore_patterns/ignored-file.ts

########### Code Actions/Commands

########### Fix All Action
None
##########
Linted file: fixtures/lsp/ignore_patterns/another_config/not-ignored-file.ts
----------
Expand Down Expand Up @@ -79,3 +81,22 @@ TextEdit: TextEdit {
},
new_text: "// oxlint-disable no-debugger\n",
}


########### Fix All Action
CodeAction:
Title: quick fix
Is Preferred: Some(true)
TextEdit: TextEdit {
range: Range {
start: Position {
line: 0,
character: 0,
},
end: Position {
line: 0,
character: 9,
},
},
new_text: "",
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ tags: None

########### Code Actions/Commands

########### Fix All Action
None
##########
Linted file: fixtures/lsp/invalid_syntax/invalid.vue
----------
Expand All @@ -38,3 +40,6 @@ source: Some("oxc")
tags: None

########### Code Actions/Commands

########### Fix All Action
None
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ source: Some("oxc")
tags: None

########### Code Actions/Commands

########### Fix All Action
None
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,7 @@ TextEdit: TextEdit {
},
new_text: "// oxlint-disable typescript/no-non-null-asserted-optional-chain\n",
}


########### Fix All Action
None
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,22 @@ TextEdit: TextEdit {
},
new_text: "// oxlint-disable no-debugger\n",
}


########### Fix All Action
CodeAction:
Title: quick fix
Is Preferred: Some(true)
TextEdit: TextEdit {
range: Range {
start: Position {
line: 0,
character: 0,
},
end: Position {
line: 0,
character: 9,
},
},
new_text: "",
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,22 @@ TextEdit: TextEdit {
},
new_text: "// oxlint-disable react/forward-ref-uses-ref\n",
}


########### Fix All Action
CodeAction:
Title: quick fix
Is Preferred: Some(true)
TextEdit: TextEdit {
range: Range {
start: Position {
line: 0,
character: 0,
},
end: Position {
line: 0,
character: 25,
},
},
new_text: "(props) => {}",
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ Linted file: fixtures/lsp/no_errors/hello_world.js
File URI: file://<variable>/fixtures/lsp/no_errors/hello_world.js

########### Code Actions/Commands

########### Fix All Action
None
Loading
Loading