internal/lsp: skip packages load for auxilary go.mod changes

This change will skip packages.load calls when a go.mod file changes if that go.mod file is not the go.mod file associated with the view.

Change-Id: I23a214a89203dd58417f3e2f69725ce3b669a5ca
Reviewed-on: https://go-review.googlesource.com/c/tools/+/217238
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Rohan Challa 2020-01-31 13:59:11 -05:00
parent c4cbd3b08f
commit a014e0aa6a
2 changed files with 9 additions and 4 deletions

View File

@ -752,7 +752,8 @@ func (s *snapshot) shouldLoad(ctx context.Context, originalFH, currentFH source.
}
// If a go.mod file's contents have changed, always invalidate metadata.
if kind := originalFH.Identity().Kind; kind == source.Mod {
return true
modfile, _ := s.view.ModFiles()
return originalFH.Identity().URI == modfile
}
// Get the original and current parsed files in order to check package name and imports.
original, _, _, originalErr := s.view.session.cache.ParseGoHandle(originalFH, source.ParseHeader).Parse(ctx)

View File

@ -147,11 +147,15 @@ func (s *Server) didModifyFiles(ctx context.Context, modifications []source.File
if err != nil {
return nil, err
}
// If a modification comes in for a go.mod file,
// and the view was never properly initialized,
// try to recreate the associated view.
// If a modification comes in for the view's go.mod file and the view
// was never properly initialized, or the view does not have
// a go.mod file, try to recreate the associated view.
switch fh.Identity().Kind {
case source.Mod:
modfile, _ := snapshot.View().ModFiles()
if modfile != "" || fh.Identity().URI != modfile {
continue
}
newSnapshot, err := snapshot.View().Rebuild(ctx)
if err != nil {
return nil, err