Skip to content

Conversation

@Sysix
Copy link
Member

@Sysix Sysix commented Sep 23, 2025

This PR aligns the main label/span with oxlint.
oxlint will use the first available span as the error. The LSP should use this span for the red line.

let a: {
  b?: {
    c: number;
  };
} = {};

for(var i = 0; i < 10; i--){}
console.log(a?.b?.c!);

Note that file.ts:7:16 means the line/column number and is linkable.

  ⚠ eslint(for-direction): The update clause in this loop moves the variable in the wrong direction
   ╭─[for_direction.ts:7:16]
 6 │ 
 7 │ for(var i = 0; i < 10; i--){}
   ·                ───┬──  ─┬─
   ·                   │     ╰── with this update
   ·                   ╰── This test moves in the wrong direction
 8 │ console.log(a?.b?.c!);
   ╰────
  help: Use while loop for intended infinite loop

  ⚠ typescript-eslint(no-non-null-asserted-optional-chain): Optional chain expressions can return undefined by design: using a non-null assertion is unsafe and wrong.
   ╭─[for_direction.ts:8:20]
 7 │ for(var i = 0; i < 10; i--){}
 8 │ console.log(a?.b?.c!);
   ·                 ┬  ┬
   ·                 │  ╰── non-null assertion made after optional chain
   ·                 ╰── optional chain used
 9 │ 
   ╰────
  help: Remove the non-null assertion.

https://github.com/oxc-project/oxc/blob/main/crates/oxc_language_server/fixtures/linter/issue_9958/issue.ts

Main:
grafik

This PR:
grafik

@github-actions github-actions bot added A-editor Area - Editor and Language Server C-bug Category - Bug labels Sep 23, 2025
Copy link
Member Author

Sysix commented Sep 23, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 23, 2025

CodSpeed Performance Report

Merging #14057 will not alter performance

Comparing 09-23-fix_language_server_build_releated_spans_from_0_instead_of_max_lsp_int_ (493082c) with main (83e7824)1

Summary

✅ 4 untouched
⏩ 33 skipped2

Footnotes

  1. No successful run was found on main (493082c) during the generation of this report, so 83e7824 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 33 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Sysix Sysix force-pushed the 09-23-fix_language_server_build_releated_spans_from_0_instead_of_max_lsp_int_ branch from fdb03e8 to 100c21a Compare September 26, 2025 13:40
@Sysix Sysix force-pushed the 09-23-fix_language_server_build_releated_spans_from_0_instead_of_max_lsp_int_ branch 2 times, most recently from 2efc8f9 to ac86d37 Compare October 7, 2025 18:26
@github-actions github-actions bot added the A-linter Area - Linter label Oct 7, 2025
@Sysix Sysix force-pushed the 09-23-fix_language_server_build_releated_spans_from_0_instead_of_max_lsp_int_ branch from ac86d37 to 553aa9a Compare October 7, 2025 18:27
@Sysix Sysix changed the title fix(language_server): build releated spans from "0" instead of MAX_LSP_INT fix(language_server): use the first Span of the message as the primary Diagnostic range Oct 7, 2025
@Sysix Sysix requested a review from Copilot October 7, 2025 18:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Align LSP diagnostics to use the first span/label as the primary diagnostic range, matching oxlint’s behavior.

  • Use the first SpanPositionMessage as the diagnostic range instead of deriving it from related information
  • Derive Default for SpanPosition and re-export SpanPositionMessage under the language_server feature
  • Remove LSP_MAX_INT and update snapshots to reflect new primary/related message ranges

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/oxc_linter/src/lsp.rs Adds #[must_use] to with_message and derives Default for SpanPosition to support default fallbacks.
crates/oxc_linter/src/lib.rs Re-exports SpanPositionMessage for language_server feature consumers.
crates/oxc_language_server/src/linter/error_with_position.rs Computes Diagnostic.range from the first label; removes LSP_MAX_INT and cmp_range logic; adjusts imports.
crates/oxc_language_server/src/main.rs Removes unused LSP_MAX_INT constant and its documentation comments.
crates/oxc_language_server/src/snapshots/fixtures_linter_issue_9958@issue.ts.snap Updates expected ranges/messages to reflect using the first span as primary.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

camc314 commented Oct 8, 2025

Merge activity

