-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
noDts project resolutions verification and updates for incremental behaviour #56016
Conversation
… to find the source
13f1ca3
to
ed80039
Compare
…file origination query
// This shows issue with two things: // When resolution is reused from different folder, failed lookups get added so next project update is going to cause ref count problem // package json info is added to cache and thats retained without watching
ed80039
to
a49de0e
Compare
…o changes to them
I'm not entirely sure how these types are used in public, but is the readonly flag something that should be exported so that external consumers know to use the API in the right way, or is it unlikely to matter? |
I think we only care about resolution cache we created and are using so i am not sure if it matters. But also while investigating i was wondering |
Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page. Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up. |
@@ -3354,7 +3354,6 @@ declare namespace ts { | |||
readFile(fileName: string): string | undefined; | |||
writeFile(fileName: string, content: string): void; | |||
fileExists(file: string): boolean; | |||
getModuleResolutionCache(): ModuleResolutionCache | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, https://github.com/marko-js/language-server/blob/6829c580d16eb1c6128c90a73af36fa4efb64d08/packages/language-server/src/ts-plugin/index.ts#L59 uses it, but that may be the only example I found, so maybe it's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They shouldnt have been. Gitlens went in loops but couldnt figure out when and why this was exposed but from looks of it, it should not be exposed at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was added in #47388, it seems. @andrewbranch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, but it's internal there. Hm, one sec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s internal on LanguageServiceHost
, but not on Project
😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yeah, I just discovered that. I guess it should just be dropped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(To be clear I'm not trying to actually blame anyone, moreso just trying to do the forensics so we know if there was a reason to have it 😅)
resultFromCache.affectingLocations = updateResolutionField(resultFromCache.affectingLocations, affectingLocations); | ||
resultFromCache.resolutionDiagnostics = updateResolutionField(resultFromCache.resolutionDiagnostics, diagnostics); | ||
return resultFromCache; | ||
if (!cache?.isReadonly) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only concern is it seems somewhat easy to miss this check if someone were adding new code that interacts with the cache, and it seems like there still are no compile-time or runtime checks preventing you from mutating the contents at a time when it could cause problems. Would it be worth changing ResolvedModuleWithFailedLookupLocations
etc. to have readonly properties that can only be changed by a method on the cache, which could check isReadonly
to ensure it’s not being violated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can do that, but frankly I dont see point in that since I think we want this method to be that one. Which ensures the resolutionWithFailedLookupLocation is created correctly.
When resolving module specifier for finding implementation file, we were using module resolution cache which means that it was possible to reuse existing module resolution and add more failed lookup locations to it. Which means that when we release that resolution as part of program update/close, we will try to release more locations than being watched.
Fixed this by marking module resolution cache as read-only after construction of program, which indicates module resolution algorithm to not update the cache or resolution. (instead of freezing internal maps, went ahead with at usage mode approach to avoid having to deal with invalidation logic eg for package json info before program construction) 1b6c9a8
Also updated some of the other
noDts
project related things:isBackgroundProject
so we can ensure all the updates where we need to skip things for background project are handled correctly fe7f068Added coverage for some of the missing cases like
resolveSingleModuleNameWithoutWatching
to ensure it does not impact state: a49de0e