Skip to content

Commit

Permalink
Invalidate the whole "top level objects" cache
Browse files Browse the repository at this point in the history
... 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
  • Loading branch information
julienduchesne committed Aug 26, 2024
1 parent 6f0feae commit 7f49262
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 3 additions & 6 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"sync"

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

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

return nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func (s *Server) DidChange(_ context.Context, params *protocol.DidChangeTextDocu
}
}
}
return nil

return s.cache.Put(doc)
}

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

0 comments on commit 7f49262

Please sign in to comment.