1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:14:46 -07:00

internal/lsp: trigger signature help after completing a function

Change-Id: Ib0ee79a11dd828c77bdf22a19a24ed9d883d8393
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172600
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Rebecca Stambler 2019-04-17 14:31:17 -04:00
parent 34437f544f
commit 780da32332
3 changed files with 17 additions and 9 deletions

View File

@ -33,20 +33,16 @@ func (s *Server) completion(ctx context.Context, params *protocol.CompletionPara
}
items, prefix, err := source.Completion(ctx, f, rng.Start)
if err != nil {
s.log.Infof(ctx, "no completions found for %s:%v:%v", uri, int(params.Position.Line), int(params.Position.Character))
s.log.Infof(ctx, "no completions found for %s:%v:%v: %v", uri, int(params.Position.Line), int(params.Position.Character), err)
items = []source.CompletionItem{}
}
return &protocol.CompletionList{
IsIncomplete: false,
Items: toProtocolCompletionItems(items, prefix, params.Position, s.snippetsSupported, s.usePlaceholders),
Items: toProtocolCompletionItems(items, prefix, params.Position, s.insertTextFormat, s.usePlaceholders),
}, nil
}
func toProtocolCompletionItems(candidates []source.CompletionItem, prefix string, pos protocol.Position, snippetsSupported, usePlaceholders bool) []protocol.CompletionItem {
insertTextFormat := protocol.PlainTextTextFormat
if snippetsSupported {
insertTextFormat = protocol.SnippetTextFormat
}
func toProtocolCompletionItems(candidates []source.CompletionItem, prefix string, pos protocol.Position, insertTextFormat protocol.InsertTextFormat, usePlaceholders bool) []protocol.CompletionItem {
sort.SliceStable(candidates, func(i, j int) bool {
return candidates[i].Score > candidates[j].Score
})
@ -79,6 +75,15 @@ func toProtocolCompletionItems(candidates []source.CompletionItem, prefix string
FilterText: insertText,
Preselect: i == 0,
}
// Trigger signature help for any function or method completion.
// This is helpful even if a function does not have parameters,
// since we show return types as well.
switch item.Kind {
case protocol.FunctionCompletion, protocol.MethodCompletion:
item.Command = &protocol.Command{
Command: "editor.action.triggerParameterHints",
}
}
items = append(items, item)
}
return items

View File

@ -98,7 +98,10 @@ func (s *Server) initialize(ctx context.Context, params *protocol.InitializePara
func (s *Server) setClientCapabilities(caps protocol.ClientCapabilities) {
// Check if the client supports snippets in completion items.
s.snippetsSupported = caps.TextDocument.Completion.CompletionItem.SnippetSupport
s.insertTextFormat = protocol.PlainTextTextFormat
if caps.TextDocument.Completion.CompletionItem.SnippetSupport {
s.insertTextFormat = protocol.SnippetTextFormat
}
// Check if the client supports configuration messages.
s.configurationSupported = caps.Workspace.Configuration
s.dynamicConfigurationSupported = caps.Workspace.DidChangeConfiguration.DynamicRegistration

View File

@ -74,7 +74,7 @@ type Server struct {
// Configurations.
// TODO(rstambler): Separate these into their own struct?
usePlaceholders bool
snippetsSupported bool
insertTextFormat protocol.InsertTextFormat
configurationSupported bool
dynamicConfigurationSupported bool