mirror of https://github.com/golang/go.git
internal/lsp: run packages.Load only if imports are added or changed
Previously, we would reload if a user's import list decreased or simply changed order. This is not necessary. Now, we only re-run if a new import needs to be loaded. Updates golang/go#35388 Change-Id: I47874afe773dddb835ac27b18895e7a082950dc7 Reviewed-on: https://go-review.googlesource.com/c/tools/+/209057 Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
parent
427c522ce2
commit
ac417207ef
|
|
@ -96,13 +96,17 @@ func (c *cache) shouldLoad(ctx context.Context, s *snapshot, originalFH, current
|
|||
if original.Name.Name != current.Name.Name {
|
||||
return true
|
||||
}
|
||||
// If the package's imports have changed, re-run `go list`.
|
||||
if len(original.Imports) != len(current.Imports) {
|
||||
// If the package's imports have increased, definitely re-run `go list`.
|
||||
if len(original.Imports) < len(current.Imports) {
|
||||
return true
|
||||
}
|
||||
for i, importSpec := range original.Imports {
|
||||
// TODO: Handle the case where the imports have just been re-ordered.
|
||||
if importSpec.Path.Value != current.Imports[i].Path.Value {
|
||||
importSet := make(map[string]struct{})
|
||||
for _, importSpec := range original.Imports {
|
||||
importSet[importSpec.Path.Value] = struct{}{}
|
||||
}
|
||||
// If any of the current imports were not in the original imports.
|
||||
for _, importSpec := range current.Imports {
|
||||
if _, ok := importSet[importSpec.Path.Value]; !ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue