Skip to content

Commit

Permalink
Improve signature help active params
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanck committed Oct 11, 2022
1 parent b58ec93 commit c53e993
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
24 changes: 1 addition & 23 deletions internal/langserver/handlers/signature_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

ilsp "github.com/hashicorp/terraform-ls/internal/lsp"
"github.com/hashicorp/terraform-ls/internal/protocol"
lsp "github.com/hashicorp/terraform-ls/internal/protocol"
)

Expand Down Expand Up @@ -34,27 +33,6 @@ func (svc *service) SignatureHelp(ctx context.Context, params lsp.SignatureHelpP
if err != nil {
return nil, err
}
if sig == nil {
return nil, nil
}

parameters := make([]protocol.ParameterInformation, 0)
for _, p := range sig.Parameters {
parameters = append(parameters, lsp.ParameterInformation{
Label: p.Name,
Documentation: p.Description.Value,
})
}
return &lsp.SignatureHelp{
Signatures: []lsp.SignatureInformation{
{
Label: sig.Name,
Documentation: sig.Description.Value,
Parameters: parameters,
ActiveParameter: 1,
},
},
ActiveSignature: 0,
ActiveParameter: 0,
}, nil
return ilsp.ToSignatureHelp(sig), nil
}
32 changes: 32 additions & 0 deletions internal/lsp/signature.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package lsp

import (
"github.com/hashicorp/hcl-lang/lang"
lsp "github.com/hashicorp/terraform-ls/internal/protocol"
)

func ToSignatureHelp(signature *lang.FuncSignature) *lsp.SignatureHelp {
if signature == nil {
return nil
}

parameters := make([]lsp.ParameterInformation, 0)
for _, p := range signature.Parameters {
parameters = append(parameters, lsp.ParameterInformation{
Label: p.Name,
Documentation: p.Description.Value, // TODO? clean
})
}

return &lsp.SignatureHelp{
Signatures: []lsp.SignatureInformation{
{
Label: signature.Name,
Documentation: signature.Description.Value, // TODO? clean
Parameters: parameters,
ActiveParameter: signature.ActiveParameter,
},
},
ActiveSignature: 0,
}
}

0 comments on commit c53e993

Please sign in to comment.