Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/lsp/cache: improve completion after dangling selector
Dangling selectors such as: func _() { x. } var x struct { i int } tend to wreak havoc on the AST. In the above example you didn't used to get completions because the declaration of "x" was missing from the AST. We now work around this issue by inserting a "_" into the source code before parsing to make the selector valid: func _() { x._ // <-- insert "_" here } var x struct { i int } This makes completion work as expected because the declaration of "x" is present in the AST. I had to change fixAST() to be called before fixSrc() because otherwise this new workaround in fixSrc() breaks the "accidental keyword" countermeasures in fixAST(). Fixes golang/go#31973. Updates golang/go#31687. Change-Id: Ia7ef6c045a9c71502d1b8b36f187ac9b8a85fe21 Reviewed-on: https://go-review.googlesource.com/c/tools/+/216484 Run-TryBot: Muir Manders <muir@mnd.rs> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
- Loading branch information
1 parent
885dec1
commit 88e652f
Showing
5 changed files
with
106 additions
and
10 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
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
7 changes: 7 additions & 0 deletions
7
internal/lsp/testdata/lsp/primarymod/danglingstmt/dangling_selector_1.go
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,7 @@ | ||
package danglingstmt | ||
|
||
func _() { | ||
x. //@rank(" //", danglingI) | ||
} | ||
|
||
var x struct { i int } //@item(danglingI, "i", "int", "field") |
8 changes: 8 additions & 0 deletions
8
internal/lsp/testdata/lsp/primarymod/danglingstmt/dangling_selector_2.go
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,8 @@ | ||
package danglingstmt | ||
|
||
import "golang.org/x/tools/internal/lsp/foo" | ||
|
||
func _() { | ||
foo. //@rank(" //", Foo) | ||
var _ = []string{foo.} //@rank("}", Foo) | ||
} |
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