mirror of
https://github.com/golang/go
synced 2024-10-01 04:18:33 -06:00
5ae4576c3a
Sometimes the prefix of the thing you want to complete is a keyword. For example: variance := 123 fmt.Println(var<>) In this case the parser produces an *ast.BadExpr which breaks completion. We now repair this BadExpr by replacing it with an *ast.Ident named "var". We also repair empty decls using a similar approach. This fixes cases like: var typeName string type<> // want to complete to "typeName" We also fix accidental keywords in selectors, such as: foo.var<> The parser produces a phantom "_" in place of the keyword, so we swap it back for an *ast.Ident named "var". In general, though, accidental keywords wreak havoc on the AST so we can only do so much. There are still many cases where a keyword prefix breaks completion. Perhaps in the future the parser can be cursor/in-progress-edit aware and turn accidental keywords into identifiers. Fixes golang/go#34332. PS I tweaked nodeContains() to include n.End() to fix a test failure against tip related to a change to go/parser. When a syntax error is present, an *ast.BlockStmt's End() is now set to the block's final statement's End() (earlier than what it used to be). In order for the cursor pos to test "inside" the block in this case I had to relax the End() comparison. Change-Id: Ib45952cf086cc974f1578298df3dd12829344faa Reviewed-on: https://go-review.googlesource.com/c/tools/+/209438 Run-TryBot: Muir Manders <muir@mnd.rs> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org> |
||
---|---|---|
.. | ||
comment_test.go | ||
comment.go | ||
completion_format.go | ||
completion_keywords.go | ||
completion_labels.go | ||
completion_literal.go | ||
completion_snippet.go | ||
completion.go | ||
deep_completion.go | ||
diagnostics.go | ||
errors.go | ||
folding_range.go | ||
format.go | ||
highlight.go | ||
hover.go | ||
identifier.go | ||
implementation.go | ||
options.go | ||
references.go | ||
rename_check.go | ||
rename.go | ||
signature_help.go | ||
source_test.go | ||
suggested_fix.go | ||
symbols.go | ||
tidy.go | ||
util.go | ||
view.go |