Skip to content

Commit fb9d0f4

Browse files
authored
fix(language_server): don't resend diagnostic on save, when typeAware is disabled and run is onType (#13604)
Fixes an edge case introduced in #13332 where diagnostics disappear when saving a file with `oxc.lint.run: "onType"` and `oxc.typeAware: false`. ## Problem The logic from #13332 assumes `tsgolint` always exists when `Run::OnType`: ```rust (ServerLinterRun::OnSave, Run::OnType) => (false, true) // always run tsgolint ``` But when `type_aware: false`, there is no `tsgo_linter`, causing the server to return empty diagnostics instead of None, which clears all error highlights in VSCode. ![clear-diagnostics](https://github.com/user-attachments/assets/3f7a530e-5319-4fa5-8668-7a34a3742e82) ## Solution Check if `tsgo_linter` actually exists: ```rust (ServerLinterRun::OnSave, Run::OnType) => { let should_run_tsgo = self.tsgo_linter.as_ref().is_some(); (false, should_run_tsgo) } ``` Now returns None when no linters should run, preserving existing diagnostics. **Test:** Added `test_lint_on_run_on_type_on_save_without_type_aware` with fixture
1 parent 2f36350 commit fb9d0f4

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
debugger;
2+
3+
async function returnsPromise() {
4+
return "value";
5+
}
6+
7+
returnsPromise().then(() => {});

crates/oxc_language_server/src/linter/server_linter.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,12 @@ impl ServerLinter {
331331
(ServerLinterRun::OnType, Run::OnType) => (true, false),
332332
// it does not match, run nothing
333333
(ServerLinterRun::OnType, Run::OnSave) => (false, false),
334-
// run only tsglint on save, even if the user wants it with type
335-
// tsgolint only supports the OS file system.
336-
(ServerLinterRun::OnSave, Run::OnType) => (false, true),
334+
// In onType mode, only TypeScript type checking runs on save
335+
// If type_aware is disabled (tsgo_linter is None), skip everything to preserve diagnostics
336+
(ServerLinterRun::OnSave, Run::OnType) => {
337+
let should_run_tsgo = self.tsgo_linter.as_ref().is_some();
338+
(false, should_run_tsgo)
339+
}
337340
};
338341

339342
// return `None` when both tools do not want to be used
@@ -483,6 +486,16 @@ mod test {
483486
.test_and_snapshot_single_file_with_run_type("on-save.ts", Run::OnSave);
484487
}
485488

489+
#[test]
490+
#[cfg(not(target_endian = "big"))]
491+
fn test_lint_on_run_on_type_on_save_without_type_aware() {
492+
Tester::new(
493+
"fixtures/linter/lint_on_run/on_type",
494+
Some(Options { type_aware: false, run: Run::OnType, ..Default::default() }),
495+
)
496+
.test_and_snapshot_single_file_with_run_type("on-save-no-type-aware.ts", Run::OnSave);
497+
}
498+
486499
#[test]
487500
fn test_no_errors() {
488501
Tester::new("fixtures/linter/no_errors", None)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
source: crates/oxc_language_server/src/tester.rs
3+
input_file: crates/oxc_language_server/fixtures/linter/lint_on_run/on_type/on-save-no-type-aware.ts
4+
---
5+
File is ignored

0 commit comments

Comments
 (0)