Skip to content

Commit 61b711c

Browse files
authored
Merge pull request #167 from prometheus-community/signature_id
Correctly set activeParameter for signatureHelp
2 parents a492451 + 96831a2 commit 61b711c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

langserver/signature.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,25 @@ func (s *server) SignatureHelp(ctx context.Context, params *protocol.SignatureHe
3838
return nil, nil
3939
}
4040

41+
activeParameter := 0.
42+
43+
for i, arg := range call.Args {
44+
if arg != nil && arg.PositionRange().End < promql.Pos(location.Pos-location.Query.Pos) {
45+
activeParameter = float64(i) + 1
46+
}
47+
}
48+
49+
// For the label_join function, which has a variable number of arguments,
50+
// the "..." should be highlighted at some point.
51+
// For reference, the signature is:
52+
// label_join(v instant-vector, dst_label string, separator string, src_label_1 string, src_label_2 string, ...)
53+
if call.Func.Name == "label_join" && activeParameter >= 5 {
54+
activeParameter = 5
55+
}
56+
4157
response := &protocol.SignatureHelp{
42-
Signatures: []protocol.SignatureInformation{signature},
58+
Signatures: []protocol.SignatureInformation{signature},
59+
ActiveParameter: activeParameter,
4360
}
4461

4562
return response, nil

0 commit comments

Comments
 (0)