Skip to content

Commit 2efc8f9

Browse files
committed
fix(language_server): build releated spans from "0" instead of MAX_LSP_INT
1 parent 382c5be commit 2efc8f9

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

crates/oxc_language_server/src/linter/error_with_position.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use tower_lsp_server::lsp_types::{
88

99
use oxc_diagnostics::Severity;
1010

11-
use crate::LSP_MAX_INT;
12-
1311
#[derive(Debug, Clone, Default)]
1412
pub struct DiagnosticReport {
1513
pub diagnostic: lsp_types::Diagnostic,
@@ -72,17 +70,11 @@ fn message_with_position_to_lsp_diagnostic(
7270
});
7371

7472
let range = related_information.as_ref().map_or(
75-
Range {
76-
start: Position { line: LSP_MAX_INT, character: LSP_MAX_INT },
77-
end: Position { line: LSP_MAX_INT, character: LSP_MAX_INT },
78-
},
73+
Range::default(),
7974
|infos: &Vec<DiagnosticRelatedInformation>| {
80-
let mut ret_range = Range {
81-
start: Position { line: LSP_MAX_INT, character: LSP_MAX_INT },
82-
end: Position { line: LSP_MAX_INT, character: LSP_MAX_INT },
83-
};
75+
let mut ret_range = Range::default();
8476
for info in infos {
85-
if cmp_range(&ret_range, &info.location.range) == std::cmp::Ordering::Greater {
77+
if cmp_range(&ret_range, &info.location.range) == std::cmp::Ordering::Less {
8678
ret_range = info.location.range;
8779
}
8880
}

crates/oxc_language_server/src/main.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ type ConcurrentHashMap<K, V> = papaya::HashMap<K, V, FxBuildHasher>;
1919

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

22-
// max range for LSP integer is 2^31 - 1
23-
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#baseTypes
24-
const LSP_MAX_INT: u32 = 2u32.pow(31) - 1;
25-
2622
#[tokio::main]
2723
async fn main() {
2824
env_logger::init();

crates/oxc_language_server/src/snapshots/fixtures_linter_issue_9958@issue.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fixed: Multiple(
5656
code: "typescript-eslint(no-non-null-asserted-optional-chain)"
5757
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-non-null-asserted-optional-chain.html"
5858
message: "Optional chain expressions can return undefined by design: using a non-null assertion is unsafe and wrong.\nhelp: Remove the non-null assertion."
59-
range: Range { start: Position { line: 11, character: 18 }, end: Position { line: 11, character: 19 } }
59+
range: Range { start: Position { line: 11, character: 21 }, end: Position { line: 11, character: 22 } }
6060
related_information[0].message: "non-null assertion made after optional chain"
6161
related_information[0].location.uri: "file://<variable>/fixtures/linter/issue_9958/issue.ts"
6262
related_information[0].location.range: Range { start: Position { line: 11, character: 21 }, end: Position { line: 11, character: 22 } }
@@ -106,11 +106,11 @@ fixed: Multiple(
106106

107107
code: "None"
108108
code_description.href: "None"
109-
message: "non-null assertion made after optional chain"
110-
range: Range { start: Position { line: 11, character: 21 }, end: Position { line: 11, character: 22 } }
109+
message: "optional chain used"
110+
range: Range { start: Position { line: 11, character: 18 }, end: Position { line: 11, character: 19 } }
111111
related_information[0].message: "original diagnostic"
112112
related_information[0].location.uri: "file://<variable>/fixtures/linter/issue_9958/issue.ts"
113-
related_information[0].location.range: Range { start: Position { line: 11, character: 18 }, end: Position { line: 11, character: 19 } }
113+
related_information[0].location.range: Range { start: Position { line: 11, character: 21 }, end: Position { line: 11, character: 22 } }
114114
severity: Some(Hint)
115115
source: Some("oxc")
116116
tags: None

0 commit comments

Comments
 (0)