Skip to content

Commit

Permalink
fix(oxc_laguage_server): code actions if report range overlap request (
Browse files Browse the repository at this point in the history
…#8902)

Requesting code actions in neovim's normal mode doesn't return any code
action, as the report range isn't fully contained in the requested range
- which is only the current cursor position. Filtering based on overlap
seems to be done by most relevant language servers (based on my tesing)
- such as `rust-analyzer` or `ts_ls`. `eslint` filters code actions
based on intercepted lines.
  • Loading branch information
marekvospel authored Feb 5, 2025
1 parent 2d06260 commit 0df939c
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions crates/oxc_language_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,10 @@ impl LanguageServer for Backend {

let mut code_actions_vec: Vec<CodeActionOrCommand> = vec![];
if let Some(value) = self.diagnostics_report_map.get(&uri.to_string()) {
let reports = value
.iter()
.filter(|r| {
r.diagnostic.range == params.range
|| range_includes(params.range, r.diagnostic.range)
})
.collect::<Vec<_>>();
let reports = value.iter().filter(|r| {
r.diagnostic.range == params.range
|| range_overlaps(params.range, r.diagnostic.range)
});
for report in reports {
// TODO: Would be better if we had exact rule name from the diagnostic instead of having to parse it.
let mut rule_name: Option<String> = None;
Expand Down Expand Up @@ -579,12 +576,6 @@ async fn main() {
Server::new(stdin, stdout, socket).serve(service).await;
}

fn range_includes(range: Range, to_include: Range) -> bool {
if range.start >= to_include.start {
return false;
}
if range.end <= to_include.end {
return false;
}
true
fn range_overlaps(a: Range, b: Range) -> bool {
a.start <= b.end && a.end >= b.start
}

0 comments on commit 0df939c

Please sign in to comment.