forked from system-pclub/GCatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signature_help.go
61 lines (55 loc) · 1.75 KB
/
signature_help.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package lsp
import (
"context"
"github.com/godaner/GCatch/tools/internal/lsp/protocol"
"github.com/godaner/GCatch/tools/internal/lsp/source"
"github.com/godaner/GCatch/tools/internal/span"
)
func (s *Server) signatureHelp(ctx context.Context, params *protocol.TextDocumentPositionParams) (*protocol.SignatureHelp, error) {
uri := span.NewURI(params.TextDocument.URI)
view := s.session.ViewOf(uri)
f, m, err := getGoFile(ctx, view, uri)
if err != nil {
return nil, err
}
spn, err := m.PointSpan(params.Position)
if err != nil {
return nil, err
}
rng, err := spn.Range(m.Converter)
if err != nil {
return nil, err
}
info, err := source.SignatureHelp(ctx, f, rng.Start)
if err != nil {
s.session.Logger().Infof(ctx, "no signature help for %s:%v:%v : %s", uri, int(params.Position.Line), int(params.Position.Character), err)
}
return toProtocolSignatureHelp(info), nil
}
func toProtocolSignatureHelp(info *source.SignatureInformation) *protocol.SignatureHelp {
if info == nil {
return &protocol.SignatureHelp{}
}
return &protocol.SignatureHelp{
ActiveParameter: float64(info.ActiveParameter),
ActiveSignature: 0, // there is only ever one possible signature
Signatures: []protocol.SignatureInformation{
{
Label: info.Label,
Parameters: toProtocolParameterInformation(info.Parameters),
},
},
}
}
func toProtocolParameterInformation(info []source.ParameterInformation) []protocol.ParameterInformation {
var result []protocol.ParameterInformation
for _, p := range info {
result = append(result, protocol.ParameterInformation{
Label: p.Label,
})
}
return result
}