aboutsummaryrefslogtreecommitdiff
path: root/internal/lsp/cache/parse.go
diff options
context:
space:
mode:
authorHeschi Kreinick <heschi@google.com>2020-07-24 17:17:13 -0400
committerHeschi Kreinick <heschi@google.com>2020-08-04 01:15:35 +0000
commit6c149bb5ef0db65038b2abbe6c6d0128f2f2cd90 (patch)
tree761727ba857d6afc025efab55ffc3759d0e04764 /internal/lsp/cache/parse.go
parent5a22b632c5de95bde241c5faab365d9aaf928c06 (diff)
downloadgolang-x-tools-6c149bb5ef0db65038b2abbe6c6d0128f2f2cd90.tar.gz
internal/lsp/cache: store parseGoHandles
parseGoHandles have lifetimes separate from the packages they belong to. For example, a package may be invalidated by a change to one of its files, but we still want to retain the parse results for all the rest. Track them explicitly. Change-Id: I03a4ffe283bf2b252d2d838bdb2cf332cd981075 Reviewed-on: https://go-review.googlesource.com/c/tools/+/245059 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Diffstat (limited to 'internal/lsp/cache/parse.go')
-rw-r--r--internal/lsp/cache/parse.go30
1 files changed, 14 insertions, 16 deletions
diff --git a/internal/lsp/cache/parse.go b/internal/lsp/cache/parse.go
index 8f92b37bf..b5ce9dff6 100644
--- a/internal/lsp/cache/parse.go
+++ b/internal/lsp/cache/parse.go
@@ -51,27 +51,31 @@ type parseGoData struct {
err error // any other errors
}
-func (c *Cache) parseGoHandle(ctx context.Context, fh source.FileHandle, mode source.ParseMode) *parseGoHandle {
+func (s *snapshot) parseGoHandle(ctx context.Context, fh source.FileHandle, mode source.ParseMode) *parseGoHandle {
key := parseKey{
file: fh.FileIdentity(),
mode: mode,
}
- parseHandle := c.store.Bind(key, func(ctx context.Context, arg memoize.Arg) interface{} {
+ if pgh := s.getGoFile(key); pgh != nil {
+ return pgh
+ }
+ parseHandle := s.view.session.cache.store.Bind(key, func(ctx context.Context, arg memoize.Arg) interface{} {
snapshot := arg.(*snapshot)
return parseGo(ctx, snapshot.view.session.cache.fset, fh, mode)
})
- astHandle := c.store.Bind(astCacheKey(key), func(ctx context.Context, arg memoize.Arg) interface{} {
+ astHandle := s.view.session.cache.store.Bind(astCacheKey(key), func(ctx context.Context, arg memoize.Arg) interface{} {
snapshot := arg.(*snapshot)
return buildASTCache(ctx, snapshot, parseHandle)
})
- return &parseGoHandle{
+ pgh := &parseGoHandle{
handle: parseHandle,
file: fh,
mode: mode,
astCacheHandle: astHandle,
}
+ return s.addGoFile(key, pgh)
}
func (pgh *parseGoHandle) String() string {
@@ -87,7 +91,7 @@ func (pgh *parseGoHandle) Mode() source.ParseMode {
}
func (s *snapshot) ParseGo(ctx context.Context, fh source.FileHandle, mode source.ParseMode) (*source.ParsedGoFile, error) {
- pgh := s.view.session.cache.parseGoHandle(ctx, fh, mode)
+ pgh := s.parseGoHandle(ctx, fh, mode)
pgf, _, err := s.parseGo(ctx, pgh)
return pgf, err
}
@@ -107,18 +111,14 @@ func (s *snapshot) PosToDecl(ctx context.Context, pgf *source.ParsedGoFile) (map
return nil, err
}
- pgh := s.view.session.cache.parseGoHandle(ctx, fh, pgf.Mode)
+ pgh := s.parseGoHandle(ctx, fh, pgf.Mode)
d, err := pgh.astCacheHandle.Get(ctx, s)
if err != nil {
return nil, err
}
data := d.(*astCacheData)
- if data.err != nil {
- return nil, data.err
- }
-
- return data.posToDecl, nil
+ return data.posToDecl, data.err
}
func (s *snapshot) PosToField(ctx context.Context, pgf *source.ParsedGoFile) (map[token.Pos]*ast.Field, error) {
@@ -127,17 +127,14 @@ func (s *snapshot) PosToField(ctx context.Context, pgf *source.ParsedGoFile) (ma
return nil, err
}
- pgh := s.view.session.cache.parseGoHandle(ctx, fh, pgf.Mode)
+ pgh := s.parseGoHandle(ctx, fh, pgf.Mode)
d, err := pgh.astCacheHandle.Get(ctx, s)
if err != nil || d == nil {
return nil, err
}
data := d.(*astCacheData)
- if data.err != nil {
- return nil, data.err
- }
- return data.posToField, nil
+ return data.posToField, data.err
}
type astCacheData struct {
@@ -317,6 +314,7 @@ func parseGo(ctx context.Context, fset *token.FileSet, fh source.FileHandle, mod
Converter: span.NewTokenConverter(fset, tok),
Content: buf,
}
+
return &parseGoData{
parsed: &source.ParsedGoFile{
URI: fh.URI(),