diff --git a/internal/project/ata_test.go b/internal/project/ata_test.go index b0ce457c55..cced33e9f6 100644 --- a/internal/project/ata_test.go +++ b/internal/project/ata_test.go @@ -285,14 +285,13 @@ func TestAta(t *testing.T) { }) t.Run("discover from node_modules", func(t *testing.T) { - t.Skip("Skip for now - to add back when we skip external library files to lookup typings for") t.Parallel() files := map[string]any{ "/user/username/projects/project/app.js": "", "/user/username/projects/project/package.json": `{ "dependencies": { - "jquery": "1.0.0", - }, + "jquery": "1.0.0" + } }`, "/user/username/projects/project/jsconfig.json": `{}`, "/user/username/projects/project/node_modules/commander/index.js": "", @@ -312,7 +311,6 @@ func TestAta(t *testing.T) { service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") - // Order is determinate since second install will run only after completing first one status := <-host.ServiceOptions.InstallStatus assert.Equal(t, status, project.TypingsInstallerStatus{ RequestId: 1, @@ -323,14 +321,13 @@ func TestAta(t *testing.T) { // Explicit types prevent automatic inclusion from package.json listing t.Run("discover from node_modules empty types", func(t *testing.T) { - t.Skip("Skip for now - to add back when we skip external library files to lookup typings for") t.Parallel() files := map[string]any{ "/user/username/projects/project/app.js": "", "/user/username/projects/project/package.json": `{ "dependencies": { - "jquery": "1.0.0", - }, + "jquery": "1.0.0" + } }`, "/user/username/projects/project/jsconfig.json": `{ "compilerOptions": { @@ -354,25 +351,23 @@ func TestAta(t *testing.T) { service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") - // Order is determinate since second install will run only after completing first one status := <-host.ServiceOptions.InstallStatus assert.Equal(t, status, project.TypingsInstallerStatus{ RequestId: 1, Project: p, - Status: "Success", + Status: "Skipped 0 typings", }) }) // A type reference directive will not resolve to the global typings cache t.Run("discover from node_modules explicit types", func(t *testing.T) { - t.Skip("Skip for now - to add back when we skip external library files to lookup typings for") t.Parallel() files := map[string]any{ "/user/username/projects/project/app.js": "", "/user/username/projects/project/package.json": `{ "dependencies": { - "jquery": "1.0.0", - }, + "jquery": "1.0.0" + } }`, "/user/username/projects/project/jsconfig.json": `{ "compilerOptions": { @@ -396,25 +391,23 @@ func TestAta(t *testing.T) { service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") - // Order is determinate since second install will run only after completing first one status := <-host.ServiceOptions.InstallStatus assert.Equal(t, status, project.TypingsInstallerStatus{ RequestId: 1, Project: p, - Status: "Success", + Status: "Skipped 0 typings", }) }) // However, explicit types will not prevent unresolved imports from pulling in typings t.Run("discover from node_modules empty types has import", func(t *testing.T) { - t.Skip("Skip for now - to add back when we skip external library files to lookup typings for") t.Parallel() files := map[string]any{ "/user/username/projects/project/app.js": `import "jquery";`, "/user/username/projects/project/package.json": `{ "dependencies": { - "jquery": "1.0.0", - }, + "jquery": "1.0.0" + } }`, "/user/username/projects/project/jsconfig.json": `{ "compilerOptions": { @@ -438,7 +431,6 @@ func TestAta(t *testing.T) { service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "") _, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js") - // Order is determinate since second install will run only after completing first one status := <-host.ServiceOptions.InstallStatus assert.Equal(t, status, project.TypingsInstallerStatus{ RequestId: 1, diff --git a/internal/project/project.go b/internal/project/project.go index a6d02be374..d2c5d6606c 100644 --- a/internal/project/project.go +++ b/internal/project/project.go @@ -635,6 +635,15 @@ func (p *Project) getTypeAcquisition() *core.TypeAcquisition { return p.typeAcquisition } +func (p *Project) setTypeAcquisition(typeAcquisition *core.TypeAcquisition) { + if typeAcquisition == nil || !typeAcquisition.Enable.IsTrue() { + p.unresolvedImports = nil + p.unresolvedImportsPerFile = nil + p.typingFiles = nil + } + p.typeAcquisition = typeAcquisition +} + func (p *Project) enqueueInstallTypingsForProject(oldProgram *compiler.Program, forceRefresh bool) { typingsInstaller := p.host.TypingsInstaller() if typingsInstaller == nil { @@ -643,10 +652,6 @@ func (p *Project) enqueueInstallTypingsForProject(oldProgram *compiler.Program, typeAcquisition := p.getTypeAcquisition() if typeAcquisition == nil || !typeAcquisition.Enable.IsTrue() { - // !!! sheetal Should be probably done where we set typeAcquisition - p.unresolvedImports = nil - p.unresolvedImportsPerFile = nil - p.typingFiles = nil return } @@ -871,7 +876,7 @@ func (p *Project) RemoveFile(info *ScriptInfo, fileExists bool) { defer p.mu.Unlock() if p.isRoot(info) && p.kind == KindInferred { p.rootFileNames.Delete(info.path) - p.typeAcquisition = nil + p.setTypeAcquisition(nil) p.programConfig = nil } p.onFileAddedOrRemoved() @@ -895,7 +900,7 @@ func (p *Project) AddInferredProjectRoot(info *ScriptInfo) { } p.rootFileNames.Set(info.path, info.fileName) p.programConfig = nil - p.typeAcquisition = nil + p.setTypeAcquisition(nil) // !!! // if p.kind == KindInferred { // p.host.startWatchingConfigFilesForInferredProjectRoot(info.path); @@ -924,11 +929,11 @@ func (p *Project) LoadConfig() error { ) p.compilerOptions = p.parsedCommandLine.CompilerOptions() - p.typeAcquisition = p.parsedCommandLine.TypeAcquisition() + p.setTypeAcquisition(p.parsedCommandLine.TypeAcquisition()) p.setRootFiles(p.parsedCommandLine.FileNames()) } else { p.compilerOptions = &core.CompilerOptions{} - p.typeAcquisition = nil + p.setTypeAcquisition(nil) return fmt.Errorf("could not read file %q", p.configFileName) } return nil @@ -983,10 +988,9 @@ func (p *Project) GetFileNames(excludeFilesFromExternalLibraries bool, excludeCo result := []string{} sourceFiles := p.program.GetSourceFiles() for _, sourceFile := range sourceFiles { - // !! This is probably ready to be implemented now? - // if excludeFilesFromExternalLibraries && p.program.IsSourceFileFromExternalLibrary(sourceFile) { - // continue; - // } + if excludeFilesFromExternalLibraries && p.program.IsSourceFileFromExternalLibrary(sourceFile) { + continue + } result = append(result, sourceFile.FileName()) } // if (!excludeConfigFiles) {