Skip to content
Merged
Changes from 3 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
40 changes: 35 additions & 5 deletions internal/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ type Project struct {
// rootFileNames was a map from Path to { NormalizedPath, ScriptInfo? } in the original code.
// But the ProjectService owns script infos, so it's not clear why there was an extra pointer.
rootFileNames *collections.OrderedMap[tspath.Path, string]
rootJSFileCount int
compilerOptions *core.CompilerOptions
typeAcquisition *core.TypeAcquisition
parsedCommandLine *tsoptions.ParsedCommandLine
Expand Down Expand Up @@ -561,6 +562,12 @@ func (p *Project) updateProgram() bool {
} else {
rootFileNames := p.GetRootFileNames()
compilerOptions := p.compilerOptions

if compilerOptions.MaxNodeModuleJsDepth == nil && p.rootJSFileCount > 0 {
compilerOptions = compilerOptions.Clone()
compilerOptions.MaxNodeModuleJsDepth = ptrTo(2)
}

p.programConfig = &tsoptions.ParsedCommandLine{
ParsedConfig: &core.ParsedOptions{
CompilerOptions: compilerOptions,
Expand Down Expand Up @@ -857,7 +864,7 @@ func (p *Project) RemoveFile(info *ScriptInfo, fileExists bool) {
p.mu.Lock()
defer p.mu.Unlock()
if p.isRoot(info) && p.kind == KindInferred {
p.rootFileNames.Delete(info.path)
p.deleteRootFileName(info.path)
p.typeAcquisition = nil
p.programConfig = nil
}
Expand All @@ -880,13 +887,12 @@ func (p *Project) AddInferredProjectRoot(info *ScriptInfo) {
if p.isRoot(info) {
panic("script info is already a root")
}
p.rootFileNames.Set(info.path, info.fileName)
p.setRootFileName(info.path, info.fileName)
p.programConfig = nil
p.typeAcquisition = nil
// !!!
// if p.kind == KindInferred {
// p.host.startWatchingConfigFilesForInferredProjectRoot(info.path);
// // handle JS toggling
// }
info.attachToProject(p)
p.markAsDirtyLocked()
Expand Down Expand Up @@ -929,7 +935,7 @@ func (p *Project) setRootFiles(rootFileNames []string) {
// !!! updateNonInferredProjectFiles uses a fileExists check, which I guess
// could be needed if a watcher fails?
newRootScriptInfos[path] = struct{}{}
p.rootFileNames.Set(path, file)
p.setRootFileName(path, file)
// if !isAlreadyRoot {
// if scriptInfo.isOpen {
// !!!s.removeRootOfInferredProjectIfNowPartOfOtherProject(scriptInfo)
Expand All @@ -940,12 +946,35 @@ func (p *Project) setRootFiles(rootFileNames []string) {
if p.rootFileNames.Size() > len(rootFileNames) {
for root := range p.rootFileNames.Keys() {
if _, ok := newRootScriptInfos[root]; !ok {
p.rootFileNames.Delete(root)
p.deleteRootFileName(root)
}
}
}
}

func (p *Project) setRootFileName(path tspath.Path, fileName string) {
has := p.rootFileNames.Has(path)
p.rootFileNames.Set(path, fileName)
if p.kind == KindInferred {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to check this ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like I should at least assert it for these functions? There's no guards elsewhere.

if !has && tspath.HasJSFileExtension(fileName) {
p.rootJSFileCount++
}
}
}

func (p *Project) deleteRootFileName(path tspath.Path) {
fileName, ok := p.rootFileNames.Get(path)
if !ok {
return
}
p.rootFileNames.Delete(path)
if p.kind == KindInferred {
if tspath.HasJSFileExtension(fileName) {
p.rootJSFileCount--
}
}
}

func (p *Project) clearSourceMapperCache() {
// !!!
}
Expand Down Expand Up @@ -1062,6 +1091,7 @@ func (p *Project) Close() {
}
}
p.rootFileNames = nil
p.rootJSFileCount = 0
p.parsedCommandLine = nil
p.programConfig = nil
p.checkerPool = nil
Expand Down