LSP: fix(diagnostics), ensure immediate updates for opened dependent files on change #1779
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.
Hey, quick fix for my previous refactor
The Problem (Bug)
Currently, if a user modifies an exported member in
export.civet, any other open file (import.civet) that imports that member does not instantly receive updated diagnostic errors even when files are open in editor. It appears only after direct edit in theimport.civetHow to Replicate
Create two files:
export.civet:import.civet:Open both files in the editor. Observe that there are no errors.
In
export.civet, change the exported variable name:Observe (The Bug): Switch to the
import.civetfile. No diagnostic error is shown. The linter is silent, even though the import ofabcis now invalid.Expected Behavior: The moment
export.civetis saved or changed, an error should immediately appear inimport.civet, highlighting thatabcis not an exported member.The Solution
The root cause of this bug was a path mismatch within the
updateProjectDiagnosticsfunction. The function iterates through all files in the TypeScript program usingprogram.getSourceFiles().The fix is to use
service.getSourceFileName(sourceFile.fileName). This method correctly resolves the path known by the TypeScript service back to its original source file path. This ensures we can reliably find the corresponding open document in ourdocumentsmap and push the updated diagnostics to the editor immediately after a dependency changes.Happy to hear any thoughts, its a small, but important fix imo