Debian Codegraph @

gopls/internal/server/signature_help.go

raw symbols SCIP
1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package server
6
7 import (
8 "context"
9
10 "golang.org/x/tools/gopls/internal/file"
11 "golang.org/x/tools/gopls/internal/golang"
12 "golang.org/x/tools/gopls/internal/label"
13 "golang.org/x/tools/gopls/internal/protocol"
14 "golang.org/x/tools/internal/event"
15 )
16
17 func (s *server) SignatureHelp(ctx context.Context, params *protocol.SignatureHelpParams) (*protocol.SignatureHelp, error) {
18 ctx, done := event.Start(ctx, "server.SignatureHelp", label.URI.Of(params.TextDocument.URI))
19 defer done()
20
21 fh, snapshot, release, err := s.session.FileOf(ctx, params.TextDocument.URI)
22 if err != nil {
23 return nil, err
24 }
25 defer release()
26
27 if snapshot.FileKind(fh) != file.Go {
28 return nil, nil // empty result
29 }
30
31 info, err := golang.SignatureHelp(ctx, snapshot, fh, params.Range, params.Context)
32 if err != nil {
33 // TODO(rfindley): is this correct? Apparently, returning an error from
34 // signatureHelp is distracting in some editors, though I haven't confirmed
35 // that recently.
36 //
37 // It's unclear whether we still need to avoid returning this error result.
38 event.Error(ctx, "signature help failed", err, label.Position.Of(params.Range.Start), label.Position.Of(params.Range.End))
39 return nil, nil
40 }
41 if info == nil {
42 return nil, nil
43 }
44 return &protocol.SignatureHelp{
45 Signatures: []protocol.SignatureInformation{*info},
46 ActiveSignature: 0,
47 ActiveParameter: info.ActiveParameter,
48 }, nil
49 }