@@ -19,6 +19,10 @@ import (
19
19
)
20
20
21
21
//go:generate go tool golang.org/x/tools/cmd/stringer -type=Kind -output=project_stringer_generated.go
22
+ const (
23
+ fileGlobPattern = "*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}"
24
+ recursiveFileGlobPattern = "**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}"
25
+ )
22
26
23
27
var projectNamer = & namer {}
24
28
@@ -62,18 +66,20 @@ type Project struct {
62
66
deferredClose bool
63
67
pendingConfigReload bool
64
68
65
- currentDirectory string
69
+ comparePathsOptions tspath.ComparePathsOptions
70
+ currentDirectory string
66
71
// Inferred projects only
67
72
rootPath tspath.Path
68
73
69
74
configFileName string
70
75
configFilePath tspath.Path
71
76
// rootFileNames was a map from Path to { NormalizedPath, ScriptInfo? } in the original code.
72
77
// But the ProjectService owns script infos, so it's not clear why there was an extra pointer.
73
- rootFileNames * collections.OrderedMap [tspath.Path , string ]
74
- compilerOptions * core.CompilerOptions
75
- languageService * ls.LanguageService
76
- program * compiler.Program
78
+ rootFileNames * collections.OrderedMap [tspath.Path , string ]
79
+ compilerOptions * core.CompilerOptions
80
+ parsedCommandLine * tsoptions.ParsedCommandLine
81
+ languageService * ls.LanguageService
82
+ program * compiler.Program
77
83
78
84
watchedGlobs []string
79
85
watcherID WatcherHandle
@@ -103,6 +109,10 @@ func NewProject(name string, kind Kind, currentDirectory string, host ProjectHos
103
109
currentDirectory : currentDirectory ,
104
110
rootFileNames : & collections.OrderedMap [tspath.Path , string ]{},
105
111
}
112
+ project .comparePathsOptions = tspath.ComparePathsOptions {
113
+ CurrentDirectory : currentDirectory ,
114
+ UseCaseSensitiveFileNames : host .FS ().UseCaseSensitiveFileNames (),
115
+ }
106
116
project .languageService = ls .NewLanguageService (project )
107
117
project .markAsDirty ()
108
118
return project
@@ -213,25 +223,28 @@ func (p *Project) LanguageService() *ls.LanguageService {
213
223
}
214
224
215
225
func (p * Project ) getWatchGlobs () []string {
216
- // !!!
217
226
if p .kind == KindConfigured {
218
- return []string {
219
- p .configFileName ,
227
+ wildcardDirectories := p .parsedCommandLine .WildcardDirectories ()
228
+ result := make ([]string , 0 , len (wildcardDirectories )+ 1 )
229
+ result = append (result , p .configFileName )
230
+ for dir , recursive := range wildcardDirectories {
231
+ result = append (result , fmt .Sprintf ("%s/%s" , dir , core .IfElse (recursive , recursiveFileGlobPattern , fileGlobPattern )))
220
232
}
233
+ return result
221
234
}
222
235
return nil
223
236
}
224
237
225
238
func (p * Project ) updateWatchers () {
226
- watchHost := p .host .Client ()
227
- if watchHost == nil {
239
+ client := p .host .Client ()
240
+ if client == nil {
228
241
return
229
242
}
230
243
231
244
globs := p .getWatchGlobs ()
232
245
if ! slices .Equal (p .watchedGlobs , globs ) {
233
246
if p .watcherID != "" {
234
- if err := watchHost .UnwatchFiles (p .watcherID ); err != nil {
247
+ if err := client .UnwatchFiles (p .watcherID ); err != nil {
235
248
p .log (fmt .Sprintf ("Failed to unwatch files: %v" , err ))
236
249
}
237
250
}
@@ -248,7 +261,7 @@ func (p *Project) updateWatchers() {
248
261
Kind : & kind ,
249
262
}
250
263
}
251
- if watcherID , err := watchHost .WatchFiles (watchers ); err != nil {
264
+ if watcherID , err := client .WatchFiles (watchers ); err != nil {
252
265
p .log (fmt .Sprintf ("Failed to watch files: %v" , err ))
253
266
} else {
254
267
p .watcherID = watcherID
@@ -284,6 +297,7 @@ func (p *Project) markAsDirty() {
284
297
}
285
298
}
286
299
300
+ // updateIfDirty returns true if the project was updated.
287
301
func (p * Project ) updateIfDirty () bool {
288
302
// !!! p.invalidateResolutionsOfFailedLookupLocations()
289
303
return p .dirty && p .updateGraph ()
@@ -437,6 +451,7 @@ func (p *Project) LoadConfig() error {
437
451
}, " " , " " )),
438
452
)
439
453
454
+ p .parsedCommandLine = parsedCommandLine
440
455
p .compilerOptions = parsedCommandLine .CompilerOptions ()
441
456
p .setRootFiles (parsedCommandLine .FileNames ())
442
457
} else {
0 commit comments