forked from golang/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/lsp/source: re-parse if needed when collecting identifier info
With the new ParseExported logic, we can lose some unexported fields on exported structs. This can lead to misleading or malformatted hover information. Fix this by ensuring we always extract the Spec from a full parse. Since this path is only hit via user-initiated requests (and should only be hit ~once per request), it is preferable to do the parse on-demand rather than parse via the cache and risk pinning the full AST for the remaining duration of the session. For golang/go#46158 Change-Id: Ib3eb61c3f75e16199eb492e3e129ba875bd8553e Reviewed-on: https://go-review.googlesource.com/c/tools/+/320550 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
- Loading branch information
Showing
7 changed files
with
146 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ go 1.12 | |
package hi | ||
var Goodbye error | ||
-- golang.org/x/[email protected]/go.mod -- | ||
-- golang.org/x/[email protected]/go.mod -- | ||
module golang.org/x/hello | ||
go 1.12 | ||
|
@@ -108,8 +108,8 @@ go 1.14 | |
require golang.org/x/hello v1.2.3 | ||
-- go.sum -- | ||
golang.org/x/hello v1.2.3 h1:jOtNXLsiCuLzU6KM3wRHidpc29IxcKpofHZiOW1hYKA= | ||
golang.org/x/hello v1.2.3/go.mod h1:X79D30QqR94cGK8aIhQNhCZLq4mIr5Gimj5qekF08rY= | ||
golang.org/x/hello v1.2.3 h1:7Wesfkx/uBd+eFgPrq0irYj/1XfmbvLV8jZ/W7C2Dwg= | ||
golang.org/x/hello v1.2.3/go.mod h1:OgtlzsxVMUUdsdQCIDYgaauCTH47B8T8vofouNJfzgY= | ||
-- main.go -- | ||
package main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2021 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package misc | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
. "golang.org/x/tools/internal/lsp/regtest" | ||
) | ||
|
||
func TestHoverUnexported(t *testing.T) { | ||
const proxy = ` | ||
-- golang.org/x/[email protected]/go.mod -- | ||
module golang.org/x/structs | ||
go 1.12 | ||
-- golang.org/x/[email protected]/types.go -- | ||
package structs | ||
type Mixed struct { | ||
Exported int | ||
unexported string | ||
} | ||
` | ||
const mod = ` | ||
-- go.mod -- | ||
module mod.com | ||
go 1.12 | ||
require golang.org/x/structs v1.0.0 | ||
-- go.sum -- | ||
golang.org/x/structs v1.0.0 h1:oxD5q25qV458xBbXf5+QX+Johgg71KFtwuJzt145c9A= | ||
golang.org/x/structs v1.0.0/go.mod h1:47gkSIdo5AaQaWJS0upVORsxfEr1LL1MWv9dmYF3iq4= | ||
-- main.go -- | ||
package main | ||
import "golang.org/x/structs" | ||
func main() { | ||
var _ structs.Mixed | ||
} | ||
` | ||
// TODO: use a nested workspace folder here. | ||
WithOptions( | ||
ProxyFiles(proxy), | ||
).Run(t, mod, func(t *testing.T, env *Env) { | ||
env.OpenFile("main.go") | ||
got, _ := env.Hover("main.go", env.RegexpSearch("main.go", "Mixed")) | ||
if !strings.Contains(got.Value, "unexported") { | ||
t.Errorf("Hover: missing expected field 'unexported'. Got:\n%q", got.Value) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters