Handle already released source files that dont match scriptKind #54401
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.
In LS we have document registry which maintain the cache by the
scriptKind
but there is not such concept at program level.So when we try to reuse program there is no fail-safe way to check if
scriptKind
doesn't match between program reuse unless we create the new source files.But this also means that we could try to get new
sourceFile
two times from the host.In LS when we try to get the source file, we see if we already have the source file from old program and if yes and their script kinds don't match we just get updated source file from the document registry,
But if the old Source file's
scriptKind
doesn't match then we release that source file (removing our ref count) and acquiring the new source file with correct script kind.What this resulted was, when we try to create source file when trying to determine if program structure can be reused, we would release the old document with script kind and acquire new document with correct script kind. But when the program structure is not reused, we would try to release the document with old Script kind but the bucket had the document with new script kind.
Fixes #54381