From 7f6cfe271045b1d652ca9c379d5c7df124bb3391 Mon Sep 17 00:00:00 2001 From: yongsk0066 Date: Tue, 9 Sep 2025 13:28:49 +0900 Subject: [PATCH] fix(language_server): don't clear diagnostics on save in onType mode When lint.run="onType" and type_aware=false, saving would clear all diagnostics. Now returns None instead of empty Vec to preserve existing diagnostics. --- .../on_type/on-save-no-type-aware.ts | 7 +++++++ .../src/linter/server_linter.rs | 19 ++++++++++++++++--- ..._run_on_type@on-save-no-type-aware.ts.snap | 5 +++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 crates/oxc_language_server/fixtures/linter/lint_on_run/on_type/on-save-no-type-aware.ts create mode 100644 crates/oxc_language_server/src/snapshots/fixtures_linter_lint_on_run_on_type@on-save-no-type-aware.ts.snap diff --git a/crates/oxc_language_server/fixtures/linter/lint_on_run/on_type/on-save-no-type-aware.ts b/crates/oxc_language_server/fixtures/linter/lint_on_run/on_type/on-save-no-type-aware.ts new file mode 100644 index 0000000000000..33daf56106c36 --- /dev/null +++ b/crates/oxc_language_server/fixtures/linter/lint_on_run/on_type/on-save-no-type-aware.ts @@ -0,0 +1,7 @@ +debugger; + +async function returnsPromise() { + return "value"; +} + +returnsPromise().then(() => {}); \ No newline at end of file diff --git a/crates/oxc_language_server/src/linter/server_linter.rs b/crates/oxc_language_server/src/linter/server_linter.rs index bcac2cf5680b9..48ad4de222f6e 100644 --- a/crates/oxc_language_server/src/linter/server_linter.rs +++ b/crates/oxc_language_server/src/linter/server_linter.rs @@ -331,9 +331,12 @@ impl ServerLinter { (ServerLinterRun::OnType, Run::OnType) => (true, false), // it does not match, run nothing (ServerLinterRun::OnType, Run::OnSave) => (false, false), - // run only tsglint on save, even if the user wants it with type - // tsgolint only supports the OS file system. - (ServerLinterRun::OnSave, Run::OnType) => (false, true), + // In onType mode, only TypeScript type checking runs on save + // If type_aware is disabled (tsgo_linter is None), skip everything to preserve diagnostics + (ServerLinterRun::OnSave, Run::OnType) => { + let should_run_tsgo = self.tsgo_linter.as_ref().is_some(); + (false, should_run_tsgo) + } }; // return `None` when both tools do not want to be used @@ -483,6 +486,16 @@ mod test { .test_and_snapshot_single_file_with_run_type("on-save.ts", Run::OnSave); } + #[test] + #[cfg(not(target_endian = "big"))] + fn test_lint_on_run_on_type_on_save_without_type_aware() { + Tester::new( + "fixtures/linter/lint_on_run/on_type", + Some(Options { type_aware: false, run: Run::OnType, ..Default::default() }), + ) + .test_and_snapshot_single_file_with_run_type("on-save-no-type-aware.ts", Run::OnSave); + } + #[test] fn test_no_errors() { Tester::new("fixtures/linter/no_errors", None) diff --git a/crates/oxc_language_server/src/snapshots/fixtures_linter_lint_on_run_on_type@on-save-no-type-aware.ts.snap b/crates/oxc_language_server/src/snapshots/fixtures_linter_lint_on_run_on_type@on-save-no-type-aware.ts.snap new file mode 100644 index 0000000000000..90415976a0380 --- /dev/null +++ b/crates/oxc_language_server/src/snapshots/fixtures_linter_lint_on_run_on_type@on-save-no-type-aware.ts.snap @@ -0,0 +1,5 @@ +--- +source: crates/oxc_language_server/src/tester.rs +input_file: crates/oxc_language_server/fixtures/linter/lint_on_run/on_type/on-save-no-type-aware.ts +--- +File is ignored