diff --git a/server/handlers/hosts/handlers/signature_help.go b/server/handlers/hosts/handlers/signature_help.go new file mode 100644 index 0000000..1a77dec --- /dev/null +++ b/server/handlers/hosts/handlers/signature_help.go @@ -0,0 +1,58 @@ +package handlers + +import ( + "config-lsp/common" + "config-lsp/handlers/hosts/ast" + + protocol "github.com/tliron/glsp/protocol_3_16" +) + +func GetEntrySignatureHelp( + entry *ast.HostsEntry, + cursor common.CursorPosition, +) *protocol.SignatureHelp { + var index uint32 + + if entry == nil || entry.IPAddress == nil || entry.IPAddress.Location.ContainsPosition(cursor) { + index = 0 + } else if entry.Hostname == nil || entry.Hostname.Location.ContainsPosition(cursor) { + index = 1 + } else { + index = 2 + } + + signature := uint32(0) + + return &protocol.SignatureHelp{ + ActiveSignature: &signature, + Signatures: []protocol.SignatureInformation{ + { + Label: " [...]", + ActiveParameter: &index, + Parameters: []protocol.ParameterInformation{ + { + Label: []uint32{ + 0, + uint32(len("")), + }, + Documentation: "The ip address to forward to", + }, + { + Label: []uint32{ + uint32(len("")), + uint32(len(" ") + len("")), + }, + Documentation: "The hostname to forward to", + }, + { + Label: []uint32{ + uint32(len(" ") + len("")), + uint32(len(" ") + len(" ") + len("[...]")), + }, + Documentation: "An optional list of aliases that can also forward", + }, + }, + }, + }, + } +} diff --git a/server/handlers/hosts/lsp/text-document-signature.go b/server/handlers/hosts/lsp/text-document-signature.go new file mode 100644 index 0000000..e79efb3 --- /dev/null +++ b/server/handlers/hosts/lsp/text-document-signature.go @@ -0,0 +1,31 @@ +package lsp + +import ( + "config-lsp/common" + "config-lsp/handlers/hosts" + "config-lsp/handlers/hosts/ast" + "config-lsp/handlers/hosts/handlers" + + "github.com/tliron/glsp" + protocol "github.com/tliron/glsp/protocol_3_16" +) + +func TextDocumentSignatureHelp(context *glsp.Context, params *protocol.SignatureHelpParams) (*protocol.SignatureHelp, error) { + document := hosts.DocumentParserMap[params.TextDocument.URI] + + line := uint32(params.Position.Line) + cursor := common.LSPCharacterAsCursorPosition(params.Position.Character) + + if _, found := document.Parser.CommentLines[line]; found { + // Comment + return nil, nil + } + + entry, found := document.Parser.Tree.Entries.Get(line) + + if !found { + return handlers.GetEntrySignatureHelp(nil, cursor), nil + } else { + return handlers.GetEntrySignatureHelp(entry.(*ast.HostsEntry), cursor), nil + } +} diff --git a/server/handlers/ssh_config/handlers/signature_help.go b/server/handlers/ssh_config/handlers/signature_help.go index 5bdacbb..f93ca93 100644 --- a/server/handlers/ssh_config/handlers/signature_help.go +++ b/server/handlers/ssh_config/handlers/signature_help.go @@ -20,6 +20,7 @@ func GetOptionSignatureHelp( } signature := uint32(0) + return &protocol.SignatureHelp{ ActiveSignature: &signature, Signatures: []protocol.SignatureInformation{ @@ -37,7 +38,7 @@ func GetOptionSignatureHelp( { Label: []uint32{ uint32(len("