Skip to content

Commit 100c21a

Browse files
committed
fix(language_server): build releated spans from "0" instead of MAX_LSP_INT
1 parent d36d227 commit 100c21a

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
@@ -7,8 +7,6 @@ use tower_lsp_server::lsp_types::{
77

88
use oxc_diagnostics::Severity;
99

10-
use crate::LSP_MAX_INT;
11-
1210
#[derive(Debug, Clone, Default)]
1311
pub struct DiagnosticReport {
1412
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
@@ -21,7 +21,7 @@ fixed: None
2121
code: "typescript-eslint(no-non-null-asserted-optional-chain)"
2222
code_description.href: "https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-non-null-asserted-optional-chain.html"
2323
message: "Optional chain expressions can return undefined by design: using a non-null assertion is unsafe and wrong.\nhelp: Remove the non-null assertion."
24-
range: Range { start: Position { line: 11, character: 18 }, end: Position { line: 11, character: 19 } }
24+
range: Range { start: Position { line: 11, character: 21 }, end: Position { line: 11, character: 22 } }
2525
related_information[0].message: "non-null assertion made after optional chain"
2626
related_information[0].location.uri: "file://<variable>/fixtures/linter/issue_9958/issue.ts"
2727
related_information[0].location.range: Range { start: Position { line: 11, character: 21 }, end: Position { line: 11, character: 22 } }
@@ -36,11 +36,11 @@ fixed: None
3636

3737
code: "None"
3838
code_description.href: "None"
39-
message: "non-null assertion made after optional chain"
40-
range: Range { start: Position { line: 11, character: 21 }, end: Position { line: 11, character: 22 } }
39+
message: "optional chain used"
40+
range: Range { start: Position { line: 11, character: 18 }, end: Position { line: 11, character: 19 } }
4141
related_information[0].message: "original diagnostic"
4242
related_information[0].location.uri: "file://<variable>/fixtures/linter/issue_9958/issue.ts"
43-
related_information[0].location.range: Range { start: Position { line: 11, character: 18 }, end: Position { line: 11, character: 19 } }
43+
related_information[0].location.range: Range { start: Position { line: 11, character: 21 }, end: Position { line: 11, character: 22 } }
4444
severity: Some(Hint)
4545
source: Some("oxc")
4646
tags: None

0 commit comments

Comments
 (0)