Skip to content

Commit d2b7dcb

Browse files
committed
fix(tsgolint): improve lsp diagnostic when linting fails (#16115)
Before: <img width="1246" height="226" alt="Screenshot 2025-11-25 at 19 02 47" src="https://github.com/user-attachments/assets/941b1f78-8d12-49a4-b4d7-2798781180d0" /> After: ![Screenshot 2025-11-25 at 18.53.31.png](https://app.graphite.com/user-attachments/assets/61ad3e2d-124e-458a-9712-8378d596186f.png)
1 parent 74cf572 commit d2b7dcb

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

crates/oxc_linter/src/tsgolint.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ impl TsGoLintState {
359359

360360
let fix = self.fix;
361361
let fix_suggestions = self.fix_suggestions;
362+
let path_file_name =
363+
Path::new(path.as_ref()).file_name().unwrap_or_default().to_os_string();
362364
let handler = std::thread::spawn(move || {
363365
let mut cmd = std::process::Command::new(&executable_path);
364366
cmd.arg("headless")
@@ -459,7 +461,18 @@ impl TsGoLintState {
459461
result.push(message);
460462
}
461463
TsGoLintDiagnostic::Internal(e) => {
462-
return Err(e.message.description);
464+
let span = e
465+
.file_path
466+
.as_ref()
467+
.is_some_and(|f| {
468+
f.file_name().unwrap_or_default() == path_file_name
469+
})
470+
.then_some(e.span)
471+
.flatten()
472+
.unwrap_or_default();
473+
let mut diagnostic: OxcDiagnostic = e.into();
474+
diagnostic = diagnostic.with_label(span);
475+
result.push(Message::new(diagnostic, PossibleFixes::None));
463476
}
464477
}
465478
}

0 commit comments

Comments
 (0)