File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ type snapshot struct {
42
42
project * Project
43
43
positionEncoding lsproto.PositionEncodingKind
44
44
program * compiler.Program
45
+ lineMaps collections.SyncMap [* ast.SourceFile , * ls.LineMap ]
45
46
}
46
47
47
48
// GetLineMap implements ls.Host.
@@ -51,7 +52,13 @@ func (s *snapshot) GetLineMap(fileName string) *ls.LineMap {
51
52
if s .project .getFileVersion (file ) == scriptInfo .Version () {
52
53
return scriptInfo .LineMap ()
53
54
}
54
- return ls .ComputeLineStarts (file .Text ())
55
+ // The version changed; recompute the line map.
56
+ // !!! This shouldn't happen so often, but does. Probably removable once snapshotting is finished.
57
+ if cached , ok := s .lineMaps .Load (file ); ok {
58
+ return cached
59
+ }
60
+ lineMap , _ := s .lineMaps .LoadOrStore (file , ls .ComputeLineStarts (file .Text ()))
61
+ return lineMap
55
62
}
56
63
57
64
// GetPositionEncoding implements ls.Host.
You can’t perform that action at this time.
0 commit comments