mirror of
https://github.com/golang/go
synced 2024-11-18 14:04:45 -07:00
internal/lsp/source: suppress completions in ellipsis
Editors typically trigger completion automatically after ".". This pops up annoying, useless completions after "..." variadic param, such as "foo(bar...<>)". We now suppress completions in or directly after the ellipsis. Fixes golang/go#37358. Change-Id: I9fc94fbdf69429bd787bcb2c643f4f730e24154d Reviewed-on: https://go-review.googlesource.com/c/tools/+/222200 Run-TryBot: Muir Manders <muir@mnd.rs> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
aa4048aca1
commit
92d517f97b
@ -423,7 +423,7 @@ func (e ErrIsDefinition) Error() string {
|
||||
// The selection is computed based on the preceding identifier and can be used by
|
||||
// the client to score the quality of the completion. For instance, some clients
|
||||
// may tolerate imperfect matches as valid completion results, since users may make typos.
|
||||
func Completion(ctx context.Context, snapshot Snapshot, fh FileHandle, pos protocol.Position) ([]CompletionItem, *Selection, error) {
|
||||
func Completion(ctx context.Context, snapshot Snapshot, fh FileHandle, protoPos protocol.Position) ([]CompletionItem, *Selection, error) {
|
||||
ctx, done := trace.StartSpan(ctx, "source.Completion")
|
||||
defer done()
|
||||
|
||||
@ -437,7 +437,7 @@ func Completion(ctx context.Context, snapshot Snapshot, fh FileHandle, pos proto
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
spn, err := m.PointSpan(pos)
|
||||
spn, err := m.PointSpan(protoPos)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -452,9 +452,18 @@ func Completion(ctx context.Context, snapshot Snapshot, fh FileHandle, pos proto
|
||||
return nil, nil, errors.Errorf("cannot find node enclosing position")
|
||||
}
|
||||
|
||||
// Skip completion inside any kind of literal.
|
||||
if _, ok := path[0].(*ast.BasicLit); ok {
|
||||
pos := rng.Start
|
||||
|
||||
switch n := path[0].(type) {
|
||||
case *ast.BasicLit:
|
||||
// Skip completion inside any kind of literal.
|
||||
return nil, nil, nil
|
||||
case *ast.CallExpr:
|
||||
if n.Ellipsis.IsValid() && pos > n.Ellipsis && pos <= n.Ellipsis+token.Pos(len("...")) {
|
||||
// Don't offer completions inside or directly after "...". For
|
||||
// example, don't offer completions at "<>" in "foo(bar...<>").
|
||||
return nil, nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
opts := snapshot.View().Options()
|
||||
@ -466,7 +475,7 @@ func Completion(ctx context.Context, snapshot Snapshot, fh FileHandle, pos proto
|
||||
filename: fh.Identity().URI.Filename(),
|
||||
file: file,
|
||||
path: path,
|
||||
pos: rng.Start,
|
||||
pos: pos,
|
||||
seen: make(map[types.Object]bool),
|
||||
enclosingFunc: enclosingFunction(path, rng.Start, pkg.GetTypesInfo()),
|
||||
enclosingCompositeLiteral: enclosingCompositeLiteral(path, rng.Start, pkg.GetTypesInfo()),
|
||||
|
@ -28,3 +28,7 @@ func f() {} //@item(vVarArg, "f", "func()", "func")
|
||||
func _() {
|
||||
qux(f) //@snippet(")", vVarArg, "f", "f")
|
||||
}
|
||||
|
||||
func _() {
|
||||
foo(0, []string{}...) //@complete(")")
|
||||
}
|
||||
|
2
internal/lsp/testdata/lsp/summary.txt.golden
vendored
2
internal/lsp/testdata/lsp/summary.txt.golden
vendored
@ -1,6 +1,6 @@
|
||||
-- summary --
|
||||
CodeLensCount = 0
|
||||
CompletionsCount = 230
|
||||
CompletionsCount = 231
|
||||
CompletionSnippetCount = 68
|
||||
UnimportedCompletionsCount = 11
|
||||
DeepCompletionsCount = 5
|
||||
|
Loading…
Reference in New Issue
Block a user