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
25 changes: 3 additions & 22 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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())
}
Expand Down
21 changes: 1 addition & 20 deletions internal/compiler/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
21 changes: 9 additions & 12 deletions internal/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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

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