@@ -50,7 +50,6 @@ class WorkspaceContext {
5050 packageManager : PackageManager = 'npm'
5151 workspaceFileUri ?: Uri
5252 #catalogs?: PromiseWithResolvers < CatalogsInfo | undefined >
53- #invalidatedPaths = new Set < string > ( )
5453
5554 private constructor ( folder : WorkspaceFolder ) {
5655 this . folder = folder
@@ -74,7 +73,7 @@ class WorkspaceContext {
7473 this . workspaceFileUri = Uri . joinPath ( this . folder . uri , workspaceFilename )
7574 this . #catalogs. resolve (
7675 await accessOk ( this . workspaceFileUri )
77- ? ( await this . loadWorkspaceCatalogInfo ( this . workspaceFileUri ) ) ?. catalogs
76+ ? ( await this . loadWorkspaceFileInfo ( this . workspaceFileUri ) ) ?. catalogs
7877 : undefined ,
7978 )
8079 } else {
@@ -87,12 +86,6 @@ class WorkspaceContext {
8786 maxAge : 0 ,
8887 swr : false ,
8988 staleMaxAge : 0 ,
90- shouldInvalidateCache : ( uri ) => this . #invalidatedPaths. delete ( uri . path ) ,
91- }
92-
93- invalidateDependencyInfo ( uri : Uri ) {
94- const path = uri . path
95- this . #invalidatedPaths. add ( path )
9689 }
9790
9891 async getCatalogs ( ) : Promise < CatalogsInfo | undefined > {
@@ -154,7 +147,7 @@ class WorkspaceContext {
154147 }
155148 } , this . #cacheOptions)
156149
157- loadWorkspaceCatalogInfo = defineCachedFunction <
150+ loadWorkspaceFileInfo = defineCachedFunction <
158151 WithDependencyInfo < WorkspaceCatalogInfo > | undefined ,
159152 [ Uri ]
160153 > ( async ( uri ) => {
@@ -178,37 +171,33 @@ class WorkspaceContext {
178171 dependencies : info . dependencies . map ( ( dep ) => this . #createResolvedDependencyInfo( dep ) ) ,
179172 }
180173 } , this . #cacheOptions)
181- }
182174
183- const invalidatedFolderPaths = new Set < string > ( )
175+ async invalidateDependencyInfo ( uri : Uri ) {
176+ if ( isPackageManifest ( uri . path ) )
177+ await this . loadPackageManifestInfo . invalidate ( uri )
178+ else if ( isWorkspaceFile ( uri . path ) )
179+ await this . loadWorkspaceFileInfo . invalidate ( uri )
180+ }
181+ }
184182
185- const getWorkspaceContextByFolder = defineCachedFunction <
183+ export const getWorkspaceContext = defineCachedFunction <
186184 WorkspaceContext | undefined ,
187- [ WorkspaceFolder ]
188- > ( async ( folder ) => {
185+ [ Uri ]
186+ > ( async ( uri ) => {
187+ const folder = workspace . getWorkspaceFolder ( uri )
188+ if ( ! folder )
189+ return
190+
189191 logger . info ( `[workspace-context] built ${ folder . uri . path } ` )
190192 return await WorkspaceContext . create ( folder )
191193} , {
192194 name : 'workspace-context' ,
193- getKey : ( folder ) => folder . uri . path ,
195+ getKey : ( uri ) => workspace . getWorkspaceFolder ( uri ) ?. uri . path ?? '' ,
194196 swr : false ,
195197 maxAge : 0 ,
196198 staleMaxAge : 0 ,
197- shouldInvalidateCache : ( folder ) => invalidatedFolderPaths . delete ( folder . uri . path ) ,
198199} )
199200
200- export function deleteWorkspaceContextCache ( folder : WorkspaceFolder ) {
201- invalidatedFolderPaths . add ( folder . uri . path )
202- }
203-
204- export async function getWorkspaceContext ( uri : Uri ) {
205- const folder = workspace . getWorkspaceFolder ( uri )
206- if ( ! folder )
207- return
208-
209- return await getWorkspaceContextByFolder ( folder )
210- }
211-
212201export async function getResolvedDependencies ( uri : Uri ) : Promise < DependencyInfo [ ] | undefined > {
213202 const ctx = await getWorkspaceContext ( uri )
214203 if ( ! ctx )
@@ -217,7 +206,7 @@ export async function getResolvedDependencies(uri: Uri): Promise<DependencyInfo[
217206 return (
218207 isPackageManifest ( uri . path )
219208 ? await ctx . loadPackageManifestInfo ( uri )
220- : await ctx . loadWorkspaceCatalogInfo ( uri )
209+ : await ctx . loadWorkspaceFileInfo ( uri )
221210 ) ?. dependencies
222211}
223212
0 commit comments