mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
feat(ssh_config): Add support for signature help
This commit is contained in:
parent
d870beb396
commit
1fc847d523
150
server/handlers/ssh_config/handlers/signature_help.go
Normal file
150
server/handlers/ssh_config/handlers/signature_help.go
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"config-lsp/common"
|
||||||
|
"config-lsp/handlers/ssh_config/ast"
|
||||||
|
|
||||||
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetOptionSignatureHelp(
|
||||||
|
option *ast.SSHOption,
|
||||||
|
cursor common.CursorPosition,
|
||||||
|
) *protocol.SignatureHelp {
|
||||||
|
var index uint32
|
||||||
|
|
||||||
|
if option == nil || option.Key == nil || (option.OptionValue == nil || option.Key.ContainsPosition(cursor)) {
|
||||||
|
index = 0
|
||||||
|
} else {
|
||||||
|
index = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
signature := uint32(0)
|
||||||
|
return &protocol.SignatureHelp{
|
||||||
|
ActiveSignature: &signature,
|
||||||
|
Signatures: []protocol.SignatureInformation{
|
||||||
|
{
|
||||||
|
Label: "<option> <value>",
|
||||||
|
ActiveParameter: &index,
|
||||||
|
Parameters: []protocol.ParameterInformation{
|
||||||
|
{
|
||||||
|
Label: []uint32{
|
||||||
|
0,
|
||||||
|
uint32(len("<option>") + 1),
|
||||||
|
},
|
||||||
|
Documentation: "The option name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Label: []uint32{
|
||||||
|
uint32(len("<option>")),
|
||||||
|
uint32(len("<option>") + len("<value>") + 1),
|
||||||
|
},
|
||||||
|
Documentation: "The value for the option",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMatchSignatureHelp(
|
||||||
|
match *ast.SSHMatchBlock,
|
||||||
|
cursor common.CursorPosition,
|
||||||
|
) *protocol.SignatureHelp {
|
||||||
|
var index uint32
|
||||||
|
|
||||||
|
if match.MatchOption.Key.ContainsPosition(cursor) {
|
||||||
|
index = 0
|
||||||
|
} else {
|
||||||
|
entry := match.MatchValue.GetEntryAtPosition(cursor)
|
||||||
|
|
||||||
|
if entry == nil || entry.Criteria.ContainsPosition(cursor) {
|
||||||
|
index = 1
|
||||||
|
} else {
|
||||||
|
index = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
signature := uint32(0)
|
||||||
|
return &protocol.SignatureHelp{
|
||||||
|
ActiveSignature: &signature,
|
||||||
|
Signatures: []protocol.SignatureInformation{
|
||||||
|
{
|
||||||
|
Label: "Match <criteria> <values>",
|
||||||
|
ActiveParameter: &index,
|
||||||
|
Parameters: []protocol.ParameterInformation{
|
||||||
|
{
|
||||||
|
Label: []uint32{
|
||||||
|
0,
|
||||||
|
uint32(len("Match") + 1),
|
||||||
|
},
|
||||||
|
Documentation: "The \"Match\" keyword",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Label: []uint32{
|
||||||
|
uint32(len("Match ")),
|
||||||
|
uint32(len("Match ") + len("<criteria>")),
|
||||||
|
},
|
||||||
|
Documentation: "The criteria name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Label: []uint32{
|
||||||
|
uint32(len("Host <criteria> ")),
|
||||||
|
uint32(len("Host <criteria> ") + len("<values>") + 1),
|
||||||
|
},
|
||||||
|
Documentation: "Values for the criteria",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetHostSignatureHelp(
|
||||||
|
host *ast.SSHHostBlock,
|
||||||
|
cursor common.CursorPosition,
|
||||||
|
) *protocol.SignatureHelp {
|
||||||
|
var index uint32
|
||||||
|
|
||||||
|
if host.HostOption.Key.ContainsPosition(cursor) {
|
||||||
|
index = 0
|
||||||
|
} else if len(host.HostValue.Hosts) >= 1 && host.HostValue.Hosts[0].ContainsPosition(cursor) {
|
||||||
|
index = 1
|
||||||
|
} else {
|
||||||
|
index = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
signature := uint32(0)
|
||||||
|
return &protocol.SignatureHelp{
|
||||||
|
ActiveSignature: &signature,
|
||||||
|
Signatures: []protocol.SignatureInformation{
|
||||||
|
{
|
||||||
|
Label: "Host <host1> [<host2> ...]",
|
||||||
|
ActiveParameter: &index,
|
||||||
|
Parameters: []protocol.ParameterInformation{
|
||||||
|
{
|
||||||
|
Label: []uint32{
|
||||||
|
0,
|
||||||
|
uint32(len("Host") + 1),
|
||||||
|
},
|
||||||
|
Documentation: "The \"Host\" keyword",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Label: []uint32{
|
||||||
|
uint32(len("Host ")),
|
||||||
|
uint32(len("Host ") + len("<host1>") + 1),
|
||||||
|
},
|
||||||
|
Documentation: "A host that should match",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Label: []uint32{
|
||||||
|
uint32(len("Host <host1> ")),
|
||||||
|
uint32(len("Host <host1> ") + len("[<host2> ...]") + 1),
|
||||||
|
},
|
||||||
|
Documentation: "Additional (optional) hosts that should match",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,49 @@
|
|||||||
package lsp
|
package lsp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"config-lsp/common"
|
||||||
|
sshconfig "config-lsp/handlers/ssh_config"
|
||||||
|
"config-lsp/handlers/ssh_config/ast"
|
||||||
|
"config-lsp/handlers/ssh_config/fields"
|
||||||
|
"config-lsp/handlers/ssh_config/handlers"
|
||||||
|
|
||||||
"github.com/tliron/glsp"
|
"github.com/tliron/glsp"
|
||||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var hostOption = fields.CreateNormalizedName("Host")
|
||||||
|
|
||||||
func TextDocumentSignatureHelp(context *glsp.Context, params *protocol.SignatureHelpParams) (*protocol.SignatureHelp, error) {
|
func TextDocumentSignatureHelp(context *glsp.Context, params *protocol.SignatureHelpParams) (*protocol.SignatureHelp, error) {
|
||||||
return nil, nil
|
document := sshconfig.DocumentParserMap[params.TextDocument.URI]
|
||||||
|
|
||||||
|
line := uint32(params.Position.Line)
|
||||||
|
cursor := common.LSPCharacterAsCursorPosition(params.Position.Character)
|
||||||
|
|
||||||
|
if _, found := document.Config.CommentLines[line]; found {
|
||||||
|
// Comment
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
option, block := document.Config.FindOption(line)
|
||||||
|
|
||||||
|
if option != nil {
|
||||||
|
if option.Key != nil {
|
||||||
|
switch option.Key.Key {
|
||||||
|
case matchOption:
|
||||||
|
return handlers.GetMatchSignatureHelp(
|
||||||
|
block.(*ast.SSHMatchBlock),
|
||||||
|
cursor,
|
||||||
|
), nil
|
||||||
|
case hostOption:
|
||||||
|
return handlers.GetHostSignatureHelp(
|
||||||
|
block.(*ast.SSHHostBlock),
|
||||||
|
cursor,
|
||||||
|
), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return handlers.GetOptionSignatureHelp(option, cursor), nil
|
||||||
|
} else {
|
||||||
|
return handlers.GetOptionSignatureHelp(option, cursor), nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package roothandler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
aliases "config-lsp/handlers/aliases/lsp"
|
aliases "config-lsp/handlers/aliases/lsp"
|
||||||
|
sshconfig "config-lsp/handlers/ssh_config/lsp"
|
||||||
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
||||||
|
|
||||||
"github.com/tliron/glsp"
|
"github.com/tliron/glsp"
|
||||||
@ -27,7 +28,7 @@ func TextDocumentSignatureHelp(context *glsp.Context, params *protocol.Signature
|
|||||||
case LanguageSSHDConfig:
|
case LanguageSSHDConfig:
|
||||||
return sshdconfig.TextDocumentSignatureHelp(context, params)
|
return sshdconfig.TextDocumentSignatureHelp(context, params)
|
||||||
case LanguageSSHConfig:
|
case LanguageSSHConfig:
|
||||||
return nil, nil
|
return sshconfig.TextDocumentSignatureHelp(context, params)
|
||||||
case LanguageFstab:
|
case LanguageFstab:
|
||||||
return nil, nil
|
return nil, nil
|
||||||
case LanguageWireguard:
|
case LanguageWireguard:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user