1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:04:44 -07:00

internal/lsp: fix bug renaming local vars with test files present

This fix adds all packages to the renamer packages map.

Renaming performs checks on each package to make sure there are no
conflicts. If there are multiple packages, each package needs to be
checked. The packages were being incorrectly added to the map and were
all being put under a single key.

Fixes golang/go#33664

Change-Id: I68466ce34ac49b700ce6d14ce0b53e2795926fa9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190399
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Suzy Mueller 2019-08-15 10:29:18 -04:00
parent ea4142463b
commit 9065c182e3
5 changed files with 18 additions and 7 deletions

View File

@ -23,7 +23,6 @@ import (
type renamer struct {
ctx context.Context
fset *token.FileSet
pkg Package // the package containing the declaration of the ident
refs []*ReferenceInfo
objsToUpdate map[types.Object]bool
hadConflicts bool
@ -66,7 +65,6 @@ func (i *IdentifierInfo) Rename(ctx context.Context, newName string) (map[span.U
r := renamer{
ctx: ctx,
fset: i.File.FileSet(),
pkg: i.pkg,
refs: refs,
objsToUpdate: make(map[types.Object]bool),
from: i.Name,
@ -74,12 +72,12 @@ func (i *IdentifierInfo) Rename(ctx context.Context, newName string) (map[span.U
packages: make(map[*types.Package]Package),
}
for _, from := range refs {
r.packages[i.pkg.GetTypes()] = from.pkg
r.packages[from.pkg.GetTypes()] = from.pkg
}
// Check that the renaming of the identifier is ok.
for _, from := range refs {
r.check(from.obj)
for _, ref := range refs {
r.check(ref.obj)
}
if r.hadConflicts {
return nil, errors.Errorf(r.errors)
@ -139,7 +137,7 @@ func (r *renamer) update() (map[span.URI][]TextEdit, error) {
continue
}
doc := r.docComment(r.pkg, ref.ident)
doc := r.docComment(ref.pkg, ref.ident)
if doc == nil {
continue
}

View File

@ -3,4 +3,5 @@ package testy
type tt int //@rename("tt", "testyType")
func a() {
foo := 42 //@rename("foo", "bar")
}

View File

@ -1,3 +1,13 @@
-- bar-rename --
testy.go:
package testy
type tt int //@rename("tt", "testyType")
func a() {
bar := 42 //@rename("foo", "bar")
}
-- testyType-rename --
testy.go:
package testy
@ -5,5 +15,6 @@ package testy
type testyType int //@rename("tt", "testyType")
func a() {
foo := 42 //@rename("foo", "bar")
}

View File

@ -5,6 +5,7 @@ package testy
type tt int //@rename("tt", "testyType")
func b() {
foo := 42 //@rename("foo", "bar")
}
testy_test.go:

View File

@ -35,7 +35,7 @@ const (
ExpectedTypeDefinitionsCount = 2
ExpectedHighlightsCount = 2
ExpectedReferencesCount = 5
ExpectedRenamesCount = 16
ExpectedRenamesCount = 17
ExpectedSymbolsCount = 1
ExpectedSignaturesCount = 21
ExpectedLinksCount = 4