mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 15:05:28 +02:00
feat(hosts): Add signature help; Improvements
This commit is contained in:
parent
634aff5993
commit
4e183d543c
58
server/handlers/hosts/handlers/signature_help.go
Normal file
58
server/handlers/hosts/handlers/signature_help.go
Normal file
@ -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: "<ip address> <hostname> [<alias>...]",
|
||||
ActiveParameter: &index,
|
||||
Parameters: []protocol.ParameterInformation{
|
||||
{
|
||||
Label: []uint32{
|
||||
0,
|
||||
uint32(len("<ip address>")),
|
||||
},
|
||||
Documentation: "The ip address to forward to",
|
||||
},
|
||||
{
|
||||
Label: []uint32{
|
||||
uint32(len("<ip address>")),
|
||||
uint32(len("<ip address> ") + len("<hostname>")),
|
||||
},
|
||||
Documentation: "The hostname to forward to",
|
||||
},
|
||||
{
|
||||
Label: []uint32{
|
||||
uint32(len("<ip address> ") + len("<hostname>")),
|
||||
uint32(len("<ip address> ") + len("<hostname> ") + len("[<alias>...]")),
|
||||
},
|
||||
Documentation: "An optional list of aliases that can also forward",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
31
server/handlers/hosts/lsp/text-document-signature.go
Normal file
31
server/handlers/hosts/lsp/text-document-signature.go
Normal file
@ -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
|
||||
}
|
||||
}
|
@ -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("<option>")),
|
||||
uint32(len("<option>") + len("<value>") + 1),
|
||||
uint32(len("<option> ") + len("<value>")),
|
||||
},
|
||||
Documentation: "The value for the option",
|
||||
},
|
||||
@ -90,7 +91,7 @@ func GetMatchSignatureHelp(
|
||||
{
|
||||
Label: []uint32{
|
||||
uint32(len("Host <criteria> ")),
|
||||
uint32(len("Host <criteria> ") + len("<values>") + 1),
|
||||
uint32(len("Host <criteria> ") + len("<values>")),
|
||||
},
|
||||
Documentation: "Values for the criteria",
|
||||
},
|
||||
@ -132,14 +133,14 @@ func GetHostSignatureHelp(
|
||||
{
|
||||
Label: []uint32{
|
||||
uint32(len("Host ")),
|
||||
uint32(len("Host ") + len("<host1>") + 1),
|
||||
uint32(len("Host ") + len("<host1>")),
|
||||
},
|
||||
Documentation: "A host that should match",
|
||||
},
|
||||
{
|
||||
Label: []uint32{
|
||||
uint32(len("Host <host1> ")),
|
||||
uint32(len("Host <host1> ") + len("[<host2> ...]") + 1),
|
||||
uint32(len("Host <host1> ") + len("[<host2> ...]")),
|
||||
},
|
||||
Documentation: "Additional (optional) hosts that should match",
|
||||
},
|
||||
|
@ -2,6 +2,7 @@ package roothandler
|
||||
|
||||
import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
hosts "config-lsp/handlers/hosts/lsp"
|
||||
sshconfig "config-lsp/handlers/ssh_config/lsp"
|
||||
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
||||
|
||||
@ -24,7 +25,7 @@ func TextDocumentSignatureHelp(context *glsp.Context, params *protocol.Signature
|
||||
|
||||
switch *language {
|
||||
case LanguageHosts:
|
||||
return nil, nil
|
||||
return hosts.TextDocumentSignatureHelp(context, params)
|
||||
case LanguageSSHDConfig:
|
||||
return sshdconfig.TextDocumentSignatureHelp(context, params)
|
||||
case LanguageSSHConfig:
|
||||
|
Loading…
x
Reference in New Issue
Block a user