Skip to content

Commit b2443cf

Browse files
Invalidate the whole "top level objects" cache (#155)
... whenever files are changed. The reason for that is that it's hard to figure out where imports actually lead, so invalidations sometimes won't happen, leading to invalid language server suggestions
1 parent 6f0feae commit b2443cf

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

pkg/cache/cache.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"errors"
55
"fmt"
66
"os"
7-
"path/filepath"
87
"strings"
98
"sync"
109

@@ -56,11 +55,9 @@ func (c *Cache) Put(new *Document) error {
5655
c.docs[uri] = new
5756

5857
// Invalidate the TopLevelObject cache
59-
for k := range c.topLevelObjects {
60-
if strings.HasSuffix(k, filepath.Base(uri.SpanURI().Filename())) {
61-
delete(c.topLevelObjects, k)
62-
}
63-
}
58+
// We can't easily invalidate the cache for a single file (hard to figure out where the import actually leads),
59+
// so we just clear the whole thing
60+
c.topLevelObjects = make(map[string][]*ast.DesugaredObject)
6461

6562
return nil
6663
}

pkg/server/server.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ func (s *Server) DidChange(_ context.Context, params *protocol.DidChangeTextDocu
105105
}
106106
}
107107
}
108-
return nil
108+
109+
return s.cache.Put(doc)
109110
}
110111

111112
func (s *Server) DidOpen(_ context.Context, params *protocol.DidOpenTextDocumentParams) (err error) {

0 commit comments

Comments
 (0)