Refresh config file diagnostics when a config file is saved - #4739
Open
UditDewan wants to merge 1 commit into
Open
Refresh config file diagnostics when a config file is saved#4739UditDewan wants to merge 1 commit into
UditDewan wants to merge 1 commit into
Conversation
Diagnostics for tsconfig/jsconfig files are only published as part of a snapshot update. Saving an edited config file left the change pending until some unrelated request happened to flush it, so the config file's diagnostics went stale. Schedule a snapshot update when a saved file is a config file. Fixes microsoft#4713
| return true | ||
| } | ||
| // Configs pulled in by `extends` or project references can be named anything. | ||
| return snapshot.ConfigFileRegistry.GetConfig(snapshot.toPath(fileName)) != nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4713.
Problem
Diagnostics for
tsconfig.json/jsconfig.jsonare push-only: they are published frompublishProgramDiagnosticsas part of a snapshot update.DidChangeFileandDidSaveFileonly append topendingFileChanges; neither schedules a snapshot update.For a normal source file that is fine, because the client follows an edit with requests (diagnostic pulls, completions, …) that flush the pending changes. Editing a config file usually isn't followed by any request, so the edit sits in the pending queue and the config file keeps showing its old diagnostics until something unrelated happens to flush it.
Repro from the issue: open a
.tsfile, opentsconfig.json, set"target": "es5", save — noOption 'target=ES5' has been removed.diagnostic appears, where 6.0 reports one.Fix
DidSaveFileschedules a (debounced) snapshot update when the saved file is a config file, which flushes the pending edit and republishes the config file's diagnostics. Config files are recognized by base name (includingcustomConfigFileName) or by being present in the snapshot'sConfigFileRegistry, which also covers configs pulled in throughextends/ project references under a non-standard name.Non-config saves are unchanged, so this adds no work to the common save path.
Tests
Added
TestPushDiagnostics/updates diagnostics when an open config file is saved: opens a config file, changestargettoes5, saves, and asserts the diagnostic is published with no intervening request. It fails onmain(no diagnostics published) and passes with this change.This change was authored with AI assistance. I picked the issue, reviewed and tested the patch myself, and will handle review feedback.