Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions internal/project/ata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand All @@ -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,
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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,
Expand Down
28 changes: 16 additions & 12 deletions internal/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -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()
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down