Skip to content
Closed
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
13 changes: 7 additions & 6 deletions crates/oxc_language_server/src/linter/error_with_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use tower_lsp_server::lsp_types::{

use oxc_diagnostics::Severity;

use crate::LSP_MAX_INT;

#[derive(Debug, Clone)]
pub struct DiagnosticReport {
pub diagnostic: lsp_types::Diagnostic,
Expand Down Expand Up @@ -71,14 +69,17 @@ fn message_with_position_to_lsp_diagnostic(
});

let range = related_information.as_ref().map_or(
// Use a zero range as fallback when no span information is available
// This is valid and commonly used for diagnostics without specific location
Range {
start: Position { line: LSP_MAX_INT, character: LSP_MAX_INT },
end: Position { line: LSP_MAX_INT, character: LSP_MAX_INT },
start: Position { line: 0, character: 0 },
end: Position { line: 0, character: 0 },
},
|infos: &Vec<DiagnosticRelatedInformation>| {
// Find the first (smallest) range from the related information
let mut ret_range = Range {
start: Position { line: LSP_MAX_INT, character: LSP_MAX_INT },
end: Position { line: LSP_MAX_INT, character: LSP_MAX_INT },
start: Position { line: u32::MAX, character: u32::MAX },
end: Position { line: u32::MAX, character: u32::MAX },
Comment on lines +81 to +82
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of u32::MAX (4294967295) here is inconsistent with the PR's approach of using (0, 0) for invalid ranges. While this works for comparison purposes, u32::MAX still exceeds the LSP specification's maximum value (2^31 - 1).

Consider an alternative approach for the initial comparison:

  • Use an Option<Range> that starts as None
  • Use a boolean flag to track if a valid range has been found
  • Or initialize with the first range found, then compare subsequent ranges

This would maintain consistency with the PR's goal of eliminating invalid range values throughout the codebase.

Suggested change
start: Position { line: u32::MAX, character: u32::MAX },
end: Position { line: u32::MAX, character: u32::MAX },
start: Position { line: 0, character: 0 },
end: Position { line: 0, character: 0 },

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Copy link
Member

Choose a reason for hiding this comment

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

Yes! IntelliJ expects to be in a valid LSP Range and will fail. We had it on u32::MAX and needed to change it for IntelliJ integration

};
for info in infos {
if cmp_range(&ret_range, &info.location.range) == std::cmp::Ordering::Greater {
Expand Down
4 changes: 0 additions & 4 deletions crates/oxc_language_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ type ConcurrentHashMap<K, V> = papaya::HashMap<K, V, FxBuildHasher>;

const OXC_CONFIG_FILE: &str = ".oxlintrc.json";

// max range for LSP integer is 2^31 - 1
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#baseTypes
const LSP_MAX_INT: u32 = 2u32.pow(31) - 1;

#[tokio::main]
async fn main() {
env_logger::init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ file: fixtures/linter/invalid_syntax/debugger.ts
code: ""
code_description.href: "None"
message: "Unexpected token"
range: Range { start: Position { line: 2147483647, character: 2147483647 }, end: Position { line: 2147483647, character: 2147483647 } }
range: Range { start: Position { line: 0, character: 0 }, end: Position { line: 0, character: 0 } }
related_information: None
severity: Some(Error)
source: Some("oxc")
Expand Down
Loading