…y Diagnostic range (#14057)

This PR aligns the main label/span with `oxlint`.
`oxlint` will use the first available span as the error. The LSP should use this span for the red line.

```
let a: {
  b?: {
    c: number;
  };
} = {};

for(var i = 0; i < 10; i--){}
console.log(a?.b?.c!);
```

Note that `file.ts:7:16` means the line/column number and is linkable.

```
  ⚠ eslint(for-direction): The update clause in this loop moves the variable in the wrong direction
   ╭─[for_direction.ts:7:16]
 6 │
 7 │ for(var i = 0; i < 10; i--){}
   ·                ───┬──  ─┬─
   ·                   │     ╰── with this update
   ·                   ╰── This test moves in the wrong direction
 8 │ console.log(a?.b?.c!);
   ╰────
  help: Use while loop for intended infinite loop

  ⚠ typescript-eslint(no-non-null-asserted-optional-chain): Optional chain expressions can return undefined by design: using a non-null assertion is unsafe and wrong.
   ╭─[for_direction.ts:8:20]
 7 │ for(var i = 0; i < 10; i--){}
 8 │ console.log(a?.b?.c!);
   ·                 ┬  ┬
   ·                 │  ╰── non-null assertion made after optional chain
   ·                 ╰── optional chain used
 9 │
   ╰────
  help: Remove the non-null assertion.
```

https://github.com/oxc-project/oxc/blob/main/crates/oxc_language_server/fixtures/linter/issue_9958/issue.ts

Main:
<img width="258" height="88" alt="grafik" src="https://github.com/user-attachments/assets/7da86f38-9789-4e04-b08b-18aa783a93ed" />

This PR:
<img width="265" height="108" alt="grafik" src="https://github.com/user-attachments/assets/2a031f84-04c3-49a8-8409-a3b1822c55a5" />
@graphite-app graphite-app bot force-pushed the 09-23-fix_language_server_build_releated_spans_from_0_instead_of_max_lsp_int_ branch from 553aa9a to 493082c Compare October 8, 2025 10:11
@camc314 camc314 removed the 0-merge Merge with Graphite Merge Queue label Oct 8, 2025
@graphite-app graphite-app bot merged commit 493082c into main Oct 8, 2025
21 checks passed
@graphite-app graphite-app bot deleted the 09-23-fix_language_server_build_releated_spans_from_0_instead_of_max_lsp_int_ branch October 8, 2025 10:15
Comment on lines +68 to +69
let start = labels.first().map(SpanPositionMessage::start).cloned().unwrap_or_default();
let end = labels.first().map(SpanPositionMessage::end).cloned().unwrap_or_default();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you double check this is correct? I think it should be:

Suggested change
let start = labels.first().map(SpanPositionMessage::start).cloned().unwrap_or_default();
let end = labels.first().map(SpanPositionMessage::end).cloned().unwrap_or_default();
let (start, end) = labels
.iter()
.find(|span| span.primary())
.or_else(|| labels.first())
.map(|span| ((SpanPositionMessage::start(span), SpanPositionMessage::end(span))));

The reasoning, is that some rules - e.g. react/exhaustive deps, mark the primary span (out of the two), and this is where the red line should be

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh these aren't spans, and don't have a primary(), method on them.

This was referenced Oct 8, 2025
camc314 added a commit that referenced this pull request Oct 8, 2025
## [1.21.0] - 2025-10-08

### 🚀 Features

- 576be20 linter/plugins: Support selectors DSL (#14435) (overlookmotel)
- b2de44f linter/plugins: Support interpolation in normal diagnostic
`message` (#14419) (overlookmotel)
- 382c5be linter/plugins: Support placeholders in messageIds (#14416)
(camc314)
- 529e88e linter/plugins: Support `messageId`s (#14415) (camc314)
- 83e7824 linter: Add `vue/require-default-export` rule (#14351) (Sysix)
- ff98536 linter: Add `vue/no-import-compiler-macros` rule (#14335)
(Sysix)
- 0ec0847 ci: Run napi tests on windows (#14383) (camc314)

### 🐛 Bug Fixes

- 11e0440 linter/jsx-handler-name: Improve handler name position in
error messages (#14174) (Takuji Shimokawa)
- 493082c language_server: Use the first Span of the message as the
primary Diagnostic range (#14057) (Sysix)
- 88ec1bd linter/plugins: Fix error messages (#14423) (overlookmotel)
- 18616c2 oxlint: Ignore fixtures dir for vitest (#14414) (camc314)
- ec02fe8 oxlint: Normalize path separators in snapshot tests (#14406)
(camc314)
- 6e8d2f6 language_server: Ignore JS plugins (#14379) (overlookmotel)
- 96663fb linter/plugins: Do not call `before` hook if empty visitor
(#14401) (overlookmotel)
- 52f04bd linter: Use `pathToFileURL` for importing plugins to ensure
correct URL format (#14394) (camc314)
- 1ea0d46 oxlint: Resolve tsdown deprecation warning (#14389) (camc314)
- bb679b5 linter: Promise/prefer-await-to-then strict option not reading
from config (#14382) (camc314)

### 🚜 Refactor

- 3374b8e linter/language_server: Move all lsp relevant code to
`oxc_language_server` crate (#14430) (Sysix)
- d24b74e linter/language_server: `oxc_linter::TsgoLinter::run_source`
returns `Message` (#14429) (Sysix)
- e5b7fb2 linter/language_server: `oxc_linter::Runtime::run_source`
returns `Message` (#14428) (Sysix)
- 3b26bf3 linter/plugins: Split adding visit function to compiler
visitor into multiple functions (#14433) (overlookmotel)
- af3a75e linter/plugins: Track ancestors while walking AST (#14432)
(overlookmotel)
- f279f0b linter/plugins: Do not lazy-load visitor keys (#14431)
(overlookmotel)
- 5e99ed3 linter/plugins: Allow nullish values as `message` or
`messageId` (#14422) (overlookmotel)
- dc30938 linter/plugins: Remove default value from `Context`
constructor (#14421) (overlookmotel)
- 28cfae0 oxlint: Use `vitest`s built in file snapshot comparison
(#14392) (camc314)
- 06b0e9f linter/plugins: Convert generated files to TS (#14385)
(overlookmotel)
- 52f35c6 napi/parser, linter/plugins: Rename `types.js` to
`type_ids.js` (#14384) (overlookmotel)

### ⚡ Performance

- 26435a1 linter/plugins: Small perf optimizations (#14420)
(overlookmotel)
- d8a8be1 linter/plugins: Avoid private methods (#14418) (overlookmotel)

### 🧪 Testing

- d8da4a4 linter/plugins: Clarify tests for message placeholders
(#14417) (overlookmotel)

Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-editor Area - Editor and Language Server A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants