mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 15:05:28 +02:00
refactor(server): Improve root handler structure
This commit is contained in:
parent
87c68de419
commit
57ce6c1f4f
@ -1,6 +1,8 @@
|
||||
package roothandler
|
||||
|
||||
import (
|
||||
"config-lsp/root-handler/lsp"
|
||||
"config-lsp/root-handler/shared"
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
|
||||
@ -17,24 +19,25 @@ var lspHandler protocol.Handler
|
||||
|
||||
// The root handler which handles all the LSP requests and then forwards them to the appropriate handler
|
||||
func SetUpRootHandler() {
|
||||
rootHandler = NewRootHandler()
|
||||
shared.Handler = shared.NewRootHandler()
|
||||
|
||||
lspHandler = protocol.Handler{
|
||||
Initialize: initialize,
|
||||
Initialized: initialized,
|
||||
Shutdown: shutdown,
|
||||
SetTrace: setTrace,
|
||||
TextDocumentDidOpen: TextDocumentDidOpen,
|
||||
TextDocumentDidChange: TextDocumentDidChange,
|
||||
TextDocumentCompletion: TextDocumentCompletion,
|
||||
TextDocumentHover: TextDocumentHover,
|
||||
TextDocumentDidClose: TextDocumentDidClose,
|
||||
TextDocumentCodeAction: TextDocumentCodeAction,
|
||||
TextDocumentDefinition: TextDocumentDefinition,
|
||||
WorkspaceExecuteCommand: WorkspaceExecuteCommand,
|
||||
TextDocumentRename: TextDocumentRename,
|
||||
TextDocumentPrepareRename: TextDocumentPrepareRename,
|
||||
TextDocumentSignatureHelp: TextDocumentSignatureHelp,
|
||||
TextDocumentRangeFormatting: TextDocumentRangeFormattingFunc,
|
||||
TextDocumentDidOpen: lsp.TextDocumentDidOpen,
|
||||
TextDocumentDidChange: lsp.TextDocumentDidChange,
|
||||
TextDocumentCompletion: lsp.TextDocumentCompletion,
|
||||
TextDocumentHover: lsp.TextDocumentHover,
|
||||
TextDocumentDidClose: lsp.TextDocumentDidClose,
|
||||
TextDocumentCodeAction: lsp.TextDocumentCodeAction,
|
||||
TextDocumentDefinition: lsp.TextDocumentDefinition,
|
||||
WorkspaceExecuteCommand: lsp.WorkspaceExecuteCommand,
|
||||
TextDocumentRename: lsp.TextDocumentRename,
|
||||
TextDocumentPrepareRename: lsp.TextDocumentPrepareRename,
|
||||
TextDocumentSignatureHelp: lsp.TextDocumentSignatureHelp,
|
||||
TextDocumentRangeFormatting: lsp.TextDocumentRangeFormattingFunc,
|
||||
}
|
||||
|
||||
server := server.NewServer(&lspHandler, lsName, false)
|
||||
|
@ -1,40 +1,36 @@
|
||||
package roothandler
|
||||
package lsp
|
||||
|
||||
import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
hosts "config-lsp/handlers/hosts/lsp"
|
||||
sshconfig "config-lsp/handlers/ssh_config/lsp"
|
||||
wireguard "config-lsp/handlers/wireguard/lsp"
|
||||
"config-lsp/root-handler/shared"
|
||||
utils "config-lsp/root-handler/utils"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentCodeAction(context *glsp.Context, params *protocol.CodeActionParams) (any, error) {
|
||||
language := rootHandler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
|
||||
if language == nil {
|
||||
showParseError(
|
||||
context,
|
||||
params.TextDocument.URI,
|
||||
undetectableError,
|
||||
)
|
||||
|
||||
return fetchAddLanguageActions(params.TextDocument.URI)
|
||||
return utils.FetchAddLanguageActions(params.TextDocument.URI)
|
||||
}
|
||||
|
||||
switch *language {
|
||||
case LanguageFstab:
|
||||
case utils.LanguageFstab:
|
||||
return nil, nil
|
||||
case LanguageHosts:
|
||||
case utils.LanguageHosts:
|
||||
return hosts.TextDocumentCodeAction(context, params)
|
||||
case LanguageSSHDConfig:
|
||||
case utils.LanguageSSHDConfig:
|
||||
return nil, nil
|
||||
case LanguageSSHConfig:
|
||||
case utils.LanguageSSHConfig:
|
||||
return sshconfig.TextDocumentCodeAction(context, params)
|
||||
case LanguageWireguard:
|
||||
case utils.LanguageWireguard:
|
||||
return wireguard.TextDocumentCodeAction(context, params)
|
||||
case LanguageAliases:
|
||||
case utils.LanguageAliases:
|
||||
return aliases.TextDocumentCodeAction(context, params)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package roothandler
|
||||
package lsp
|
||||
|
||||
import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
@ -7,36 +7,32 @@ import (
|
||||
sshconfig "config-lsp/handlers/ssh_config/lsp"
|
||||
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
||||
wireguard "config-lsp/handlers/wireguard/lsp"
|
||||
"config-lsp/root-handler/shared"
|
||||
"config-lsp/root-handler/utils"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (any, error) {
|
||||
language := rootHandler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
|
||||
if language == nil {
|
||||
showParseError(
|
||||
context,
|
||||
params.TextDocument.URI,
|
||||
undetectableError,
|
||||
)
|
||||
|
||||
return nil, undetectableError.Err
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
switch *language {
|
||||
case LanguageFstab:
|
||||
case utils.LanguageFstab:
|
||||
return fstab.TextDocumentCompletion(context, params)
|
||||
case LanguageSSHDConfig:
|
||||
case utils.LanguageSSHDConfig:
|
||||
return sshdconfig.TextDocumentCompletion(context, params)
|
||||
case LanguageSSHConfig:
|
||||
case utils.LanguageSSHConfig:
|
||||
return sshconfig.TextDocumentCompletion(context, params)
|
||||
case LanguageWireguard:
|
||||
case utils.LanguageWireguard:
|
||||
return wireguard.TextDocumentCompletion(context, params)
|
||||
case LanguageHosts:
|
||||
case utils.LanguageHosts:
|
||||
return hosts.TextDocumentCompletion(context, params)
|
||||
case LanguageAliases:
|
||||
case utils.LanguageAliases:
|
||||
return aliases.TextDocumentCompletion(context, params)
|
||||
}
|
||||
|
@ -1,39 +1,35 @@
|
||||
package roothandler
|
||||
package lsp
|
||||
|
||||
import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
sshconfig "config-lsp/handlers/ssh_config/lsp"
|
||||
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
||||
"config-lsp/root-handler/shared"
|
||||
"config-lsp/root-handler/utils"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentDefinition(context *glsp.Context, params *protocol.DefinitionParams) (any, error) {
|
||||
language := rootHandler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
|
||||
if language == nil {
|
||||
showParseError(
|
||||
context,
|
||||
params.TextDocument.URI,
|
||||
undetectableError,
|
||||
)
|
||||
|
||||
return nil, undetectableError.Err
|
||||
return nil, utils.LanguageUndetectableError{}
|
||||
}
|
||||
|
||||
switch *language {
|
||||
case LanguageHosts:
|
||||
case utils.LanguageHosts:
|
||||
return nil, nil
|
||||
case LanguageSSHDConfig:
|
||||
case utils.LanguageSSHDConfig:
|
||||
return sshdconfig.TextDocumentDefinition(context, params)
|
||||
case LanguageSSHConfig:
|
||||
case utils.LanguageSSHConfig:
|
||||
return sshconfig.TextDocumentDefinition(context, params)
|
||||
case LanguageFstab:
|
||||
case utils.LanguageFstab:
|
||||
return nil, nil
|
||||
case LanguageWireguard:
|
||||
case utils.LanguageWireguard:
|
||||
return nil, nil
|
||||
case LanguageAliases:
|
||||
case utils.LanguageAliases:
|
||||
return aliases.TextDocumentDefinition(context, params)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package roothandler
|
||||
package lsp
|
||||
|
||||
import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
@ -7,13 +7,15 @@ import (
|
||||
sshconfig "config-lsp/handlers/ssh_config/lsp"
|
||||
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
||||
wireguard "config-lsp/handlers/wireguard/lsp"
|
||||
"config-lsp/root-handler/shared"
|
||||
"config-lsp/root-handler/utils"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentDidChange(context *glsp.Context, params *protocol.DidChangeTextDocumentParams) error {
|
||||
language := rootHandler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
|
||||
if language == nil {
|
||||
content := params.ContentChanges[0].(protocol.TextDocumentContentChangeEventWhole).Text
|
||||
@ -40,33 +42,33 @@ func TextDocumentDidChange(context *glsp.Context, params *protocol.DidChangeText
|
||||
}
|
||||
|
||||
switch *language {
|
||||
case LanguageFstab:
|
||||
case utils.LanguageFstab:
|
||||
return fstab.TextDocumentDidOpen(context, params)
|
||||
case LanguageSSHDConfig:
|
||||
case utils.LanguageSSHDConfig:
|
||||
return sshdconfig.TextDocumentDidOpen(context, params)
|
||||
case LanguageSSHConfig:
|
||||
case utils.LanguageSSHConfig:
|
||||
return sshconfig.TextDocumentDidOpen(context, params)
|
||||
case LanguageWireguard:
|
||||
case utils.LanguageWireguard:
|
||||
return wireguard.TextDocumentDidOpen(context, params)
|
||||
case LanguageHosts:
|
||||
case utils.LanguageHosts:
|
||||
return hosts.TextDocumentDidOpen(context, params)
|
||||
case LanguageAliases:
|
||||
case utils.LanguageAliases:
|
||||
return aliases.TextDocumentDidOpen(context, params)
|
||||
}
|
||||
}
|
||||
|
||||
switch *language {
|
||||
case LanguageFstab:
|
||||
case utils.LanguageFstab:
|
||||
return fstab.TextDocumentDidChange(context, params)
|
||||
case LanguageSSHDConfig:
|
||||
case utils.LanguageSSHDConfig:
|
||||
return sshdconfig.TextDocumentDidChange(context, params)
|
||||
case LanguageSSHConfig:
|
||||
case utils.LanguageSSHConfig:
|
||||
return sshconfig.TextDocumentDidChange(context, params)
|
||||
case LanguageWireguard:
|
||||
case utils.LanguageWireguard:
|
||||
return wireguard.TextDocumentDidChange(context, params)
|
||||
case LanguageHosts:
|
||||
case utils.LanguageHosts:
|
||||
return hosts.TextDocumentDidChange(context, params)
|
||||
case LanguageAliases:
|
||||
case utils.LanguageAliases:
|
||||
return aliases.TextDocumentDidChange(context, params)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package roothandler
|
||||
package lsp
|
||||
|
||||
import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
@ -7,39 +7,35 @@ import (
|
||||
sshconfig "config-lsp/handlers/ssh_config/lsp"
|
||||
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
||||
wireguard "config-lsp/handlers/wireguard/lsp"
|
||||
"config-lsp/root-handler/shared"
|
||||
"config-lsp/root-handler/utils"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentDidClose(context *glsp.Context, params *protocol.DidCloseTextDocumentParams) error {
|
||||
language := rootHandler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
|
||||
if language == nil {
|
||||
showParseError(
|
||||
context,
|
||||
params.TextDocument.URI,
|
||||
undetectableError,
|
||||
)
|
||||
|
||||
return undetectableError.Err
|
||||
return nil
|
||||
}
|
||||
|
||||
delete(openedFiles, params.TextDocument.URI)
|
||||
rootHandler.RemoveDocument(params.TextDocument.URI)
|
||||
delete(shared.OpenedFiles, params.TextDocument.URI)
|
||||
shared.Handler.RemoveDocument(params.TextDocument.URI)
|
||||
|
||||
switch *language {
|
||||
case LanguageSSHDConfig:
|
||||
case utils.LanguageSSHDConfig:
|
||||
return sshdconfig.TextDocumentDidClose(context, params)
|
||||
case LanguageSSHConfig:
|
||||
case utils.LanguageSSHConfig:
|
||||
return sshconfig.TextDocumentDidClose(context, params)
|
||||
case LanguageFstab:
|
||||
case utils.LanguageFstab:
|
||||
return fstab.TextDocumentDidClose(context, params)
|
||||
case LanguageWireguard:
|
||||
case utils.LanguageWireguard:
|
||||
return wireguard.TextDocumentDidClose(context, params)
|
||||
case LanguageHosts:
|
||||
case utils.LanguageHosts:
|
||||
return hosts.TextDocumentDidClose(context, params)
|
||||
case LanguageAliases:
|
||||
case utils.LanguageAliases:
|
||||
return aliases.TextDocumentDidClose(context, params)
|
||||
default:
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package roothandler
|
||||
package lsp
|
||||
|
||||
import (
|
||||
"config-lsp/common"
|
||||
"config-lsp/root-handler/shared"
|
||||
"config-lsp/root-handler/utils"
|
||||
"fmt"
|
||||
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
@ -32,60 +34,41 @@ func TextDocumentDidOpen(context *glsp.Context, params *protocol.DidOpenTextDocu
|
||||
}
|
||||
|
||||
switch *language {
|
||||
case LanguageFstab:
|
||||
case utils.LanguageFstab:
|
||||
return fstab.TextDocumentDidOpen(context, params)
|
||||
case LanguageSSHDConfig:
|
||||
case utils.LanguageSSHDConfig:
|
||||
return sshdconfig.TextDocumentDidOpen(context, params)
|
||||
case LanguageSSHConfig:
|
||||
case utils.LanguageSSHConfig:
|
||||
return sshconfig.TextDocumentDidOpen(context, params)
|
||||
case LanguageWireguard:
|
||||
case utils.LanguageWireguard:
|
||||
return wireguard.TextDocumentDidOpen(context, params)
|
||||
case LanguageHosts:
|
||||
case utils.LanguageHosts:
|
||||
return hosts.TextDocumentDidOpen(context, params)
|
||||
case LanguageAliases:
|
||||
case utils.LanguageAliases:
|
||||
return aliases.TextDocumentDidOpen(context, params)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unexpected roothandler.SupportedLanguage: %#v", language))
|
||||
}
|
||||
|
||||
func showParseError(
|
||||
context *glsp.Context,
|
||||
uri protocol.DocumentUri,
|
||||
err common.ParseError,
|
||||
) {
|
||||
context.Notify(
|
||||
"window/showMessage",
|
||||
protocol.ShowMessageParams{
|
||||
Type: protocol.MessageTypeError,
|
||||
Message: err.Err.Error(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func initFile(
|
||||
context *glsp.Context,
|
||||
content string,
|
||||
uri protocol.DocumentUri,
|
||||
advertisedLanguage string,
|
||||
) (*SupportedLanguage, error) {
|
||||
language, err := DetectLanguage(content, advertisedLanguage, uri)
|
||||
) (*utils.SupportedLanguage, error) {
|
||||
language, err := utils.DetectLanguage(content, advertisedLanguage, uri)
|
||||
|
||||
if err != nil {
|
||||
parseError := err.(common.ParseError)
|
||||
showParseError(
|
||||
context,
|
||||
uri,
|
||||
parseError,
|
||||
)
|
||||
utils.NotifyLanguageUndetectable(context, uri)
|
||||
|
||||
return nil, parseError.Err
|
||||
return nil, utils.LanguageUndetectableError{}
|
||||
}
|
||||
|
||||
openedFiles[uri] = struct{}{}
|
||||
shared.OpenedFiles[uri] = struct{}{}
|
||||
|
||||
// Everything okay, now we can handle the file
|
||||
rootHandler.AddDocument(uri, language)
|
||||
shared.Handler.AddDocument(uri, language)
|
||||
|
||||
return &language, nil
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package roothandler
|
||||
package lsp
|
||||
|
||||
import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
@ -7,36 +7,32 @@ import (
|
||||
sshconfig "config-lsp/handlers/ssh_config/lsp"
|
||||
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
||||
wireguard "config-lsp/handlers/wireguard/lsp"
|
||||
"config-lsp/root-handler/shared"
|
||||
"config-lsp/root-handler/utils"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentHover(context *glsp.Context, params *protocol.HoverParams) (*protocol.Hover, error) {
|
||||
language := rootHandler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
|
||||
if language == nil {
|
||||
showParseError(
|
||||
context,
|
||||
params.TextDocument.URI,
|
||||
undetectableError,
|
||||
)
|
||||
|
||||
return nil, undetectableError.Err
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
switch *language {
|
||||
case LanguageHosts:
|
||||
case utils.LanguageHosts:
|
||||
return hosts.TextDocumentHover(context, params)
|
||||
case LanguageSSHDConfig:
|
||||
case utils.LanguageSSHDConfig:
|
||||
return sshdconfig.TextDocumentHover(context, params)
|
||||
case LanguageSSHConfig:
|
||||
case utils.LanguageSSHConfig:
|
||||
return sshconfig.TextDocumentHover(context, params)
|
||||
case LanguageFstab:
|
||||
case utils.LanguageFstab:
|
||||
return fstab.TextDocumentHover(context, params)
|
||||
case LanguageWireguard:
|
||||
case utils.LanguageWireguard:
|
||||
return wireguard.TextDocumentHover(context, params)
|
||||
case LanguageAliases:
|
||||
case utils.LanguageAliases:
|
||||
return aliases.TextDocumentHover(context, params)
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
package roothandler
|
||||
package lsp
|
||||
|
||||
import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
sshconfig "config-lsp/handlers/ssh_config/lsp"
|
||||
"config-lsp/root-handler/shared"
|
||||
"config-lsp/root-handler/utils"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
|
||||
@ -10,30 +12,24 @@ import (
|
||||
)
|
||||
|
||||
func TextDocumentPrepareRename(context *glsp.Context, params *protocol.PrepareRenameParams) (any, error) {
|
||||
language := rootHandler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
|
||||
if language == nil {
|
||||
showParseError(
|
||||
context,
|
||||
params.TextDocument.URI,
|
||||
undetectableError,
|
||||
)
|
||||
|
||||
return nil, undetectableError.Err
|
||||
return nil, utils.LanguageUndetectableError{}
|
||||
}
|
||||
|
||||
switch *language {
|
||||
case LanguageHosts:
|
||||
case utils.LanguageHosts:
|
||||
return nil, nil
|
||||
case LanguageSSHDConfig:
|
||||
case utils.LanguageSSHDConfig:
|
||||
return nil, nil
|
||||
case LanguageSSHConfig:
|
||||
case utils.LanguageSSHConfig:
|
||||
return sshconfig.TextDocumentPrepareRename(context, params)
|
||||
case LanguageFstab:
|
||||
case utils.LanguageFstab:
|
||||
return nil, nil
|
||||
case LanguageWireguard:
|
||||
case utils.LanguageWireguard:
|
||||
return nil, nil
|
||||
case LanguageAliases:
|
||||
case utils.LanguageAliases:
|
||||
return aliases.TextDocumentPrepareRename(context, params)
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
package roothandler
|
||||
package lsp
|
||||
|
||||
import (
|
||||
sshconfig "config-lsp/handlers/ssh_config/lsp"
|
||||
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
||||
"config-lsp/root-handler/shared"
|
||||
"config-lsp/root-handler/utils"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
@ -12,30 +14,24 @@ func TextDocumentRangeFormattingFunc(
|
||||
context *glsp.Context,
|
||||
params *protocol.DocumentRangeFormattingParams,
|
||||
) ([]protocol.TextEdit, error) {
|
||||
language := rootHandler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
|
||||
if language == nil {
|
||||
showParseError(
|
||||
context,
|
||||
params.TextDocument.URI,
|
||||
undetectableError,
|
||||
)
|
||||
|
||||
return nil, undetectableError.Err
|
||||
return nil, utils.LanguageUndetectableError{}
|
||||
}
|
||||
|
||||
switch *language {
|
||||
case LanguageHosts:
|
||||
case utils.LanguageHosts:
|
||||
return nil, nil
|
||||
case LanguageSSHDConfig:
|
||||
case utils.LanguageSSHDConfig:
|
||||
return sshdconfig.TextDocumentRangeFormatting(context, params)
|
||||
case LanguageSSHConfig:
|
||||
case utils.LanguageSSHConfig:
|
||||
return sshconfig.TextDocumentRangeFormatting(context, params)
|
||||
case LanguageFstab:
|
||||
case utils.LanguageFstab:
|
||||
return nil, nil
|
||||
case LanguageWireguard:
|
||||
case utils.LanguageWireguard:
|
||||
return nil, nil
|
||||
case LanguageAliases:
|
||||
case utils.LanguageAliases:
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -1,38 +1,34 @@
|
||||
package roothandler
|
||||
package lsp
|
||||
|
||||
import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
sshconfig "config-lsp/handlers/ssh_config/lsp"
|
||||
"config-lsp/root-handler/shared"
|
||||
"config-lsp/root-handler/utils"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentRename(context *glsp.Context, params *protocol.RenameParams) (*protocol.WorkspaceEdit, error) {
|
||||
language := rootHandler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
|
||||
if language == nil {
|
||||
showParseError(
|
||||
context,
|
||||
params.TextDocument.URI,
|
||||
undetectableError,
|
||||
)
|
||||
|
||||
return nil, undetectableError.Err
|
||||
return nil, utils.LanguageUndetectableError{}
|
||||
}
|
||||
|
||||
switch *language {
|
||||
case LanguageHosts:
|
||||
case utils.LanguageHosts:
|
||||
return nil, nil
|
||||
case LanguageSSHDConfig:
|
||||
case utils.LanguageSSHDConfig:
|
||||
return nil, nil
|
||||
case LanguageSSHConfig:
|
||||
case utils.LanguageSSHConfig:
|
||||
return sshconfig.TextDocumentRename(context, params)
|
||||
case LanguageFstab:
|
||||
case utils.LanguageFstab:
|
||||
return nil, nil
|
||||
case LanguageWireguard:
|
||||
case utils.LanguageWireguard:
|
||||
return nil, nil
|
||||
case LanguageAliases:
|
||||
case utils.LanguageAliases:
|
||||
return aliases.TextDocumentRename(context, params)
|
||||
}
|
||||
|
@ -1,39 +1,35 @@
|
||||
package roothandler
|
||||
package lsp
|
||||
|
||||
import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
||||
sshconfig "config-lsp/handlers/ssh_config/lsp"
|
||||
sshdconfig "config-lsp/handlers/sshd_config/lsp"
|
||||
"config-lsp/root-handler/shared"
|
||||
"config-lsp/root-handler/utils"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func TextDocumentSignatureHelp(context *glsp.Context, params *protocol.SignatureHelpParams) (*protocol.SignatureHelp, error) {
|
||||
language := rootHandler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
language := shared.Handler.GetLanguageForDocument(params.TextDocument.URI)
|
||||
|
||||
if language == nil {
|
||||
showParseError(
|
||||
context,
|
||||
params.TextDocument.URI,
|
||||
undetectableError,
|
||||
)
|
||||
|
||||
return nil, undetectableError.Err
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
switch *language {
|
||||
case LanguageHosts:
|
||||
case utils.LanguageHosts:
|
||||
return nil, nil
|
||||
case LanguageSSHDConfig:
|
||||
case utils.LanguageSSHDConfig:
|
||||
return sshdconfig.TextDocumentSignatureHelp(context, params)
|
||||
case LanguageSSHConfig:
|
||||
case utils.LanguageSSHConfig:
|
||||
return sshconfig.TextDocumentSignatureHelp(context, params)
|
||||
case LanguageFstab:
|
||||
case utils.LanguageFstab:
|
||||
return nil, nil
|
||||
case LanguageWireguard:
|
||||
case utils.LanguageWireguard:
|
||||
return nil, nil
|
||||
case LanguageAliases:
|
||||
case utils.LanguageAliases:
|
||||
return aliases.TextDocumentSignatureHelp(context, params)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package roothandler
|
||||
package lsp
|
||||
|
||||
import (
|
||||
aliases "config-lsp/handlers/aliases/lsp"
|
@ -1,5 +0,0 @@
|
||||
package roothandler
|
||||
|
||||
import protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
|
||||
var openedFiles = make(map[protocol.DocumentUri]struct{})
|
@ -1,26 +1,30 @@
|
||||
package roothandler
|
||||
package shared
|
||||
|
||||
import (
|
||||
"config-lsp/root-handler/utils"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
var rootHandler RootHandler
|
||||
var Handler RootHandler
|
||||
|
||||
var OpenedFiles = make(map[protocol.DocumentUri]struct{})
|
||||
|
||||
type RootHandler struct {
|
||||
languageMap map[protocol.DocumentUri]SupportedLanguage
|
||||
languageMap map[protocol.DocumentUri]utils.SupportedLanguage
|
||||
}
|
||||
|
||||
func NewRootHandler() RootHandler {
|
||||
return RootHandler{
|
||||
languageMap: make(map[protocol.DocumentUri]SupportedLanguage),
|
||||
languageMap: make(map[protocol.DocumentUri]utils.SupportedLanguage),
|
||||
}
|
||||
}
|
||||
|
||||
func (h *RootHandler) AddDocument(uri protocol.DocumentUri, language SupportedLanguage) {
|
||||
func (h *RootHandler) AddDocument(uri protocol.DocumentUri, language utils.SupportedLanguage) {
|
||||
h.languageMap[uri] = language
|
||||
}
|
||||
|
||||
func (h *RootHandler) GetLanguageForDocument(uri protocol.DocumentUri) *SupportedLanguage {
|
||||
func (h *RootHandler) GetLanguageForDocument(uri protocol.DocumentUri) *utils.SupportedLanguage {
|
||||
language, found := h.languageMap[uri]
|
||||
|
||||
if !found {
|
@ -1,4 +1,4 @@
|
||||
package roothandler
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -6,7 +6,7 @@ import (
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func fetchAddLanguageActions(uri protocol.DocumentUri) ([]protocol.CodeAction, error) {
|
||||
func FetchAddLanguageActions(uri protocol.DocumentUri) ([]protocol.CodeAction, error) {
|
||||
actions := make([]protocol.CodeAction, 0, len(AllSupportedLanguages))
|
||||
|
||||
kind := protocol.CodeActionKindQuickFix
|
@ -1,4 +1,4 @@
|
||||
package roothandler
|
||||
package utils
|
||||
|
||||
import (
|
||||
"config-lsp/common"
|
||||
@ -31,15 +31,6 @@ var AllSupportedLanguages = []string{
|
||||
string(LanguageAliases),
|
||||
}
|
||||
|
||||
type FatalFileNotReadableError struct {
|
||||
FileURI protocol.DocumentUri
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e FatalFileNotReadableError) Error() string {
|
||||
return fmt.Sprintf("Fatal error! config-lsp was unable to read the file (%s); error: %s", e.FileURI, e.Err.Error())
|
||||
}
|
||||
|
||||
type UnsupportedLanguageError struct {
|
||||
SuggestedLanguage string
|
||||
}
|
45
server/root-handler/utils/notification.go
Normal file
45
server/root-handler/utils/notification.go
Normal file
@ -0,0 +1,45 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
type lspNotification struct {
|
||||
uri string
|
||||
}
|
||||
|
||||
type lspDetectedLanguage struct {
|
||||
lspNotification
|
||||
|
||||
language string
|
||||
}
|
||||
|
||||
func NotifyLanguageUndetectable(context *glsp.Context, uri protocol.DocumentUri) {
|
||||
go context.Notify(
|
||||
"$/config-lsp/languageUndetectable",
|
||||
lspNotification{
|
||||
uri: string(uri),
|
||||
},
|
||||
)
|
||||
|
||||
go context.Notify(
|
||||
"window/showMessage",
|
||||
protocol.ShowMessageParams{
|
||||
Type: protocol.MessageTypeError,
|
||||
Message: "config-lsp was unable to detect the appropriate language for this file. Please add: '#?lsp.language=<language>'.",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func NotifyDetectedLanguage(context *glsp.Context, uri protocol.DocumentUri, language SupportedLanguage) {
|
||||
go context.Notify(
|
||||
"$/config-lsp/detectedLanguage",
|
||||
lspDetectedLanguage{
|
||||
lspNotification: lspNotification{
|
||||
uri: string(uri),
|
||||
},
|
||||
language: string(language),
|
||||
},
|
||||
)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user