mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
feat(fstab): Add signature help support
This commit is contained in:
parent
4e183d543c
commit
aa5f9a6630
85
server/handlers/fstab/handlers/signature_help.go
Normal file
85
server/handlers/fstab/handlers/signature_help.go
Normal file
@ -0,0 +1,85 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"config-lsp/common"
|
||||
"config-lsp/handlers/fstab/ast"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func GetEntrySignatureHelp(
|
||||
entry *ast.FstabEntry,
|
||||
cursor common.CursorPosition,
|
||||
) *protocol.SignatureHelp {
|
||||
var index uint32
|
||||
|
||||
if entry == nil || entry.Fields.Spec == nil || entry.Fields.Spec.ContainsPosition(cursor) {
|
||||
index = 0
|
||||
} else if entry.Fields.MountPoint == nil && entry.Fields.MountPoint.ContainsPosition(cursor) {
|
||||
index = 1
|
||||
} else if entry.Fields.FilesystemType == nil && entry.Fields.FilesystemType.ContainsPosition(cursor) {
|
||||
index = 2
|
||||
} else if entry.Fields.Options == nil || entry.Fields.Options.ContainsPosition(cursor) {
|
||||
index = 3
|
||||
} else if entry.Fields.Freq == nil || entry.Fields.Freq.ContainsPosition(cursor) {
|
||||
index = 4
|
||||
} else {
|
||||
index = 5
|
||||
}
|
||||
|
||||
signature := uint32(0)
|
||||
|
||||
return &protocol.SignatureHelp{
|
||||
ActiveSignature: &signature,
|
||||
Signatures: []protocol.SignatureInformation{
|
||||
{
|
||||
Label: "<spec> <mount point> <file system type> <options> <freq> <pass>",
|
||||
ActiveParameter: &index,
|
||||
Parameters: []protocol.ParameterInformation{
|
||||
{
|
||||
Label: []uint32{
|
||||
0,
|
||||
uint32(len("<spec>")),
|
||||
},
|
||||
Documentation: "The device or remote filesystem to mount",
|
||||
},
|
||||
{
|
||||
Label: []uint32{
|
||||
uint32(len("<spec>")),
|
||||
uint32(len("<spec> ") + len("<mount point>")),
|
||||
},
|
||||
Documentation: "The directory to mount the device or remote filesystem",
|
||||
},
|
||||
{
|
||||
Label: []uint32{
|
||||
uint32(len("<spec> <mount point>")),
|
||||
uint32(len("<spec> <mount point> ") + len("<file system type>")),
|
||||
},
|
||||
Documentation: "The type of filesystem",
|
||||
},
|
||||
{
|
||||
Label: []uint32{
|
||||
uint32(len("<spec> <mount point> <file system type>")),
|
||||
uint32(len("<spec> <mount point> <file system type> ") + len("<options>")),
|
||||
},
|
||||
Documentation: "Mount options",
|
||||
},
|
||||
{
|
||||
Label: []uint32{
|
||||
uint32(len("<spec> <mount point> <file system type> <options>")),
|
||||
uint32(len("<spec> <mount point> <file system type> <options> ") + len("<freq>")),
|
||||
},
|
||||
Documentation: "Used by dump(8) to determine which filesystems need to be dumped",
|
||||
},
|
||||
{
|
||||
Label: []uint32{
|
||||
uint32(len("<spec> <mount point> <file system type> <options> <freq>")),
|
||||
uint32(len("<spec> <mount point> <file system type> <options> <freq> ") + len("<pass>")),
|
||||
},
|
||||
Documentation: "Used by fsck(8) to determine the order in which filesystem checks are done at boot time",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
31
server/handlers/fstab/lsp/text-document-signature-help.go
Normal file
31
server/handlers/fstab/lsp/text-document-signature-help.go
Normal file
@ -0,0 +1,31 @@
|
||||
package lsp
|
||||
|
||||
import (
|
||||
"config-lsp/common"
|
||||
"config-lsp/handlers/fstab/ast"
|
||||
"config-lsp/handlers/fstab/handlers"
|
||||
fstab "config-lsp/handlers/fstab/shared"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentSignatureHelp(context *glsp.Context, params *protocol.SignatureHelpParams) (*protocol.SignatureHelp, error) {
|
||||
document := fstab.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
|
||||
}
|
||||
|
||||
entry, found := document.Config.Entries.Get(line)
|
||||
|
||||
if !found {
|
||||
return handlers.GetEntrySignatureHelp(nil, cursor), nil
|
||||
} else {
|
||||
return handlers.GetEntrySignatureHelp(entry.(*ast.FstabEntry), cursor), nil
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package roothandler
|
||||
|
||||
import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
fstab "config-lsp/handlers/fstab/lsp"
|
||||
hosts "config-lsp/handlers/hosts/lsp"
|
||||
sshconfig "config-lsp/handlers/ssh_config/lsp"
|
||||
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
||||
@ -31,7 +32,7 @@ func TextDocumentSignatureHelp(context *glsp.Context, params *protocol.Signature
|
||||
case LanguageSSHConfig:
|
||||
return sshconfig.TextDocumentSignatureHelp(context, params)
|
||||
case LanguageFstab:
|
||||
return nil, nil
|
||||
return fstab.TextDocumentSignatureHelp(context, params)
|
||||
case LanguageWireguard:
|
||||
return nil, nil
|
||||
case LanguageAliases:
|
||||
|
Loading…
x
Reference in New Issue
Block a user