Skip to content

Commit

Permalink
feat(sshd_config): Add lsp handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Sep 10, 2024
1 parent c897523 commit 7ec2483
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 4 deletions.
12 changes: 12 additions & 0 deletions handlers/sshd_config/analyzer/analyzer.go
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions handlers/sshd_config/lsp/text-document-code-action.go
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions handlers/sshd_config/lsp/text-document-completion.go
Original file line number Diff line number Diff line change
@@ -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 changes: 42 additions & 0 deletions handlers/sshd_config/lsp/text-document-did-change.go
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions handlers/sshd_config/lsp/text-document-did-close.go
Original file line number Diff line number Diff line change
@@ -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 changes: 45 additions & 0 deletions handlers/sshd_config/lsp/text-document-did-open.go
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions handlers/sshd_config/lsp/text-document-hover.go
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions handlers/sshd_config/lsp/text-document-signature-help.go
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions handlers/sshd_config/lsp/workspace-execute-command.go
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions handlers/sshd_config/shared.go
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 1 deletion root-handler/text-document-code-action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion root-handler/text-document-completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion root-handler/text-document-hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion root-handler/text-document-signature-help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions root-handler/workspace-execute-command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package roothandler
import (
hosts "config-lsp/handlers/hosts/lsp"
wireguard "config-lsp/handlers/wireguard/lsp"

"strings"

"github.com/tliron/glsp"
Expand Down

0 comments on commit 7ec2483

Please sign in to comment.