mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
feat(sshd_config): Add lsp handler
This commit is contained in:
parent
c897523321
commit
7ec24834f3
12
handlers/sshd_config/analyzer/analyzer.go
Normal file
12
handlers/sshd_config/analyzer/analyzer.go
Normal file
@ -0,0 +1,12 @@
|
||||
package analyzer
|
||||
|
||||
import (
|
||||
"config-lsp/handlers/sshd_config"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func Analyze(
|
||||
d *sshdconfig.SSHDocument,
|
||||
) []protocol.Diagnostic {
|
||||
return nil
|
||||
}
|
14
handlers/sshd_config/lsp/text-document-code-action.go
Normal file
14
handlers/sshd_config/lsp/text-document-code-action.go
Normal file
@ -0,0 +1,14 @@
|
||||
package lsp
|
||||
|
||||
import (
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentCodeAction(context *glsp.Context, params *protocol.CodeActionParams) ([]protocol.CodeAction, error) {
|
||||
// document := hosts.DocumentParserMap[params.TextDocument.URI]
|
||||
//
|
||||
// actions := make([]protocol.CodeAction, 0, 1)
|
||||
|
||||
return nil, nil
|
||||
}
|
10
handlers/sshd_config/lsp/text-document-completion.go
Normal file
10
handlers/sshd_config/lsp/text-document-completion.go
Normal file
@ -0,0 +1,10 @@
|
||||
package lsp
|
||||
|
||||
import (
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (any, error) {
|
||||
return nil, nil
|
||||
}
|
42
handlers/sshd_config/lsp/text-document-did-change.go
Normal file
42
handlers/sshd_config/lsp/text-document-did-change.go
Normal file
@ -0,0 +1,42 @@
|
||||
package lsp
|
||||
|
||||
import (
|
||||
"config-lsp/common"
|
||||
"config-lsp/handlers/sshd_config/analyzer"
|
||||
"config-lsp/handlers/sshd_config"
|
||||
"config-lsp/utils"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentDidChange(
|
||||
context *glsp.Context,
|
||||
params *protocol.DidChangeTextDocumentParams,
|
||||
) error {
|
||||
content := params.ContentChanges[0].(protocol.TextDocumentContentChangeEventWhole).Text
|
||||
common.ClearDiagnostics(context, params.TextDocument.URI)
|
||||
|
||||
document := sshdconfig.DocumentParserMap[params.TextDocument.URI]
|
||||
document.Config.Clear()
|
||||
|
||||
diagnostics := make([]protocol.Diagnostic, 0)
|
||||
errors := document.Config.Parse(content)
|
||||
|
||||
if len(errors) > 0 {
|
||||
diagnostics = append(diagnostics, utils.Map(
|
||||
errors,
|
||||
func(err common.LSPError) protocol.Diagnostic {
|
||||
return err.ToDiagnostic()
|
||||
},
|
||||
)...)
|
||||
}
|
||||
|
||||
diagnostics = append(diagnostics, analyzer.Analyze(document)...)
|
||||
|
||||
if len(diagnostics) > 0 {
|
||||
common.SendDiagnostics(context, params.TextDocument.URI, diagnostics)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
13
handlers/sshd_config/lsp/text-document-did-close.go
Normal file
13
handlers/sshd_config/lsp/text-document-did-close.go
Normal file
@ -0,0 +1,13 @@
|
||||
package lsp
|
||||
|
||||
import (
|
||||
"config-lsp/handlers/sshd_config"
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentDidClose(context *glsp.Context, params *protocol.DidCloseTextDocumentParams) error {
|
||||
delete(sshdconfig.DocumentParserMap, params.TextDocument.URI)
|
||||
|
||||
return nil
|
||||
}
|
45
handlers/sshd_config/lsp/text-document-did-open.go
Normal file
45
handlers/sshd_config/lsp/text-document-did-open.go
Normal file
@ -0,0 +1,45 @@
|
||||
package lsp
|
||||
|
||||
import (
|
||||
"config-lsp/common"
|
||||
"config-lsp/handlers/sshd_config"
|
||||
"config-lsp/handlers/sshd_config/analyzer"
|
||||
"config-lsp/handlers/sshd_config/ast"
|
||||
"config-lsp/utils"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentDidOpen(
|
||||
context *glsp.Context,
|
||||
params *protocol.DidOpenTextDocumentParams,
|
||||
) error {
|
||||
common.ClearDiagnostics(context, params.TextDocument.URI)
|
||||
|
||||
parser := ast.NewSSHConfig()
|
||||
document := sshdconfig.SSHDocument{
|
||||
Config: parser,
|
||||
}
|
||||
sshdconfig.DocumentParserMap[params.TextDocument.URI] = &document
|
||||
|
||||
errors := parser.Parse(params.TextDocument.Text)
|
||||
|
||||
diagnostics := utils.Map(
|
||||
errors,
|
||||
func(err common.LSPError) protocol.Diagnostic {
|
||||
return err.ToDiagnostic()
|
||||
},
|
||||
)
|
||||
|
||||
diagnostics = append(
|
||||
diagnostics,
|
||||
analyzer.Analyze(&document)...,
|
||||
)
|
||||
|
||||
if len(diagnostics) > 0 {
|
||||
common.SendDiagnostics(context, params.TextDocument.URI, diagnostics)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
13
handlers/sshd_config/lsp/text-document-hover.go
Normal file
13
handlers/sshd_config/lsp/text-document-hover.go
Normal file
@ -0,0 +1,13 @@
|
||||
package lsp
|
||||
|
||||
import (
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentHover(
|
||||
context *glsp.Context,
|
||||
params *protocol.HoverParams,
|
||||
) (*protocol.Hover, error) {
|
||||
return nil, nil
|
||||
}
|
10
handlers/sshd_config/lsp/text-document-signature-help.go
Normal file
10
handlers/sshd_config/lsp/text-document-signature-help.go
Normal file
@ -0,0 +1,10 @@
|
||||
package lsp
|
||||
|
||||
import (
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentSignatureHelp(context *glsp.Context, params *protocol.SignatureHelpParams) (*protocol.SignatureHelp, error) {
|
||||
return nil, nil
|
||||
}
|
10
handlers/sshd_config/lsp/workspace-execute-command.go
Normal file
10
handlers/sshd_config/lsp/workspace-execute-command.go
Normal file
@ -0,0 +1,10 @@
|
||||
package lsp
|
||||
|
||||
import (
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func WorkspaceExecuteCommand(context *glsp.Context, params *protocol.ExecuteCommandParams) (*protocol.ApplyWorkspaceEditParams, error) {
|
||||
return nil, nil
|
||||
}
|
14
handlers/sshd_config/shared.go
Normal file
14
handlers/sshd_config/shared.go
Normal file
@ -0,0 +1,14 @@
|
||||
package sshdconfig
|
||||
|
||||
import (
|
||||
"config-lsp/handlers/sshd_config/ast"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
type SSHDocument struct {
|
||||
Config *ast.SSHConfig
|
||||
}
|
||||
|
||||
var DocumentParserMap = map[protocol.DocumentUri]*SSHDocument{}
|
||||
|
@ -3,6 +3,7 @@ package roothandler
|
||||
import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
hosts "config-lsp/handlers/hosts/lsp"
|
||||
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
||||
wireguard "config-lsp/handlers/wireguard/lsp"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
@ -28,7 +29,7 @@ func TextDocumentCodeAction(context *glsp.Context, params *protocol.CodeActionPa
|
||||
case LanguageHosts:
|
||||
return hosts.TextDocumentCodeAction(context, params)
|
||||
case LanguageSSHDConfig:
|
||||
return nil, nil
|
||||
return sshdconfig.TextDocumentCodeAction(context, params)
|
||||
case LanguageWireguard:
|
||||
return wireguard.TextDocumentCodeAction(context, params)
|
||||
case LanguageAliases:
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
fstab "config-lsp/handlers/fstab/lsp"
|
||||
hosts "config-lsp/handlers/hosts/lsp"
|
||||
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
||||
wireguard "config-lsp/handlers/wireguard/lsp"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
@ -27,7 +28,7 @@ func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionPa
|
||||
case LanguageFstab:
|
||||
return fstab.TextDocumentCompletion(context, params)
|
||||
case LanguageSSHDConfig:
|
||||
return nil, nil
|
||||
return sshdconfig.TextDocumentCompletion(context, params)
|
||||
case LanguageWireguard:
|
||||
return wireguard.TextDocumentCompletion(context, params)
|
||||
case LanguageHosts:
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
fstab "config-lsp/handlers/fstab/lsp"
|
||||
hosts "config-lsp/handlers/hosts/lsp"
|
||||
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
||||
wireguard "config-lsp/handlers/wireguard/lsp"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
@ -27,7 +28,7 @@ func TextDocumentHover(context *glsp.Context, params *protocol.HoverParams) (*pr
|
||||
case LanguageHosts:
|
||||
return hosts.TextDocumentHover(context, params)
|
||||
case LanguageSSHDConfig:
|
||||
return nil, nil
|
||||
return sshdconfig.TextDocumentHover(context, params)
|
||||
case LanguageFstab:
|
||||
return fstab.TextDocumentHover(context, params)
|
||||
case LanguageWireguard:
|
||||
|
@ -2,6 +2,7 @@ package roothandler
|
||||
|
||||
import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
@ -24,7 +25,7 @@ func TextDocumentSignatureHelp(context *glsp.Context, params *protocol.Signature
|
||||
case LanguageHosts:
|
||||
return nil, nil
|
||||
case LanguageSSHDConfig:
|
||||
return nil, nil
|
||||
return sshdconfig.TextDocumentSignatureHelp(context, params)
|
||||
case LanguageFstab:
|
||||
return nil, nil
|
||||
case LanguageWireguard:
|
||||
|
@ -3,6 +3,7 @@ package roothandler
|
||||
import (
|
||||
hosts "config-lsp/handlers/hosts/lsp"
|
||||
wireguard "config-lsp/handlers/wireguard/lsp"
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
|
Loading…
x
Reference in New Issue
Block a user