diff --git a/internal/api/api.go b/internal/api/api.go index 99dca04727..b522371125 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -81,9 +81,9 @@ func (api *API) TypingsInstaller() *project.TypingsInstaller { return nil } -// DocumentRegistry implements ProjectHost. -func (api *API) DocumentRegistry() *project.DocumentRegistry { - return api.documentStore.DocumentRegistry() +// DocumentStore implements ProjectHost. +func (api *API) DocumentStore() *project.DocumentStore { + return api.documentStore } // ConfigFileRegistry implements ProjectHost. @@ -101,21 +101,6 @@ func (api *API) GetCurrentDirectory() string { return api.host.GetCurrentDirectory() } -// GetOrCreateScriptInfoForFile implements ProjectHost. -func (api *API) GetOrCreateScriptInfoForFile(fileName string, path tspath.Path, scriptKind core.ScriptKind) *project.ScriptInfo { - return api.getOrCreateScriptInfo(fileName, path, scriptKind) -} - -// GetScriptInfoByPath implements ProjectHost. -func (api *API) GetScriptInfoByPath(path tspath.Path) *project.ScriptInfo { - return api.documentStore.GetScriptInfoByPath(path) -} - -// OnDiscoveredSymlink implements ProjectHost. -func (api *API) OnDiscoveredSymlink(info *project.ScriptInfo) { - api.documentStore.AddRealpathMapping(info) -} - // Log implements ProjectHost. func (api *API) Log(s string) { api.options.Logger.Info(s) @@ -372,10 +357,6 @@ func (api *API) releaseHandle(handle string) error { return nil } -func (api *API) getOrCreateScriptInfo(fileName string, path tspath.Path, scriptKind core.ScriptKind) *project.ScriptInfo { - return api.documentStore.GetOrCreateScriptInfo(fileName, path, scriptKind, api.host.FS()) -} - func (api *API) toAbsoluteFileName(fileName string) string { return tspath.GetNormalizedAbsolutePath(fileName, api.host.GetCurrentDirectory()) } diff --git a/internal/compiler/fileloader.go b/internal/compiler/fileloader.go index 1751edc63e..d39c5b74e5 100644 --- a/internal/compiler/fileloader.go +++ b/internal/compiler/fileloader.go @@ -382,7 +382,7 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(file *ast.SourceFile, continue } - mode := getModeForUsageLocation(file.FileName(), meta, entry, module.GetCompilerOptionsWithRedirect(p.opts.Config.CompilerOptions(), redirect)) + mode := getModeForUsageLocation(file.FileName(), meta, entry, optionsForFile) resolvedModule := p.resolver.ResolveModuleName(moduleName, file.FileName(), mode, redirect) resolutionsInFile[module.ModeAwareCacheKey{Name: moduleName, Mode: mode}] = resolvedModule @@ -474,25 +474,6 @@ func getResolutionDiagnostic(options *core.CompilerOptions, resolvedModule *modu } } -func (p *fileLoader) resolveModuleNames(entries []*ast.Node, file *ast.SourceFile, meta ast.SourceFileMetaData, redirect *tsoptions.ParsedCommandLine) []*resolution { - if len(entries) == 0 { - return nil - } - - resolvedModules := make([]*resolution, 0, len(entries)) - - for _, entry := range entries { - moduleName := entry.Text() - if moduleName == "" { - continue - } - resolvedModule := p.resolver.ResolveModuleName(moduleName, file.FileName(), getModeForUsageLocation(file.FileName(), meta, entry, module.GetCompilerOptionsWithRedirect(p.opts.Config.CompilerOptions(), redirect)), redirect) - resolvedModules = append(resolvedModules, &resolution{node: entry, resolvedModule: resolvedModule}) - } - - return resolvedModules -} - func (p *fileLoader) createSyntheticImport(text string, file *ast.SourceFile) *ast.Node { p.factoryMu.Lock() defer p.factoryMu.Unlock() diff --git a/internal/project/project.go b/internal/project/project.go index 3ed15c5096..1b5acb0243 100644 --- a/internal/project/project.go +++ b/internal/project/project.go @@ -47,7 +47,7 @@ type snapshot struct { // GetLineMap implements ls.Host. func (s *snapshot) GetLineMap(fileName string) *ls.LineMap { file := s.program.GetSourceFile(fileName) - scriptInfo := s.project.host.GetScriptInfoByPath(file.Path()) + scriptInfo := s.project.host.DocumentStore().GetScriptInfoByPath(file.Path()) if s.project.getFileVersion(file) == scriptInfo.Version() { return scriptInfo.LineMap() } @@ -80,11 +80,8 @@ type ProjectHost interface { NewLine() string DefaultLibraryPath() string TypingsInstaller() *TypingsInstaller - DocumentRegistry() *DocumentRegistry + DocumentStore() *DocumentStore ConfigFileRegistry() *ConfigFileRegistry - GetScriptInfoByPath(path tspath.Path) *ScriptInfo - GetOrCreateScriptInfoForFile(fileName string, path tspath.Path, scriptKind core.ScriptKind) *ScriptInfo - OnDiscoveredSymlink(info *ScriptInfo) Log(s string) PositionEncoding() lsproto.PositionEncodingKind @@ -280,7 +277,7 @@ func (p *Project) GetSourceFile(opts ast.SourceFileParseOptions) *ast.SourceFile if p.program != nil { oldSourceFile = p.program.GetSourceFileByPath(scriptInfo.path) } - return p.host.DocumentRegistry().AcquireDocument(scriptInfo, opts, oldSourceFile) + return p.host.DocumentStore().documentRegistry.AcquireDocument(scriptInfo, opts, oldSourceFile) } return nil } @@ -418,7 +415,7 @@ func (p *Project) onWatchEventForNilScriptInfo(fileName string) { } func (p *Project) getOrCreateScriptInfoAndAttachToProject(fileName string, scriptKind core.ScriptKind) *ScriptInfo { - if scriptInfo := p.host.GetOrCreateScriptInfoForFile(fileName, p.toPath(fileName), scriptKind); scriptInfo != nil { + if scriptInfo := p.host.DocumentStore().getOrCreateScriptInfoWorker(fileName, p.toPath(fileName), scriptKind, false, "", false, p.host.FS()); scriptInfo != nil { scriptInfo.attachToProject(p) return scriptInfo } @@ -519,7 +516,7 @@ func (p *Project) updateGraph() (*compiler.Program, bool) { if oldProgram != nil { for _, oldSourceFile := range oldProgram.GetSourceFiles() { if p.program.GetSourceFileByPath(oldSourceFile.Path()) == nil { - p.host.DocumentRegistry().ReleaseDocument(oldSourceFile) + p.host.DocumentStore().documentRegistry.ReleaseDocument(oldSourceFile) p.detachScriptInfoIfNotInferredRoot(oldSourceFile.Path()) } } @@ -1017,7 +1014,7 @@ func (p *Project) print(writeFileNames bool, writeFileExplanation bool, writeFil } func (p *Project) getFileVersion(file *ast.SourceFile) int { - return p.host.DocumentRegistry().getFileVersion(file) + return p.host.DocumentStore().documentRegistry.getFileVersion(file) } func (p *Project) Log(s string) { @@ -1031,7 +1028,7 @@ func (p *Project) Logf(format string, args ...interface{}) { func (p *Project) detachScriptInfoIfNotInferredRoot(path tspath.Path) { // We might not find the script info in case its not associated with the project any more // and project graph was not updated (eg delayed update graph in case of files changed/deleted on the disk) - if scriptInfo := p.host.GetScriptInfoByPath(path); scriptInfo != nil && + if scriptInfo := p.host.DocumentStore().GetScriptInfoByPath(path); scriptInfo != nil && (p.kind != KindInferred || !p.isRoot(scriptInfo)) { scriptInfo.detachFromProject(p) } @@ -1043,7 +1040,7 @@ func (p *Project) Close() { if p.program != nil { for _, sourceFile := range p.program.GetSourceFiles() { - p.host.DocumentRegistry().ReleaseDocument(sourceFile) + p.host.DocumentStore().documentRegistry.ReleaseDocument(sourceFile) // Detach script info if its not root or is root of non inferred project p.detachScriptInfoIfNotInferredRoot(sourceFile.Path()) } @@ -1059,7 +1056,7 @@ func (p *Project) Close() { if p.kind == KindInferred { // Release root script infos for inferred projects. for path := range p.rootFileNames.Keys() { - if info := p.host.GetScriptInfoByPath(path); info != nil { + if info := p.host.DocumentStore().GetScriptInfoByPath(path); info != nil { info.detachFromProject(p) } } diff --git a/internal/project/projectlifetime_test.go b/internal/project/projectlifetime_test.go index b4ba9c91bf..4abe4aeae6 100644 --- a/internal/project/projectlifetime_test.go +++ b/internal/project/projectlifetime_test.go @@ -5,17 +5,11 @@ import ( "github.com/microsoft/typescript-go/internal/bundled" "github.com/microsoft/typescript-go/internal/core" - "github.com/microsoft/typescript-go/internal/project" "github.com/microsoft/typescript-go/internal/testutil/projecttestutil" "github.com/microsoft/typescript-go/internal/tspath" "gotest.tools/v3/assert" ) -func configFileExists(t *testing.T, service *project.Service, path tspath.Path, exists bool) { - _, loaded := service.ConfigFileRegistry().ConfigFiles.Load(path) - assert.Equal(t, loaded, exists, "config file %s should exist: %v", path, exists) -} - func TestProjectLifetime(t *testing.T) { t.Parallel() if !bundled.Embedded { @@ -63,41 +57,41 @@ func TestProjectLifetime(t *testing.T) { service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") service.OpenFile("/home/projects/TS/p2/src/index.ts", files["/home/projects/TS/p2/src/index.ts"].(string), core.ScriptKindTS, "") assert.Equal(t, len(service.Projects()), 2) - assert.Assert(t, service.ConfiguredProject(tspath.ToPath("/home/projects/TS/p1/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) != nil) - assert.Assert(t, service.ConfiguredProject(tspath.ToPath("/home/projects/TS/p2/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) != nil) + assert.Assert(t, service.ConfiguredProject(serviceToPath(service, "/home/projects/TS/p1/tsconfig.json")) != nil) + assert.Assert(t, service.ConfiguredProject(serviceToPath(service, "/home/projects/TS/p2/tsconfig.json")) != nil) assert.Equal(t, len(host.ClientMock.WatchFilesCalls()), 2) - configFileExists(t, service, tspath.ToPath("/home/projects/TS/p1/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames()), true) - configFileExists(t, service, tspath.ToPath("/home/projects/TS/p2/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames()), true) + configFileExists(t, service, serviceToPath(service, "/home/projects/TS/p1/tsconfig.json"), true) + configFileExists(t, service, serviceToPath(service, "/home/projects/TS/p2/tsconfig.json"), true) service.CloseFile("/home/projects/TS/p1/src/index.ts") service.OpenFile("/home/projects/TS/p3/src/index.ts", files["/home/projects/TS/p3/src/index.ts"].(string), core.ScriptKindTS, "") assert.Equal(t, len(service.Projects()), 2) - assert.Assert(t, service.ConfiguredProject(tspath.ToPath("/home/projects/TS/p1/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) - assert.Assert(t, service.ConfiguredProject(tspath.ToPath("/home/projects/TS/p2/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) != nil) - assert.Assert(t, service.ConfiguredProject(tspath.ToPath("/home/projects/TS/p3/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) != nil) - assert.Assert(t, service.GetScriptInfoByPath(tspath.ToPath("/home/projects/TS/p1/src/index.ts", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) - assert.Assert(t, service.GetScriptInfoByPath(tspath.ToPath("/home/projects/TS/p1/src/x.ts", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) + assert.Assert(t, service.ConfiguredProject(serviceToPath(service, "/home/projects/TS/p1/tsconfig.json")) == nil) + assert.Assert(t, service.ConfiguredProject(serviceToPath(service, "/home/projects/TS/p2/tsconfig.json")) != nil) + assert.Assert(t, service.ConfiguredProject(serviceToPath(service, "/home/projects/TS/p3/tsconfig.json")) != nil) + assert.Assert(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p1/src/index.ts")) == nil) + assert.Assert(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p1/src/x.ts")) == nil) assert.Equal(t, len(host.ClientMock.WatchFilesCalls()), 3) assert.Equal(t, len(host.ClientMock.UnwatchFilesCalls()), 1) - configFileExists(t, service, tspath.ToPath("/home/projects/TS/p1/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames()), false) - configFileExists(t, service, tspath.ToPath("/home/projects/TS/p2/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames()), true) - configFileExists(t, service, tspath.ToPath("/home/projects/TS/p3/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames()), true) + configFileExists(t, service, serviceToPath(service, "/home/projects/TS/p1/tsconfig.json"), false) + configFileExists(t, service, serviceToPath(service, "/home/projects/TS/p2/tsconfig.json"), true) + configFileExists(t, service, serviceToPath(service, "/home/projects/TS/p3/tsconfig.json"), true) service.CloseFile("/home/projects/TS/p2/src/index.ts") service.CloseFile("/home/projects/TS/p3/src/index.ts") service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") - assert.Assert(t, service.ConfiguredProject(tspath.ToPath("/home/projects/TS/p1/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) != nil) - assert.Assert(t, service.ConfiguredProject(tspath.ToPath("/home/projects/TS/p2/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) - assert.Assert(t, service.ConfiguredProject(tspath.ToPath("/home/projects/TS/p3/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) - assert.Assert(t, service.GetScriptInfoByPath(tspath.ToPath("/home/projects/TS/p2/src/index.ts", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) - assert.Assert(t, service.GetScriptInfoByPath(tspath.ToPath("/home/projects/TS/p2/src/x.ts", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) - assert.Assert(t, service.GetScriptInfoByPath(tspath.ToPath("/home/projects/TS/p3/src/index.ts", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) - assert.Assert(t, service.GetScriptInfoByPath(tspath.ToPath("/home/projects/TS/p3/src/x.ts", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) + assert.Assert(t, service.ConfiguredProject(serviceToPath(service, "/home/projects/TS/p1/tsconfig.json")) != nil) + assert.Assert(t, service.ConfiguredProject(serviceToPath(service, "/home/projects/TS/p2/tsconfig.json")) == nil) + assert.Assert(t, service.ConfiguredProject(serviceToPath(service, "/home/projects/TS/p3/tsconfig.json")) == nil) + assert.Assert(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p2/src/index.ts")) == nil) + assert.Assert(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p2/src/x.ts")) == nil) + assert.Assert(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p3/src/index.ts")) == nil) + assert.Assert(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p3/src/x.ts")) == nil) assert.Equal(t, len(host.ClientMock.WatchFilesCalls()), 4) assert.Equal(t, len(host.ClientMock.UnwatchFilesCalls()), 3) - configFileExists(t, service, tspath.ToPath("/home/projects/TS/p1/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames()), true) - configFileExists(t, service, tspath.ToPath("/home/projects/TS/p2/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames()), false) - configFileExists(t, service, tspath.ToPath("/home/projects/TS/p3/tsconfig.json", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames()), false) + configFileExists(t, service, serviceToPath(service, "/home/projects/TS/p1/tsconfig.json"), true) + configFileExists(t, service, serviceToPath(service, "/home/projects/TS/p2/tsconfig.json"), false) + configFileExists(t, service, serviceToPath(service, "/home/projects/TS/p3/tsconfig.json"), false) }) t.Run("inferred projects", func(t *testing.T) { @@ -113,30 +107,30 @@ func TestProjectLifetime(t *testing.T) { "/home/projects/TS/p3/src/x.ts": `export const x = 1;`, "/home/projects/TS/p3/config.ts": `let x = 1, y = 2;`, } - service, host := projecttestutil.Setup(files, nil) + service, _ := projecttestutil.Setup(files, nil) assert.Equal(t, len(service.Projects()), 0) service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "/home/projects/TS/p1") service.OpenFile("/home/projects/TS/p2/src/index.ts", files["/home/projects/TS/p2/src/index.ts"].(string), core.ScriptKindTS, "/home/projects/TS/p2") assert.Equal(t, len(service.Projects()), 2) - assert.Assert(t, service.InferredProject(tspath.ToPath("/home/projects/TS/p1", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) != nil) - assert.Assert(t, service.InferredProject(tspath.ToPath("/home/projects/TS/p2", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) != nil) + assert.Assert(t, service.InferredProject(serviceToPath(service, "/home/projects/TS/p1")) != nil) + assert.Assert(t, service.InferredProject(serviceToPath(service, "/home/projects/TS/p2")) != nil) service.CloseFile("/home/projects/TS/p1/src/index.ts") service.OpenFile("/home/projects/TS/p3/src/index.ts", files["/home/projects/TS/p3/src/index.ts"].(string), core.ScriptKindTS, "/home/projects/TS/p3") assert.Equal(t, len(service.Projects()), 2) - assert.Assert(t, service.InferredProject(tspath.ToPath("/home/projects/TS/p1", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) - assert.Assert(t, service.InferredProject(tspath.ToPath("/home/projects/TS/p2", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) != nil) - assert.Assert(t, service.InferredProject(tspath.ToPath("/home/projects/TS/p3", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) != nil) - assert.Assert(t, service.GetScriptInfoByPath(tspath.ToPath("/home/projects/TS/p1/src/index.ts", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) + assert.Assert(t, service.InferredProject(serviceToPath(service, "/home/projects/TS/p1")) == nil) + assert.Assert(t, service.InferredProject(serviceToPath(service, "/home/projects/TS/p2")) != nil) + assert.Assert(t, service.InferredProject(serviceToPath(service, "/home/projects/TS/p3")) != nil) + assert.Assert(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p1/src/index.ts")) == nil) service.CloseFile("/home/projects/TS/p2/src/index.ts") service.CloseFile("/home/projects/TS/p3/src/index.ts") service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "/home/projects/TS/p1") - assert.Assert(t, service.InferredProject(tspath.ToPath("/home/projects/TS/p1", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) != nil) - assert.Assert(t, service.InferredProject(tspath.ToPath("/home/projects/TS/p2", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) - assert.Assert(t, service.InferredProject(tspath.ToPath("/home/projects/TS/p3", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) - assert.Assert(t, service.GetScriptInfoByPath(tspath.ToPath("/home/projects/TS/p2/src/index.ts", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) - assert.Assert(t, service.GetScriptInfoByPath(tspath.ToPath("/home/projects/TS/p3/src/index.ts", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) + assert.Assert(t, service.InferredProject(serviceToPath(service, "/home/projects/TS/p1")) != nil) + assert.Assert(t, service.InferredProject(serviceToPath(service, "/home/projects/TS/p2")) == nil) + assert.Assert(t, service.InferredProject(serviceToPath(service, "/home/projects/TS/p3")) == nil) + assert.Assert(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p2/src/index.ts")) == nil) + assert.Assert(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p3/src/index.ts")) == nil) }) t.Run("unrooted inferred projects", func(t *testing.T) { @@ -152,7 +146,7 @@ func TestProjectLifetime(t *testing.T) { "/home/projects/TS/p3/src/x.ts": `export const x = 1;`, "/home/projects/TS/p3/config.ts": `let x = 1, y = 2;`, } - service, host := projecttestutil.Setup(files, nil) + service, _ := projecttestutil.Setup(files, nil) assert.Equal(t, len(service.Projects()), 0) service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") service.OpenFile("/home/projects/TS/p2/src/index.ts", files["/home/projects/TS/p2/src/index.ts"].(string), core.ScriptKindTS, "") @@ -163,20 +157,20 @@ func TestProjectLifetime(t *testing.T) { service.OpenFile("/home/projects/TS/p3/src/index.ts", files["/home/projects/TS/p3/src/index.ts"].(string), core.ScriptKindTS, "") assert.Equal(t, len(service.Projects()), 1) assert.Assert(t, service.InferredProject(tspath.Path("")) != nil) - assert.Assert(t, service.GetScriptInfoByPath(tspath.ToPath("/home/projects/TS/p1/src/index.ts", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) + assert.Assert(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p1/src/index.ts")) == nil) service.CloseFile("/home/projects/TS/p2/src/index.ts") service.CloseFile("/home/projects/TS/p3/src/index.ts") service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") assert.Assert(t, service.InferredProject(tspath.Path("")) != nil) - assert.Assert(t, service.GetScriptInfoByPath(tspath.ToPath("/home/projects/TS/p2/src/index.ts", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) - assert.Assert(t, service.GetScriptInfoByPath(tspath.ToPath("/home/projects/TS/p3/src/index.ts", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) + assert.Assert(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p2/src/index.ts")) == nil) + assert.Assert(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p3/src/index.ts")) == nil) service.CloseFile("/home/projects/TS/p1/src/index.ts") service.OpenFile("/home/projects/TS/p2/src/index.ts", files["/home/projects/TS/p2/src/index.ts"].(string), core.ScriptKindTS, "/home/projects/TS/p2") assert.Equal(t, len(service.Projects()), 1) assert.Assert(t, service.InferredProject(tspath.Path("")) == nil) - assert.Assert(t, service.GetScriptInfoByPath(tspath.ToPath("/home/projects/TS/p1/src/index.ts", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) == nil) - assert.Assert(t, service.InferredProject(tspath.ToPath("/home/projects/TS/p2", host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames())) != nil) + assert.Assert(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p1/src/index.ts")) == nil) + assert.Assert(t, service.InferredProject(serviceToPath(service, "/home/projects/TS/p2")) != nil) }) } diff --git a/internal/project/projectreferencesprogram_test.go b/internal/project/projectreferencesprogram_test.go index 1d14f71018..6478cab201 100644 --- a/internal/project/projectreferencesprogram_test.go +++ b/internal/project/projectreferencesprogram_test.go @@ -30,9 +30,9 @@ func TestProjectReferencesProgram(t *testing.T) { assert.Equal(t, len(service.Projects()), 1) p := service.Projects()[0] assert.Equal(t, p.Kind(), project.KindConfigured) - scriptInfo := service.GetScriptInfo("/user/username/projects/myproject/dependency/fns.ts") + scriptInfo := service.DocumentStore().GetScriptInfoByPath("/user/username/projects/myproject/dependency/fns.ts") assert.Assert(t, scriptInfo != nil) - dtsScriptInfo := service.GetScriptInfo("/user/username/projects/myproject/decls/fns.d.ts") + dtsScriptInfo := service.DocumentStore().GetScriptInfoByPath("/user/username/projects/myproject/decls/fns.d.ts") assert.Assert(t, dtsScriptInfo == nil) file := p.CurrentProgram().GetSourceFileByPath(tspath.Path("/user/username/projects/myproject/dependency/fns.ts")) assert.Assert(t, file != nil) @@ -56,9 +56,9 @@ func TestProjectReferencesProgram(t *testing.T) { assert.Equal(t, len(service.Projects()), 1) p := service.Projects()[0] assert.Equal(t, p.Kind(), project.KindConfigured) - scriptInfo := service.GetScriptInfo("/user/username/projects/myproject/dependency/fns.ts") + scriptInfo := service.DocumentStore().GetScriptInfoByPath("/user/username/projects/myproject/dependency/fns.ts") assert.Assert(t, scriptInfo == nil) - dtsScriptInfo := service.GetScriptInfo("/user/username/projects/myproject/decls/fns.d.ts") + dtsScriptInfo := service.DocumentStore().GetScriptInfoByPath("/user/username/projects/myproject/decls/fns.d.ts") assert.Assert(t, dtsScriptInfo != nil) file := p.CurrentProgram().GetSourceFileByPath(tspath.Path("/user/username/projects/myproject/dependency/fns.ts")) assert.Assert(t, file == nil) @@ -75,9 +75,9 @@ func TestProjectReferencesProgram(t *testing.T) { assert.Equal(t, len(service.Projects()), 1) p := service.Projects()[0] assert.Equal(t, p.Kind(), project.KindConfigured) - fooInfo := service.GetScriptInfo(bFoo) + fooInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bFoo)) assert.Assert(t, fooInfo != nil) - barInfo := service.GetScriptInfo(bBar) + barInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bBar)) assert.Assert(t, barInfo != nil) fooFile := p.CurrentProgram().GetSourceFile(bFoo) assert.Assert(t, fooFile != nil) @@ -94,9 +94,9 @@ func TestProjectReferencesProgram(t *testing.T) { assert.Equal(t, len(service.Projects()), 1) p := service.Projects()[0] assert.Equal(t, p.Kind(), project.KindConfigured) - fooInfo := service.GetScriptInfo(bFoo) + fooInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bFoo)) assert.Assert(t, fooInfo != nil) - barInfo := service.GetScriptInfo(bBar) + barInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bBar)) assert.Assert(t, barInfo != nil) fooFile := p.CurrentProgram().GetSourceFile(bFoo) assert.Assert(t, fooFile != nil) @@ -113,9 +113,9 @@ func TestProjectReferencesProgram(t *testing.T) { assert.Equal(t, len(service.Projects()), 1) p := service.Projects()[0] assert.Equal(t, p.Kind(), project.KindConfigured) - fooInfo := service.GetScriptInfo(bFoo) + fooInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bFoo)) assert.Assert(t, fooInfo != nil) - barInfo := service.GetScriptInfo(bBar) + barInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bBar)) assert.Assert(t, barInfo != nil) fooFile := p.CurrentProgram().GetSourceFile(bFoo) assert.Assert(t, fooFile != nil) @@ -132,9 +132,9 @@ func TestProjectReferencesProgram(t *testing.T) { assert.Equal(t, len(service.Projects()), 1) p := service.Projects()[0] assert.Equal(t, p.Kind(), project.KindConfigured) - fooInfo := service.GetScriptInfo(bFoo) + fooInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bFoo)) assert.Assert(t, fooInfo != nil) - barInfo := service.GetScriptInfo(bBar) + barInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bBar)) assert.Assert(t, barInfo != nil) fooFile := p.CurrentProgram().GetSourceFile(bFoo) assert.Assert(t, fooFile != nil) @@ -151,9 +151,9 @@ func TestProjectReferencesProgram(t *testing.T) { assert.Equal(t, len(service.Projects()), 1) p := service.Projects()[0] assert.Equal(t, p.Kind(), project.KindConfigured) - fooInfo := service.GetScriptInfo(bFoo) + fooInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bFoo)) assert.Assert(t, fooInfo != nil) - barInfo := service.GetScriptInfo(bBar) + barInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bBar)) assert.Assert(t, barInfo != nil) fooFile := p.CurrentProgram().GetSourceFile(bFoo) assert.Assert(t, fooFile != nil) @@ -170,9 +170,9 @@ func TestProjectReferencesProgram(t *testing.T) { assert.Equal(t, len(service.Projects()), 1) p := service.Projects()[0] assert.Equal(t, p.Kind(), project.KindConfigured) - fooInfo := service.GetScriptInfo(bFoo) + fooInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bFoo)) assert.Assert(t, fooInfo != nil) - barInfo := service.GetScriptInfo(bBar) + barInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bBar)) assert.Assert(t, barInfo != nil) fooFile := p.CurrentProgram().GetSourceFile(bFoo) assert.Assert(t, fooFile != nil) @@ -189,9 +189,9 @@ func TestProjectReferencesProgram(t *testing.T) { assert.Equal(t, len(service.Projects()), 1) p := service.Projects()[0] assert.Equal(t, p.Kind(), project.KindConfigured) - fooInfo := service.GetScriptInfo(bFoo) + fooInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bFoo)) assert.Assert(t, fooInfo != nil) - barInfo := service.GetScriptInfo(bBar) + barInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bBar)) assert.Assert(t, barInfo != nil) fooFile := p.CurrentProgram().GetSourceFile(bFoo) assert.Assert(t, fooFile != nil) @@ -208,9 +208,9 @@ func TestProjectReferencesProgram(t *testing.T) { assert.Equal(t, len(service.Projects()), 1) p := service.Projects()[0] assert.Equal(t, p.Kind(), project.KindConfigured) - fooInfo := service.GetScriptInfo(bFoo) + fooInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bFoo)) assert.Assert(t, fooInfo != nil) - barInfo := service.GetScriptInfo(bBar) + barInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, bBar)) assert.Assert(t, barInfo != nil) fooFile := p.CurrentProgram().GetSourceFile(bFoo) assert.Assert(t, fooFile != nil) diff --git a/internal/project/scriptinfo.go b/internal/project/scriptinfo.go index f54c672772..fb3ad5fc69 100644 --- a/internal/project/scriptinfo.go +++ b/internal/project/scriptinfo.go @@ -184,7 +184,7 @@ func (s *ScriptInfo) ensureRealpath(project *Project) { realpath := project.FS().Realpath(string(s.path)) s.realpath = project.toPath(realpath) if s.realpath != s.path { - project.host.OnDiscoveredSymlink(s) + project.host.DocumentStore().AddRealpathMapping(s) } } } diff --git a/internal/project/service.go b/internal/project/service.go index 7f3e77def3..b4a5249cd1 100644 --- a/internal/project/service.go +++ b/internal/project/service.go @@ -94,7 +94,7 @@ func NewService(host ServiceHost, options ServiceOptions) *Service { defaultProjectFinder: service.defaultProjectFinder, } service.converters = ls.NewConverters(options.PositionEncoding, func(fileName string) *ls.LineMap { - return service.GetScriptInfo(fileName).LineMap() + return service.documentStore.GetScriptInfoByPath(service.toPath(fileName)).LineMap() }) return service @@ -143,9 +143,9 @@ func (s *Service) TypingsInstaller() *TypingsInstaller { return s.typingsInstaller } -// DocumentRegistry implements ProjectHost. -func (s *Service) DocumentRegistry() *DocumentRegistry { - return s.documentStore.DocumentRegistry() +// DocumentStore implements ProjectHost. +func (s *Service) DocumentStore() *DocumentStore { + return s.documentStore } // ConfigFileRegistry implements ProjectHost. @@ -158,11 +158,6 @@ func (s *Service) FS() vfs.FS { return s.host.FS() } -// GetOrCreateScriptInfoForFile implements ProjectHost. -func (s *Service) GetOrCreateScriptInfoForFile(fileName string, path tspath.Path, scriptKind core.ScriptKind) *ScriptInfo { - return s.getOrCreateScriptInfoNotOpenedByClient(fileName, path, scriptKind) -} - // PositionEncoding implements ProjectHost. func (s *Service) PositionEncoding() lsproto.PositionEncodingKind { return s.options.PositionEncoding @@ -209,14 +204,6 @@ func (s *Service) InferredProject(rootPath tspath.Path) *Project { return nil } -func (s *Service) GetScriptInfo(fileName string) *ScriptInfo { - return s.GetScriptInfoByPath(s.toPath(fileName)) -} - -func (s *Service) GetScriptInfoByPath(path tspath.Path) *ScriptInfo { - return s.documentStore.GetScriptInfoByPath(path) -} - func (s *Service) isOpenFile(info *ScriptInfo) bool { _, ok := s.openFiles[info.path] return ok @@ -224,8 +211,9 @@ func (s *Service) isOpenFile(info *ScriptInfo) bool { func (s *Service) OpenFile(fileName string, fileContent string, scriptKind core.ScriptKind, projectRootPath string) { path := s.toPath(fileName) - existing := s.GetScriptInfoByPath(path) - info := s.getOrCreateOpenScriptInfo(fileName, path, fileContent, scriptKind, projectRootPath) + existing := s.documentStore.GetScriptInfoByPath(path) + info := s.documentStore.getOrCreateScriptInfoWorker(fileName, path, scriptKind, true /*openedByClient*/, fileContent, true /*deferredDeleteOk*/, s.FS()) + s.openFiles[info.path] = projectRootPath if existing == nil && info != nil && !info.isDynamic { // Invoke wild card directory watcher to ensure that the file presence is reflected s.configFileRegistry.tryInvokeWildCardDirectories(fileName, info.path) @@ -239,7 +227,7 @@ func (s *Service) OpenFile(fileName string, fileContent string, scriptKind core. func (s *Service) ChangeFile(document lsproto.VersionedTextDocumentIdentifier, changes []lsproto.TextDocumentContentChangeEvent) error { fileName := ls.DocumentURIToFileName(document.Uri) path := s.toPath(fileName) - scriptInfo := s.GetScriptInfoByPath(path) + scriptInfo := s.documentStore.GetScriptInfoByPath(path) if scriptInfo == nil { return fmt.Errorf("file %s not found", fileName) } @@ -263,8 +251,8 @@ func (s *Service) ChangeFile(document lsproto.VersionedTextDocumentIdentifier, c } func (s *Service) CloseFile(fileName string) { - if info := s.GetScriptInfoByPath(s.toPath(fileName)); info != nil { - fileExists := !info.isDynamic && s.host.FS().FileExists(info.fileName) + if info := s.documentStore.GetScriptInfoByPath(s.toPath(fileName)); info != nil { + fileExists := !info.isDynamic && s.FS().FileExists(info.fileName) info.close(fileExists) delete(s.openFiles, info.path) delete(s.defaultProjectFinder.configFileForOpenFiles, info.path) @@ -277,7 +265,7 @@ func (s *Service) CloseFile(fileName string) { } func (s *Service) MarkFileSaved(fileName string, text string) { - if info := s.GetScriptInfoByPath(s.toPath(fileName)); info != nil { + if info := s.documentStore.GetScriptInfoByPath(s.toPath(fileName)); info != nil { info.SetTextFromDisk(text) } } @@ -289,13 +277,13 @@ func (s *Service) EnsureDefaultProjectForURI(url lsproto.DocumentUri) *Project { func (s *Service) EnsureDefaultProjectForFile(fileName string) (*ScriptInfo, *Project) { path := s.toPath(fileName) - if info := s.GetScriptInfoByPath(path); info != nil && !info.isOrphan() { + if info := s.documentStore.GetScriptInfoByPath(path); info != nil && !info.isOrphan() { if project := s.getDefaultProjectForScript(info); project != nil { return info, project } } s.ensureProjectStructureUpToDate() - if info := s.GetScriptInfoByPath(path); info != nil { + if info := s.documentStore.GetScriptInfoByPath(path); info != nil { if project := s.getDefaultProjectForScript(info); project != nil { return info, project } @@ -307,11 +295,6 @@ func (s *Service) Close() { s.options.Logger.Close() } -// SourceFileCount should only be used for testing. -func (s *Service) SourceFileCount() int { - return s.documentStore.SourceFileCount() -} - func (s *Service) OnWatchedFilesChanged(ctx context.Context, changes []*lsproto.FileEvent) error { s.projectsMu.RLock() defer s.projectsMu.RUnlock() @@ -325,7 +308,7 @@ func (s *Service) OnWatchedFilesChanged(ctx context.Context, changes []*lsproto. } else if _, ok := s.openFiles[path]; ok { // open file continue - } else if info := s.GetScriptInfoByPath(path); info != nil { + } else if info := s.documentStore.GetScriptInfoByPath(path); info != nil { // closed existing file if change.Type == lsproto.FileChangeTypeDeleted { s.handleDeletedFile(info, true /*deferredDelete*/) @@ -376,7 +359,7 @@ func (s *Service) ensureProjectForOpenFiles() { s.printProjects() for filePath, projectRootPath := range s.openFiles { - info := s.GetScriptInfoByPath(filePath) + info := s.documentStore.GetScriptInfoByPath(filePath) if info == nil { panic("scriptInfo not found for open file") } @@ -432,10 +415,6 @@ func (s *Service) deleteScriptInfoLocked(info *ScriptInfo) { // !!! closeSourceMapFileWatcher } -func (s *Service) OnDiscoveredSymlink(info *ScriptInfo) { - s.documentStore.AddRealpathMapping(info) -} - func (s *Service) updateProjectGraphs(projects []*Project, clearSourceMapperCache bool) { for _, project := range projects { if clearSourceMapperCache { @@ -445,20 +424,6 @@ func (s *Service) updateProjectGraphs(projects []*Project, clearSourceMapperCach } } -func (s *Service) getOrCreateScriptInfoNotOpenedByClient(fileName string, path tspath.Path, scriptKind core.ScriptKind) *ScriptInfo { - return s.getOrCreateScriptInfoWorker(fileName, path, scriptKind, false /*openedByClient*/, "" /*fileContent*/, false /*deferredDeleteOk*/) -} - -func (s *Service) getOrCreateOpenScriptInfo(fileName string, path tspath.Path, fileContent string, scriptKind core.ScriptKind, projectRootPath string) *ScriptInfo { - info := s.getOrCreateScriptInfoWorker(fileName, path, scriptKind, true /*openedByClient*/, fileContent, true /*deferredDeleteOk*/) - s.openFiles[info.path] = projectRootPath - return info -} - -func (s *Service) getOrCreateScriptInfoWorker(fileName string, path tspath.Path, scriptKind core.ScriptKind, openedByClient bool, fileContent string, deferredDeleteOk bool) *ScriptInfo { - return s.documentStore.getOrCreateScriptInfoWorker(fileName, path, scriptKind, openedByClient, fileContent, deferredDeleteOk, s.host.FS()) -} - func (s *Service) createConfiguredProject(configFileName string, configFilePath tspath.Path) *Project { s.projectsMu.Lock() defer s.projectsMu.Unlock() @@ -551,7 +516,7 @@ func (s *Service) cleanupConfiguredProjects(openInfo *ScriptInfo, retainedByOpen if path == openInfo.path { continue } - info := s.GetScriptInfoByPath(path) + info := s.documentStore.GetScriptInfoByPath(path) // We want to retain the projects for open file if they are pending updates so deferredClosed projects are ok result := s.defaultProjectFinder.tryFindDefaultConfiguredProjectAndLoadAncestorsForOpenScriptInfo( info, @@ -636,7 +601,7 @@ func (s *Service) getOrCreateInferredProjectForProjectRootPath(info *ScriptInfo, if projectRootDirectory != "" { return s.createInferredProject(projectRootDirectory, s.toPath(projectRootDirectory)) } - return s.createInferredProject(s.host.GetCurrentDirectory(), "") + return s.createInferredProject(s.GetCurrentDirectory(), "") } func (s *Service) getInferredProjectForProjectRootPath(info *ScriptInfo, projectRootDirectory string) *Project { @@ -764,7 +729,7 @@ func (s *Service) createInferredProject(currentDirectory string, projectRootPath } func (s *Service) toPath(fileName string) tspath.Path { - return tspath.ToPath(fileName, s.host.GetCurrentDirectory(), s.host.FS().UseCaseSensitiveFileNames()) + return tspath.ToPath(fileName, s.GetCurrentDirectory(), s.FS().UseCaseSensitiveFileNames()) } func (s *Service) printProjects() { @@ -786,7 +751,7 @@ func (s *Service) printProjects() { builder.WriteString("Open files:") for path, projectRootPath := range s.openFiles { - info := s.GetScriptInfoByPath(path) + info := s.documentStore.GetScriptInfoByPath(path) builder.WriteString(fmt.Sprintf("\n\tFileName: %s ProjectRootPath: %s", info.fileName, projectRootPath)) builder.WriteString("\n\t\tProjects: " + strings.Join(core.Map(info.ContainingProjects(), func(project *Project) string { return project.name }), ", ")) } diff --git a/internal/project/service_test.go b/internal/project/service_test.go index ae8ec4d525..3e39e14096 100644 --- a/internal/project/service_test.go +++ b/internal/project/service_test.go @@ -43,7 +43,7 @@ func TestService(t *testing.T) { assert.Equal(t, len(service.Projects()), 1) p := service.Projects()[0] assert.Equal(t, p.Kind(), project.KindConfigured) - xScriptInfo := service.GetScriptInfo("/home/projects/TS/p1/src/x.ts") + xScriptInfo := service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p1/src/x.ts")) assert.Assert(t, xScriptInfo != nil) assert.Equal(t, xScriptInfo.Text(), "export const x = 1;") }) @@ -167,7 +167,7 @@ func TestService(t *testing.T) { files["/home/projects/TS/p1/y.ts"] = `export const y = 2;` service, _ := projecttestutil.Setup(files, nil) service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") - assert.Check(t, service.GetScriptInfo("/home/projects/TS/p1/y.ts") == nil) + assert.Check(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p1/y.ts")) == nil) // Avoid using initial file set after this point files = nil //nolint:ineffassign @@ -279,22 +279,22 @@ func TestService(t *testing.T) { service, host := projecttestutil.Setup(files, nil) service.OpenFile("/home/projects/TS/p1/src/x.ts", files["/home/projects/TS/p1/src/x.ts"].(string), core.ScriptKindTS, "") service.OpenFile("/home/projects/TS/p1/src/index.ts", files["/home/projects/TS/p1/src/index.ts"].(string), core.ScriptKindTS, "") - assert.Equal(t, service.SourceFileCount(), 2) + assert.Equal(t, service.DocumentStore().SourceFileCount(), 2) // Avoid using initial file set after this point files = nil //nolint:ineffassign assert.NilError(t, host.FS().Remove("/home/projects/TS/p1/src/x.ts")) service.CloseFile("/home/projects/TS/p1/src/x.ts") - assert.Check(t, service.GetScriptInfo("/home/projects/TS/p1/src/x.ts") == nil) + assert.Check(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p1/src/x.ts")) == nil) assert.Check(t, service.Projects()[0].GetProgram().GetSourceFile("/home/projects/TS/p1/src/x.ts") == nil) - assert.Equal(t, service.SourceFileCount(), 1) + assert.Equal(t, service.DocumentStore().SourceFileCount(), 1) err := host.FS().WriteFile("/home/projects/TS/p1/src/x.ts", "", false) assert.NilError(t, err) service.OpenFile("/home/projects/TS/p1/src/x.ts", "", core.ScriptKindTS, "") - assert.Equal(t, service.GetScriptInfo("/home/projects/TS/p1/src/x.ts").Text(), "") + assert.Equal(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p1/src/x.ts")).Text(), "") assert.Check(t, service.Projects()[0].GetProgram().GetSourceFile("/home/projects/TS/p1/src/x.ts") != nil) assert.Equal(t, service.Projects()[0].GetProgram().GetSourceFile("/home/projects/TS/p1/src/x.ts").Text(), "") }) @@ -316,14 +316,14 @@ func TestService(t *testing.T) { assert.NilError(t, err) service.CloseFile("/home/projects/TS/p1/src/x.ts") - assert.Check(t, service.GetScriptInfo("/home/projects/TS/p1/src/x.ts") == nil) + assert.Check(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p1/src/x.ts")) == nil) assert.Check(t, service.Projects()[0].GetProgram().GetSourceFile("/home/projects/TS/p1/src/x.ts") == nil) err = host.FS().WriteFile("/home/projects/TS/p1/src/x.ts", "", false) assert.NilError(t, err) service.OpenFile("/home/projects/TS/p1/src/x.ts", "", core.ScriptKindTS, "") - assert.Equal(t, service.GetScriptInfo("/home/projects/TS/p1/src/x.ts").Text(), "") + assert.Equal(t, service.DocumentStore().GetScriptInfoByPath(serviceToPath(service, "/home/projects/TS/p1/src/x.ts")).Text(), "") assert.Check(t, service.Projects()[0].GetProgram().GetSourceFile("/home/projects/TS/p1/src/x.ts") != nil) assert.Equal(t, service.Projects()[0].GetProgram().GetSourceFile("/home/projects/TS/p1/src/x.ts").Text(), "") }) diff --git a/internal/project/util_test.go b/internal/project/util_test.go new file mode 100644 index 0000000000..9dd319853f --- /dev/null +++ b/internal/project/util_test.go @@ -0,0 +1,19 @@ +package project_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/project" + "github.com/microsoft/typescript-go/internal/tspath" + "gotest.tools/v3/assert" +) + +func configFileExists(t *testing.T, service *project.Service, path tspath.Path, exists bool) { + t.Helper() + _, loaded := service.ConfigFileRegistry().ConfigFiles.Load(path) + assert.Equal(t, loaded, exists, "config file %s should exist: %v", path, exists) +} + +func serviceToPath(service *project.Service, fileName string) tspath.Path { + return tspath.ToPath(fileName, service.GetCurrentDirectory(), service.FS().UseCaseSensitiveFileNames()) +}