github.com/v2fly/tools@v0.100.0/internal/lsp/protocol/tsclient.go (about) 1 // Copyright 2019 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package protocol 6 7 // Package protocol contains data types and code for LSP jsonrpcs 8 // generated automatically from vscode-languageserver-node 9 // commit: d58c00bbf8837b9fd0144924db5e7b1c543d839e 10 // last fetched Sat Apr 17 2021 08:26:29 GMT-0400 (Eastern Daylight Time) 11 12 // Code generated (see typescript/README.md) DO NOT EDIT. 13 14 import ( 15 "context" 16 "encoding/json" 17 18 "github.com/v2fly/tools/internal/jsonrpc2" 19 errors "golang.org/x/xerrors" 20 ) 21 22 type Client interface { 23 ShowMessage(context.Context, *ShowMessageParams) error 24 LogMessage(context.Context, *LogMessageParams) error 25 Event(context.Context, *interface{}) error 26 PublishDiagnostics(context.Context, *PublishDiagnosticsParams) error 27 Progress(context.Context, *ProgressParams) error 28 WorkspaceFolders(context.Context) ([]WorkspaceFolder /*WorkspaceFolder[] | null*/, error) 29 Configuration(context.Context, *ParamConfiguration) ([]interface{}, error) 30 WorkDoneProgressCreate(context.Context, *WorkDoneProgressCreateParams) error 31 RegisterCapability(context.Context, *RegistrationParams) error 32 UnregisterCapability(context.Context, *UnregistrationParams) error 33 ShowMessageRequest(context.Context, *ShowMessageRequestParams) (*MessageActionItem /*MessageActionItem | null*/, error) 34 ApplyEdit(context.Context, *ApplyWorkspaceEditParams) (*ApplyWorkspaceEditResponse, error) 35 } 36 37 func clientDispatch(ctx context.Context, client Client, reply jsonrpc2.Replier, r jsonrpc2.Request) (bool, error) { 38 switch r.Method() { 39 case "window/showMessage": // notif 40 var params ShowMessageParams 41 if err := json.Unmarshal(r.Params(), ¶ms); err != nil { 42 return true, sendParseError(ctx, reply, err) 43 } 44 err := client.ShowMessage(ctx, ¶ms) 45 return true, reply(ctx, nil, err) 46 case "window/logMessage": // notif 47 var params LogMessageParams 48 if err := json.Unmarshal(r.Params(), ¶ms); err != nil { 49 return true, sendParseError(ctx, reply, err) 50 } 51 err := client.LogMessage(ctx, ¶ms) 52 return true, reply(ctx, nil, err) 53 case "telemetry/event": // notif 54 var params interface{} 55 if err := json.Unmarshal(r.Params(), ¶ms); err != nil { 56 return true, sendParseError(ctx, reply, err) 57 } 58 err := client.Event(ctx, ¶ms) 59 return true, reply(ctx, nil, err) 60 case "textDocument/publishDiagnostics": // notif 61 var params PublishDiagnosticsParams 62 if err := json.Unmarshal(r.Params(), ¶ms); err != nil { 63 return true, sendParseError(ctx, reply, err) 64 } 65 err := client.PublishDiagnostics(ctx, ¶ms) 66 return true, reply(ctx, nil, err) 67 case "$/progress": // notif 68 var params ProgressParams 69 if err := json.Unmarshal(r.Params(), ¶ms); err != nil { 70 return true, sendParseError(ctx, reply, err) 71 } 72 err := client.Progress(ctx, ¶ms) 73 return true, reply(ctx, nil, err) 74 case "workspace/workspaceFolders": // req 75 if len(r.Params()) > 0 { 76 return true, reply(ctx, nil, errors.Errorf("%w: expected no params", jsonrpc2.ErrInvalidParams)) 77 } 78 resp, err := client.WorkspaceFolders(ctx) 79 return true, reply(ctx, resp, err) 80 case "workspace/configuration": // req 81 var params ParamConfiguration 82 if err := json.Unmarshal(r.Params(), ¶ms); err != nil { 83 return true, sendParseError(ctx, reply, err) 84 } 85 resp, err := client.Configuration(ctx, ¶ms) 86 return true, reply(ctx, resp, err) 87 case "window/workDoneProgress/create": // req 88 var params WorkDoneProgressCreateParams 89 if err := json.Unmarshal(r.Params(), ¶ms); err != nil { 90 return true, sendParseError(ctx, reply, err) 91 } 92 err := client.WorkDoneProgressCreate(ctx, ¶ms) 93 return true, reply(ctx, nil, err) 94 case "client/registerCapability": // req 95 var params RegistrationParams 96 if err := json.Unmarshal(r.Params(), ¶ms); err != nil { 97 return true, sendParseError(ctx, reply, err) 98 } 99 err := client.RegisterCapability(ctx, ¶ms) 100 return true, reply(ctx, nil, err) 101 case "client/unregisterCapability": // req 102 var params UnregistrationParams 103 if err := json.Unmarshal(r.Params(), ¶ms); err != nil { 104 return true, sendParseError(ctx, reply, err) 105 } 106 err := client.UnregisterCapability(ctx, ¶ms) 107 return true, reply(ctx, nil, err) 108 case "window/showMessageRequest": // req 109 var params ShowMessageRequestParams 110 if err := json.Unmarshal(r.Params(), ¶ms); err != nil { 111 return true, sendParseError(ctx, reply, err) 112 } 113 resp, err := client.ShowMessageRequest(ctx, ¶ms) 114 return true, reply(ctx, resp, err) 115 case "workspace/applyEdit": // req 116 var params ApplyWorkspaceEditParams 117 if err := json.Unmarshal(r.Params(), ¶ms); err != nil { 118 return true, sendParseError(ctx, reply, err) 119 } 120 resp, err := client.ApplyEdit(ctx, ¶ms) 121 return true, reply(ctx, resp, err) 122 123 default: 124 return false, nil 125 } 126 } 127 128 func (s *clientDispatcher) ShowMessage(ctx context.Context, params *ShowMessageParams) error { 129 return s.Conn.Notify(ctx, "window/showMessage", params) 130 } 131 132 func (s *clientDispatcher) LogMessage(ctx context.Context, params *LogMessageParams) error { 133 return s.Conn.Notify(ctx, "window/logMessage", params) 134 } 135 136 func (s *clientDispatcher) Event(ctx context.Context, params *interface{}) error { 137 return s.Conn.Notify(ctx, "telemetry/event", params) 138 } 139 140 func (s *clientDispatcher) PublishDiagnostics(ctx context.Context, params *PublishDiagnosticsParams) error { 141 return s.Conn.Notify(ctx, "textDocument/publishDiagnostics", params) 142 } 143 144 func (s *clientDispatcher) Progress(ctx context.Context, params *ProgressParams) error { 145 return s.Conn.Notify(ctx, "$/progress", params) 146 } 147 func (s *clientDispatcher) WorkspaceFolders(ctx context.Context) ([]WorkspaceFolder /*WorkspaceFolder[] | null*/, error) { 148 var result []WorkspaceFolder /*WorkspaceFolder[] | null*/ 149 if err := Call(ctx, s.Conn, "workspace/workspaceFolders", nil, &result); err != nil { 150 return nil, err 151 } 152 return result, nil 153 } 154 155 func (s *clientDispatcher) Configuration(ctx context.Context, params *ParamConfiguration) ([]interface{}, error) { 156 var result []interface{} 157 if err := Call(ctx, s.Conn, "workspace/configuration", params, &result); err != nil { 158 return nil, err 159 } 160 return result, nil 161 } 162 163 func (s *clientDispatcher) WorkDoneProgressCreate(ctx context.Context, params *WorkDoneProgressCreateParams) error { 164 return Call(ctx, s.Conn, "window/workDoneProgress/create", params, nil) // Call, not Notify 165 } 166 167 func (s *clientDispatcher) RegisterCapability(ctx context.Context, params *RegistrationParams) error { 168 return Call(ctx, s.Conn, "client/registerCapability", params, nil) // Call, not Notify 169 } 170 171 func (s *clientDispatcher) UnregisterCapability(ctx context.Context, params *UnregistrationParams) error { 172 return Call(ctx, s.Conn, "client/unregisterCapability", params, nil) // Call, not Notify 173 } 174 175 func (s *clientDispatcher) ShowMessageRequest(ctx context.Context, params *ShowMessageRequestParams) (*MessageActionItem /*MessageActionItem | null*/, error) { 176 var result *MessageActionItem /*MessageActionItem | null*/ 177 if err := Call(ctx, s.Conn, "window/showMessageRequest", params, &result); err != nil { 178 return nil, err 179 } 180 return result, nil 181 } 182 183 func (s *clientDispatcher) ApplyEdit(ctx context.Context, params *ApplyWorkspaceEditParams) (*ApplyWorkspaceEditResponse, error) { 184 var result *ApplyWorkspaceEditResponse 185 if err := Call(ctx, s.Conn, "workspace/applyEdit", params, &result); err != nil { 186 return nil, err 187 } 188 return result, nil 189 }