config-lsp/root-handler/workspace-execute-command.go
2024-09-10 23:11:14 +02:00

37 lines
734 B
Go

package roothandler
import (
hosts "config-lsp/handlers/hosts/lsp"
wireguard "config-lsp/handlers/wireguard/lsp"
"strings"
"github.com/tliron/glsp"
protocol "github.com/tliron/glsp/protocol_3_16"
)
func WorkspaceExecuteCommand(context *glsp.Context, params *protocol.ExecuteCommandParams) (any, error) {
commandSection, _, _ := strings.Cut(params.Command, ".")
var edit *protocol.ApplyWorkspaceEditParams
var err error
switch commandSection {
case "wireguard":
edit, err = wireguard.WorkspaceExecuteCommand(context, params)
case "hosts":
edit, err = hosts.WorkspaceExecuteCommand(context, params)
}
if err != nil {
return nil, err
}
context.Notify(
"workspace/applyEdit",
edit,
)
return nil, nil
}