1
0
mirror of https://github.com/golang/go synced 2024-10-01 04:18:33 -06:00
go/internal/lsp/source
Muir Manders 5ae4576c3a internal/lsp: improve completion after accidental keywords
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>
2019-12-03 04:30:02 +00:00
..
comment_test.go internal/lsp: convert comments to markdown before sending to client 2019-10-04 18:35:38 +00:00
comment.go internal/lsp: convert comments to markdown before sending to client 2019-10-04 18:35:38 +00:00
completion_format.go internal/lsp: track and parse non-compiled go files 2019-11-25 19:20:50 +00:00
completion_keywords.go internal/lsp: add some keyword completions 2019-10-22 20:49:18 +00:00
completion_labels.go internal/lsp: fix label completion in range and type switch stmts 2019-10-22 21:33:09 +00:00
completion_literal.go internal/span: support line directives 2019-11-25 19:20:43 +00:00
completion_snippet.go internal/lsp: reorganize and refactor code 2019-11-21 02:33:28 +00:00
completion.go internal/lsp: improve completion after accidental keywords 2019-12-03 04:30:02 +00:00
deep_completion.go internal/lsp/source: attach Package to completions when available 2019-11-05 20:21:09 +00:00
diagnostics.go internal/lsp: rename CheckPackageHandle to PackageHandle 2019-12-02 18:29:46 +00:00
errors.go internal/lsp: move the missing imports handling into the metadata 2019-09-25 23:05:17 +00:00
folding_range.go internal/lsp: rename CheckPackageHandle to PackageHandle 2019-12-02 18:29:46 +00:00
format.go internal/lsp: rename CheckPackageHandle to PackageHandle 2019-12-02 18:29:46 +00:00
highlight.go internal/lsp: add nil check for control flow highlighting 2019-12-02 20:31:27 +00:00
hover.go internal/lsp: add documentation for package-level vars 2019-11-25 18:28:23 +00:00
identifier.go internal/lsp: rename CheckPackageHandle to PackageHandle 2019-12-02 18:29:46 +00:00
implementation.go internal/lsp: fixes premature return in find implementations 2019-11-26 21:00:16 +00:00
options.go internal/lsp: link to the new pkg.go.dev instead of godoc.org 2019-11-30 07:06:09 +00:00
references.go internal/lsp: rename CheckPackageHandle to PackageHandle 2019-12-02 18:29:46 +00:00
rename_check.go internal/lsp: improve literal func completion candidates 2019-11-07 21:18:00 +00:00
rename.go internal/lsp: use AST to construct placeholders 2019-11-25 01:11:57 +00:00
signature_help.go internal/lsp: rename CheckPackageHandle to PackageHandle 2019-12-02 18:29:46 +00:00
source_test.go internal/lsp: add control flow highlighting for functions 2019-12-02 19:01:20 +00:00
suggested_fix.go internal/lsp: move error range computations into cache package 2019-10-21 22:12:58 +00:00
symbols.go internal/lsp: rename CheckPackageHandle to PackageHandle 2019-12-02 18:29:46 +00:00
tidy.go internal/lsp: support running go mod tidy as a code action 2019-09-20 13:08:46 +00:00
util.go internal/lsp: add control flow highlighting for functions 2019-12-02 19:01:20 +00:00
view.go internal/lsp: rename CheckPackageHandle to PackageHandle 2019-12-02 18:29:46 +00:00