@@ -31,6 +31,23 @@ export function createProjects(
31
31
uri : string ,
32
32
time : number ,
33
33
} | undefined ;
34
+ const fileExistsCache = shared . createPathMap < boolean > ( ) ;
35
+ const directoryExistsCache = shared . createPathMap < boolean > ( ) ;
36
+ const sys : ts . System = {
37
+ ...ts . sys ,
38
+ fileExists ( path : string ) {
39
+ if ( ! fileExistsCache . fsPathHas ( path ) ) {
40
+ fileExistsCache . fsPathSet ( path , ts . sys . fileExists ( path ) ) ;
41
+ }
42
+ return fileExistsCache . fsPathGet ( path ) ! ;
43
+ } ,
44
+ directoryExists ( path : string ) {
45
+ if ( ! directoryExistsCache . fsPathHas ( path ) ) {
46
+ directoryExistsCache . fsPathSet ( path , ts . sys . directoryExists ( path ) ) ;
47
+ }
48
+ return directoryExistsCache . fsPathGet ( path ) ! ;
49
+ } ,
50
+ } ;
34
51
35
52
const workspaces = new Map < string , ReturnType < typeof createWorkspace > > ( ) ;
36
53
@@ -40,6 +57,7 @@ export function createProjects(
40
57
languageConfigs ,
41
58
rootPath ,
42
59
ts ,
60
+ sys ,
43
61
tsLocalized ,
44
62
options ,
45
63
documents ,
@@ -77,6 +95,15 @@ export function createProjects(
77
95
} ) ;
78
96
connection . onDidChangeWatchedFiles ( async handler => {
79
97
98
+ for ( const change of handler . changes ) {
99
+ if ( change . type === vscode . FileChangeType . Created ) {
100
+ fileExistsCache . uriSet ( change . uri , true ) ;
101
+ }
102
+ else if ( change . type === vscode . FileChangeType . Deleted ) {
103
+ fileExistsCache . uriSet ( change . uri , false ) ;
104
+ }
105
+ }
106
+
80
107
const tsConfigChanges : vscode . FileEvent [ ] = [ ] ;
81
108
const scriptChanges : vscode . FileEvent [ ] = [ ] ;
82
109
@@ -233,6 +260,7 @@ function createWorkspace(
233
260
languageConfigs : LanguageConfigs ,
234
261
rootPath : string ,
235
262
ts : typeof import ( 'typescript/lib/tsserverlibrary' ) ,
263
+ sys : ts . System ,
236
264
tsLocalized : ts . MapLike < string > | undefined ,
237
265
options : shared . ServerInitializationOptions ,
238
266
documents : vscode . TextDocuments < TextDocument > ,
@@ -241,12 +269,12 @@ function createWorkspace(
241
269
getInferredCompilerOptions : ( ) => Promise < ts . CompilerOptions > ,
242
270
) {
243
271
244
- const rootTsConfigs = ts . sys . readDirectory ( rootPath , rootTsConfigNames , undefined , [ '**/*' ] ) ;
272
+ const rootTsConfigs = sys . readDirectory ( rootPath , rootTsConfigNames , undefined , [ '**/*' ] ) ;
245
273
const projects = shared . createPathMap < Project > ( ) ;
246
274
let inferredProject : Project | undefined ;
247
275
248
276
const getRootPath = ( ) => rootPath ;
249
- const workspaceSys = ts . sys . getCurrentDirectory ( ) === rootPath ? ts . sys : new Proxy ( ts . sys , {
277
+ const workspaceSys = sys . getCurrentDirectory ( ) === rootPath ? sys : new Proxy ( sys , {
250
278
get ( target , prop ) {
251
279
const fn = target [ prop as keyof typeof target ] ;
252
280
if ( typeof fn === 'function' ) {
@@ -380,13 +408,13 @@ function createWorkspace(
380
408
let tsConfigPath = projectReference . path ;
381
409
382
410
// fix https://github.com/johnsoncodehk/volar/issues/712
383
- if ( ! ts . sys . fileExists ( tsConfigPath ) && ts . sys . directoryExists ( tsConfigPath ) ) {
411
+ if ( ! sys . fileExists ( tsConfigPath ) && sys . directoryExists ( tsConfigPath ) ) {
384
412
const newTsConfigPath = path . join ( tsConfigPath , 'tsconfig.json' ) ;
385
413
const newJsConfigPath = path . join ( tsConfigPath , 'jsconfig.json' ) ;
386
- if ( ts . sys . fileExists ( newTsConfigPath ) ) {
414
+ if ( sys . fileExists ( newTsConfigPath ) ) {
387
415
tsConfigPath = newTsConfigPath ;
388
416
}
389
- else if ( ts . sys . fileExists ( newJsConfigPath ) ) {
417
+ else if ( sys . fileExists ( newJsConfigPath ) ) {
390
418
tsConfigPath = newJsConfigPath ;
391
419
}
392
420
}
0 commit comments