Fix flaky diagnostic added by declaration emit for untyped module imports - #64479
Mateusz Burzyński (Andarist) wants to merge 2 commits into
Conversation
Fourslash now initializes the server with trackFlakyDiagnostics set to panic, so every textDocument/diagnostic request also emits the program and fails if the diagnostics differ before and after emit. This complements the compiler harness's pre/post-emit check, which compares separate programs by diagnostic count only and doesn't catch emit adding a diagnostic to an already-checked program. Add fourslash tests where declaration emit adds a "Could not find a declaration file for module" (7016) suggestion for an untyped import whose error was dropped by checking (plain JS file, @ts-expect-error, and an ES module under NodeNext).
…FromDeclaration getExternalModuleFileFromDeclaration is only used by emit (IsImportRequiredByAugmentation, module transforms) and by type-node reuse in the node builder. It resolved with the specifier as the error node, so for an untyped JS module it re-ran errorOnImplicitAnyModule with moduleNotFoundError == nil and recorded 7016 as a *suggestion*. Checking had already reported 7016 as an error, which was then dropped (plain JS file or @ts-expect-error), but suggestions bypass both filters, so the diagnostic appeared only after emit and tripped the LSP's flaky-diagnostic tracking. Resolve with ignoreErrors so these emit-time queries are free of diagnostic side effects. Fixes microsoft#64458
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
| CodeLensShowLocationsCommandName: new(showCodeLensLocationsCommandName), | ||
| // Make every textDocument/diagnostic request also emit the program and fail if the | ||
| // diagnostics differ before and after emit, e.g. because the emit resolver added some. | ||
| TrackFlakyDiagnostics: new(lsproto.DiagnosticFlakeLogLevelPanic), |
There was a problem hiding this comment.
this "builds up" on microsoft/typescript-go#4526 and microsoft/typescript-go#4710 . It feels the same unconditional flaky diagnostic tracking can just be added to fourslash. And it makes it easier to write tests for this without going full in on server-level tests
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused fix prevents emit-only diagnostic mutation and is covered across the reported import scenarios.
Review effort: Balanced
Findings: None
What changed in this PR
Prevents declaration emit/type printing from introducing diagnostics after checking.
Changes:
- Resolves emit-time module references without reporting errors.
- Enables flaky-diagnostic detection across Fourslash tests.
- Adds regression coverage for package, JavaScript, and NodeNext imports.
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Suppresses diagnostic side effects during emit-time resolution. |
tsc/internal/fourslash/fourslash.go |
Enables panic-level flaky-diagnostic tracking. |
tsc/internal/fourslash/tests/noFlakyDiagnosticsUntypedModule1_test.go |
Tests an untyped package import. |
tsc/internal/fourslash/tests/noFlakyDiagnosticsUntypedModule2_test.go |
Tests a relative JavaScript import. |
tsc/internal/fourslash/tests/noFlakyDiagnosticsUntypedModule3_test.go |
Tests a NodeNext .mjs import. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
fixes crash reported here: #64458 (comment)