gopls/internal/lsp: remove access to mutable session state from the view
To avoid concurrency bugs and/or operation on inconsistent session
state, remove visibility into the session from views. In a few places,
this refactoring highlighted bugs (such as incorrect usage of
view.SetOptions).
This broke one of the debug templates, for which it was simply easier to
remove the back-link from view to session.
Change-Id: I4dbce0dcebab6f25a9c70524310ae1e0e04e2d97
Reviewed-on: https://go-review.googlesource.com/c/tools/+/453815
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
diff --git a/gopls/internal/lsp/cache/snapshot.go b/gopls/internal/lsp/cache/snapshot.go
index 1f738c6..5a15641 100644
--- a/gopls/internal/lsp/cache/snapshot.go
+++ b/gopls/internal/lsp/cache/snapshot.go
@@ -258,7 +258,7 @@
}
func (s *snapshot) FileSet() *token.FileSet {
- return s.view.session.cache.fset
+ return s.view.cache.fset
}
func (s *snapshot) ModFiles() []span.URI {
@@ -376,7 +376,7 @@
if typesinternal.SetUsesCgo(&types.Config{}) {
cfg.Mode |= packages.LoadMode(packagesinternal.TypecheckCgo)
}
- packagesinternal.SetGoCmdRunner(cfg, s.view.session.gocmdRunner)
+ packagesinternal.SetGoCmdRunner(cfg, s.view.gocmdRunner)
return cfg
}
@@ -387,7 +387,7 @@
}
defer cleanup()
- return s.view.session.gocmdRunner.Run(ctx, *inv)
+ return s.view.gocmdRunner.Run(ctx, *inv)
}
func (s *snapshot) RunGoCommandPiped(ctx context.Context, mode source.InvocationFlags, inv *gocommand.Invocation, stdout, stderr io.Writer) error {
@@ -396,7 +396,7 @@
return err
}
defer cleanup()
- return s.view.session.gocmdRunner.RunPiped(ctx, *inv, stdout, stderr)
+ return s.view.gocmdRunner.RunPiped(ctx, *inv, stdout, stderr)
}
func (s *snapshot) RunGoCommands(ctx context.Context, allowNetwork bool, wd string, run func(invoke func(...string) (*bytes.Buffer, error)) error) (bool, []byte, []byte, error) {
@@ -417,7 +417,7 @@
invoke := func(args ...string) (*bytes.Buffer, error) {
inv.Verb = args[0]
inv.Args = args[1:]
- return s.view.session.gocmdRunner.Run(ctx, *inv)
+ return s.view.gocmdRunner.Run(ctx, *inv)
}
if err := run(invoke); err != nil {
return false, nil, nil, err
@@ -1319,7 +1319,7 @@
return fh, nil
}
- fh, err := s.view.session.cache.getFile(ctx, f.URI()) // read the file
+ fh, err := s.view.cache.getFile(ctx, f.URI()) // read the file
if err != nil {
return nil, err
}