Skip to content

Commit a755353

Browse files
committed
More refactor and fixes
1 parent b6e5833 commit a755353

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

internal/api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (api *API) LoadProject(configFileName string) (*ProjectResponse, error) {
220220
configFileName = api.toAbsoluteFileName(configFileName)
221221
configFilePath := api.toPath(configFileName)
222222
p := project.NewConfiguredProject(configFileName, configFilePath, api)
223-
if err := p.LoadConfig(); err != nil {
223+
if _, err := p.LoadConfig(); err != nil {
224224
return nil, err
225225
}
226226
p.GetProgram()

internal/project/project.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ func NewProject(name string, kind Kind, currentDirectory string, host ProjectHos
194194
kind: kind,
195195
currentDirectory: currentDirectory,
196196
rootFileNames: &collections.OrderedMap[tspath.Path, string]{},
197+
dirty: true,
197198
}
198199
project.comparePathsOptions = tspath.ComparePathsOptions{
199200
CurrentDirectory: currentDirectory,
@@ -490,7 +491,9 @@ func (p *Project) updateGraph() bool {
490491
p.programConfig = nil
491492
p.pendingReload = PendingReloadNone
492493
case PendingReloadFull:
493-
if err := p.loadConfig(); err != nil {
494+
var err error
495+
writeFileNames, err = p.LoadConfig()
496+
if err != nil {
494497
panic(fmt.Sprintf("failed to reload config: %v", err))
495498
}
496499
}
@@ -865,15 +868,7 @@ func (p *Project) AddInferredProjectRoot(info *ScriptInfo) {
865868
p.markAsDirtyLocked()
866869
}
867870

868-
func (p *Project) LoadConfig() error {
869-
if err := p.loadConfig(); err != nil {
870-
return err
871-
}
872-
p.markAsDirty()
873-
return nil
874-
}
875-
876-
func (p *Project) loadConfig() error {
871+
func (p *Project) LoadConfig() (bool, error) {
877872
if p.kind != KindConfigured {
878873
panic("loadConfig called on non-configured project")
879874
}
@@ -906,13 +901,12 @@ func (p *Project) loadConfig() error {
906901
p.parsedCommandLine = parsedCommandLine
907902
p.compilerOptions = parsedCommandLine.CompilerOptions()
908903
p.typeAcquisition = parsedCommandLine.TypeAcquisition()
909-
p.setRootFiles(parsedCommandLine.FileNames())
904+
return p.setRootFiles(parsedCommandLine.FileNames()), nil
910905
} else {
911906
p.compilerOptions = &core.CompilerOptions{}
912907
p.typeAcquisition = nil
913-
return fmt.Errorf("could not read file %q", p.configFileName)
908+
return false, fmt.Errorf("could not read file %q", p.configFileName)
914909
}
915-
return nil
916910
}
917911

918912
// setRootFiles returns true if the set of root files has changed.

internal/project/service.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"maps"
8+
"runtime"
89
"strings"
910
"sync"
1011

@@ -219,6 +220,7 @@ func (s *Service) OpenFile(fileName string, fileContent string, scriptKind core.
219220
}
220221
result := s.assignProjectToOpenedScriptInfo(info)
221222
s.cleanupProjectsAndScriptInfos(info, result)
223+
s.printMemoryUsage()
222224
s.printProjects()
223225
}
224226

@@ -929,3 +931,14 @@ func (s *Service) printProjects() {
929931
func (s *Service) logf(format string, args ...any) {
930932
s.Log(fmt.Sprintf(format, args...))
931933
}
934+
935+
func (s *Service) printMemoryUsage() {
936+
runtime.GC() // Force garbage collection to get accurate memory stats
937+
var memStats runtime.MemStats
938+
runtime.ReadMemStats(&memStats)
939+
940+
s.logf("Alloc: %v KB\n", memStats.Alloc/1024)
941+
s.logf("TotalAlloc: %v KB\n", memStats.TotalAlloc/1024)
942+
s.logf("Sys: %v KB\n", memStats.Sys/1024)
943+
s.logf("NumGC: %v\n", memStats.NumGC)
944+
}

0 commit comments

Comments
 (0)