2018-09-24 15:24:58 -06:00
|
|
|
package protocol
|
|
|
|
|
2019-11-17 12:29:15 -07:00
|
|
|
// Package protocol contains data types and code for LSP jsonrpcs
|
|
|
|
// generated automatically from vscode-languageserver-node
|
2020-01-27 06:23:25 -07:00
|
|
|
// commit: 7b90c29d0cb5cd7b9c41084f6cb3781a955adeba
|
2020-03-04 11:29:23 -07:00
|
|
|
// last fetched Wed Mar 04 2020 13:02:46 GMT-0500 (Eastern Standard Time)
|
2019-11-17 12:29:15 -07:00
|
|
|
|
2019-05-13 10:27:26 -06:00
|
|
|
// Code generated (see typescript/README.md) DO NOT EDIT.
|
2019-04-23 08:05:23 -06:00
|
|
|
|
2018-09-24 15:24:58 -06:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"golang.org/x/tools/internal/jsonrpc2"
|
2019-08-13 13:07:39 -06:00
|
|
|
"golang.org/x/tools/internal/telemetry/log"
|
2019-10-11 14:08:39 -06:00
|
|
|
"golang.org/x/tools/internal/xcontext"
|
2018-09-24 15:24:58 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
type Client interface {
|
|
|
|
ShowMessage(context.Context, *ShowMessageParams) error
|
|
|
|
LogMessage(context.Context, *LogMessageParams) error
|
2019-04-23 08:05:23 -06:00
|
|
|
Event(context.Context, *interface{}) error
|
|
|
|
PublishDiagnostics(context.Context, *PublishDiagnosticsParams) error
|
2019-11-17 12:29:15 -07:00
|
|
|
WorkspaceFolders(context.Context) ([]WorkspaceFolder /*WorkspaceFolder[] | null*/, error)
|
|
|
|
Configuration(context.Context, *ParamConfiguration) ([]interface{}, error)
|
2019-04-23 08:05:23 -06:00
|
|
|
RegisterCapability(context.Context, *RegistrationParams) error
|
|
|
|
UnregisterCapability(context.Context, *UnregistrationParams) error
|
2019-11-17 12:29:15 -07:00
|
|
|
ShowMessageRequest(context.Context, *ShowMessageRequestParams) (*MessageActionItem /*MessageActionItem | null*/, error)
|
2019-04-23 08:05:23 -06:00
|
|
|
ApplyEdit(context.Context, *ApplyWorkspaceEditParams) (*ApplyWorkspaceEditResponse, error)
|
2018-09-24 15:24:58 -06:00
|
|
|
}
|
|
|
|
|
2019-07-11 10:57:35 -06:00
|
|
|
func (h clientHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, delivered bool) bool {
|
|
|
|
if delivered {
|
|
|
|
return false
|
|
|
|
}
|
2019-10-11 14:08:39 -06:00
|
|
|
if ctx.Err() != nil {
|
|
|
|
ctx := xcontext.Detach(ctx)
|
|
|
|
r.Reply(ctx, nil, jsonrpc2.NewErrorf(RequestCancelledError, ""))
|
2019-07-11 10:57:35 -06:00
|
|
|
return true
|
2019-10-11 14:08:39 -06:00
|
|
|
}
|
|
|
|
switch r.Method {
|
2019-07-11 10:57:35 -06:00
|
|
|
case "window/showMessage": // notif
|
|
|
|
var params ShowMessageParams
|
|
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
2019-07-12 17:26:13 -06:00
|
|
|
sendParseError(ctx, r, err)
|
2019-07-11 10:57:35 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
if err := h.client.ShowMessage(ctx, ¶ms); err != nil {
|
2019-07-14 21:08:10 -06:00
|
|
|
log.Error(ctx, "", err)
|
2019-07-11 10:57:35 -06:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
case "window/logMessage": // notif
|
|
|
|
var params LogMessageParams
|
|
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
2019-07-12 17:26:13 -06:00
|
|
|
sendParseError(ctx, r, err)
|
2019-07-11 10:57:35 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
if err := h.client.LogMessage(ctx, ¶ms); err != nil {
|
2019-07-14 21:08:10 -06:00
|
|
|
log.Error(ctx, "", err)
|
2019-07-11 10:57:35 -06:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
case "telemetry/event": // notif
|
|
|
|
var params interface{}
|
|
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
2019-07-12 17:26:13 -06:00
|
|
|
sendParseError(ctx, r, err)
|
2019-07-11 10:57:35 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
if err := h.client.Event(ctx, ¶ms); err != nil {
|
2019-07-14 21:08:10 -06:00
|
|
|
log.Error(ctx, "", err)
|
2019-07-11 10:57:35 -06:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
case "textDocument/publishDiagnostics": // notif
|
|
|
|
var params PublishDiagnosticsParams
|
|
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
2019-07-12 17:26:13 -06:00
|
|
|
sendParseError(ctx, r, err)
|
2019-07-11 10:57:35 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
if err := h.client.PublishDiagnostics(ctx, ¶ms); err != nil {
|
2019-07-14 21:08:10 -06:00
|
|
|
log.Error(ctx, "", err)
|
2019-07-11 10:57:35 -06:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
case "workspace/workspaceFolders": // req
|
|
|
|
if r.Params != nil {
|
|
|
|
r.Reply(ctx, nil, jsonrpc2.NewErrorf(jsonrpc2.CodeInvalidParams, "Expected no params"))
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
resp, err := h.client.WorkspaceFolders(ctx)
|
|
|
|
if err := r.Reply(ctx, resp, err); err != nil {
|
2019-07-14 21:08:10 -06:00
|
|
|
log.Error(ctx, "", err)
|
2018-09-24 15:24:58 -06:00
|
|
|
}
|
2019-07-11 10:57:35 -06:00
|
|
|
return true
|
|
|
|
case "workspace/configuration": // req
|
2019-11-17 12:29:15 -07:00
|
|
|
var params ParamConfiguration
|
2019-07-11 10:57:35 -06:00
|
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
2019-07-12 17:26:13 -06:00
|
|
|
sendParseError(ctx, r, err)
|
2019-07-11 10:57:35 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
resp, err := h.client.Configuration(ctx, ¶ms)
|
|
|
|
if err := r.Reply(ctx, resp, err); err != nil {
|
2019-07-14 21:08:10 -06:00
|
|
|
log.Error(ctx, "", err)
|
2019-07-11 10:57:35 -06:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
case "client/registerCapability": // req
|
|
|
|
var params RegistrationParams
|
|
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
2019-07-12 17:26:13 -06:00
|
|
|
sendParseError(ctx, r, err)
|
2019-07-11 10:57:35 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
err := h.client.RegisterCapability(ctx, ¶ms)
|
|
|
|
if err := r.Reply(ctx, nil, err); err != nil {
|
2019-07-14 21:08:10 -06:00
|
|
|
log.Error(ctx, "", err)
|
2019-07-11 10:57:35 -06:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
case "client/unregisterCapability": // req
|
|
|
|
var params UnregistrationParams
|
|
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
2019-07-12 17:26:13 -06:00
|
|
|
sendParseError(ctx, r, err)
|
2019-07-11 10:57:35 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
err := h.client.UnregisterCapability(ctx, ¶ms)
|
|
|
|
if err := r.Reply(ctx, nil, err); err != nil {
|
2019-07-14 21:08:10 -06:00
|
|
|
log.Error(ctx, "", err)
|
2019-07-11 10:57:35 -06:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
case "window/showMessageRequest": // req
|
|
|
|
var params ShowMessageRequestParams
|
|
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
2019-07-12 17:26:13 -06:00
|
|
|
sendParseError(ctx, r, err)
|
2019-07-11 10:57:35 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
resp, err := h.client.ShowMessageRequest(ctx, ¶ms)
|
|
|
|
if err := r.Reply(ctx, resp, err); err != nil {
|
2019-07-14 21:08:10 -06:00
|
|
|
log.Error(ctx, "", err)
|
2019-07-11 10:57:35 -06:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
case "workspace/applyEdit": // req
|
|
|
|
var params ApplyWorkspaceEditParams
|
|
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
2019-07-12 17:26:13 -06:00
|
|
|
sendParseError(ctx, r, err)
|
2019-07-11 10:57:35 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
resp, err := h.client.ApplyEdit(ctx, ¶ms)
|
|
|
|
if err := r.Reply(ctx, resp, err); err != nil {
|
2019-07-14 21:08:10 -06:00
|
|
|
log.Error(ctx, "", err)
|
2019-07-11 10:57:35 -06:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
2020-01-10 15:35:46 -07:00
|
|
|
|
2018-09-24 15:24:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type clientDispatcher struct {
|
|
|
|
*jsonrpc2.Conn
|
|
|
|
}
|
|
|
|
|
2019-04-23 08:05:23 -06:00
|
|
|
func (s *clientDispatcher) ShowMessage(ctx context.Context, params *ShowMessageParams) error {
|
|
|
|
return s.Conn.Notify(ctx, "window/showMessage", params)
|
2018-09-24 15:24:58 -06:00
|
|
|
}
|
|
|
|
|
2019-04-23 08:05:23 -06:00
|
|
|
func (s *clientDispatcher) LogMessage(ctx context.Context, params *LogMessageParams) error {
|
|
|
|
return s.Conn.Notify(ctx, "window/logMessage", params)
|
2018-09-24 15:24:58 -06:00
|
|
|
}
|
|
|
|
|
2019-04-23 08:05:23 -06:00
|
|
|
func (s *clientDispatcher) Event(ctx context.Context, params *interface{}) error {
|
|
|
|
return s.Conn.Notify(ctx, "telemetry/event", params)
|
2018-09-24 15:24:58 -06:00
|
|
|
}
|
|
|
|
|
2019-04-23 08:05:23 -06:00
|
|
|
func (s *clientDispatcher) PublishDiagnostics(ctx context.Context, params *PublishDiagnosticsParams) error {
|
|
|
|
return s.Conn.Notify(ctx, "textDocument/publishDiagnostics", params)
|
2018-09-24 15:24:58 -06:00
|
|
|
}
|
2019-11-17 12:29:15 -07:00
|
|
|
func (s *clientDispatcher) WorkspaceFolders(ctx context.Context) ([]WorkspaceFolder /*WorkspaceFolder[] | null*/, error) {
|
|
|
|
var result []WorkspaceFolder /*WorkspaceFolder[] | null*/
|
2019-04-23 08:05:23 -06:00
|
|
|
if err := s.Conn.Call(ctx, "workspace/workspaceFolders", nil, &result); err != nil {
|
2018-09-24 15:24:58 -06:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2019-11-17 12:29:15 -07:00
|
|
|
func (s *clientDispatcher) Configuration(ctx context.Context, params *ParamConfiguration) ([]interface{}, error) {
|
2018-09-24 15:24:58 -06:00
|
|
|
var result []interface{}
|
2019-04-23 08:05:23 -06:00
|
|
|
if err := s.Conn.Call(ctx, "workspace/configuration", params, &result); err != nil {
|
2018-09-24 15:24:58 -06:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2019-04-23 08:05:23 -06:00
|
|
|
func (s *clientDispatcher) RegisterCapability(ctx context.Context, params *RegistrationParams) error {
|
2019-05-28 07:47:51 -06:00
|
|
|
return s.Conn.Call(ctx, "client/registerCapability", params, nil) // Call, not Notify
|
2019-04-23 08:05:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *clientDispatcher) UnregisterCapability(ctx context.Context, params *UnregistrationParams) error {
|
2019-05-28 07:47:51 -06:00
|
|
|
return s.Conn.Call(ctx, "client/unregisterCapability", params, nil) // Call, not Notify
|
2019-04-23 08:05:23 -06:00
|
|
|
}
|
|
|
|
|
2019-11-17 12:29:15 -07:00
|
|
|
func (s *clientDispatcher) ShowMessageRequest(ctx context.Context, params *ShowMessageRequestParams) (*MessageActionItem /*MessageActionItem | null*/, error) {
|
2020-03-04 11:29:23 -07:00
|
|
|
var result *MessageActionItem /*MessageActionItem | null*/
|
2019-04-23 08:05:23 -06:00
|
|
|
if err := s.Conn.Call(ctx, "window/showMessageRequest", params, &result); err != nil {
|
|
|
|
return nil, err
|
2018-09-24 15:24:58 -06:00
|
|
|
}
|
2020-03-04 11:29:23 -07:00
|
|
|
return result, nil
|
2018-09-24 15:24:58 -06:00
|
|
|
}
|
|
|
|
|
2019-04-23 08:05:23 -06:00
|
|
|
func (s *clientDispatcher) ApplyEdit(ctx context.Context, params *ApplyWorkspaceEditParams) (*ApplyWorkspaceEditResponse, error) {
|
2020-03-04 11:29:23 -07:00
|
|
|
var result *ApplyWorkspaceEditResponse
|
2019-04-23 08:05:23 -06:00
|
|
|
if err := s.Conn.Call(ctx, "workspace/applyEdit", params, &result); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-03-04 11:29:23 -07:00
|
|
|
return result, nil
|
2018-09-24 15:24:58 -06:00
|
|
|
}
|