1// Copyright 2019 The Go Authors. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package protocol 16 17import ( 18 "context" 19 "encoding/json" 20 "log" 21 22 "github.com/KhronosGroup/SPIRV-Tools/utils/vscode/src/lsp/jsonrpc2" 23) 24 25type Server interface { 26 DidChangeWorkspaceFolders(context.Context, *DidChangeWorkspaceFoldersParams) error 27 Initialized(context.Context, *InitializedParams) error 28 Exit(context.Context) error 29 DidChangeConfiguration(context.Context, *DidChangeConfigurationParams) error 30 DidOpen(context.Context, *DidOpenTextDocumentParams) error 31 DidChange(context.Context, *DidChangeTextDocumentParams) error 32 DidClose(context.Context, *DidCloseTextDocumentParams) error 33 DidSave(context.Context, *DidSaveTextDocumentParams) error 34 WillSave(context.Context, *WillSaveTextDocumentParams) error 35 DidChangeWatchedFiles(context.Context, *DidChangeWatchedFilesParams) error 36 Progress(context.Context, *ProgressParams) error 37 SetTraceNotification(context.Context, *SetTraceParams) error 38 LogTraceNotification(context.Context, *LogTraceParams) error 39 Implementation(context.Context, *ImplementationParams) ([]Location, error) 40 TypeDefinition(context.Context, *TypeDefinitionParams) ([]Location, error) 41 DocumentColor(context.Context, *DocumentColorParams) ([]ColorInformation, error) 42 ColorPresentation(context.Context, *ColorPresentationParams) ([]ColorPresentation, error) 43 FoldingRange(context.Context, *FoldingRangeParams) ([]FoldingRange, error) 44 Declaration(context.Context, *DeclarationParams) ([]DeclarationLink, error) 45 SelectionRange(context.Context, *SelectionRangeParams) ([]SelectionRange, error) 46 Initialize(context.Context, *ParamInitia) (*InitializeResult, error) 47 Shutdown(context.Context) error 48 WillSaveWaitUntil(context.Context, *WillSaveTextDocumentParams) ([]TextEdit, error) 49 Completion(context.Context, *CompletionParams) (*CompletionList, error) 50 Resolve(context.Context, *CompletionItem) (*CompletionItem, error) 51 Hover(context.Context, *HoverParams) (*Hover, error) 52 SignatureHelp(context.Context, *SignatureHelpParams) (*SignatureHelp, error) 53 Definition(context.Context, *DefinitionParams) ([]Location, error) 54 References(context.Context, *ReferenceParams) ([]Location, error) 55 DocumentHighlight(context.Context, *DocumentHighlightParams) ([]DocumentHighlight, error) 56 DocumentSymbol(context.Context, *DocumentSymbolParams) ([]DocumentSymbol, error) 57 CodeAction(context.Context, *CodeActionParams) ([]CodeAction, error) 58 Symbol(context.Context, *WorkspaceSymbolParams) ([]SymbolInformation, error) 59 CodeLens(context.Context, *CodeLensParams) ([]CodeLens, error) 60 ResolveCodeLens(context.Context, *CodeLens) (*CodeLens, error) 61 DocumentLink(context.Context, *DocumentLinkParams) ([]DocumentLink, error) 62 ResolveDocumentLink(context.Context, *DocumentLink) (*DocumentLink, error) 63 Formatting(context.Context, *DocumentFormattingParams) ([]TextEdit, error) 64 RangeFormatting(context.Context, *DocumentRangeFormattingParams) ([]TextEdit, error) 65 OnTypeFormatting(context.Context, *DocumentOnTypeFormattingParams) ([]TextEdit, error) 66 Rename(context.Context, *RenameParams) (*WorkspaceEdit, error) 67 PrepareRename(context.Context, *PrepareRenameParams) (*Range, error) 68 ExecuteCommand(context.Context, *ExecuteCommandParams) (interface{}, error) 69} 70 71func (h serverHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, delivered bool) bool { 72 if delivered { 73 return false 74 } 75 if ctx.Err() != nil { 76 r.Reply(ctx, nil, jsonrpc2.NewErrorf(RequestCancelledError, "")) 77 return true 78 } 79 switch r.Method { 80 case "workspace/didChangeWorkspaceFolders": // notif 81 var params DidChangeWorkspaceFoldersParams 82 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 83 sendParseError(ctx, r, err) 84 return true 85 } 86 if err := h.server.DidChangeWorkspaceFolders(ctx, ¶ms); err != nil { 87 log.Printf("%v", err) 88 } 89 return true 90 case "initialized": // notif 91 var params InitializedParams 92 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 93 sendParseError(ctx, r, err) 94 return true 95 } 96 if err := h.server.Initialized(ctx, ¶ms); err != nil { 97 log.Printf("%v", err) 98 } 99 return true 100 case "exit": // notif 101 if err := h.server.Exit(ctx); err != nil { 102 log.Printf("%v", err) 103 } 104 return true 105 case "workspace/didChangeConfiguration": // notif 106 var params DidChangeConfigurationParams 107 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 108 sendParseError(ctx, r, err) 109 return true 110 } 111 if err := h.server.DidChangeConfiguration(ctx, ¶ms); err != nil { 112 log.Printf("%v", err) 113 } 114 return true 115 case "textDocument/didOpen": // notif 116 var params DidOpenTextDocumentParams 117 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 118 sendParseError(ctx, r, err) 119 return true 120 } 121 if err := h.server.DidOpen(ctx, ¶ms); err != nil { 122 log.Printf("%v", err) 123 } 124 return true 125 case "textDocument/didChange": // notif 126 var params DidChangeTextDocumentParams 127 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 128 sendParseError(ctx, r, err) 129 return true 130 } 131 if err := h.server.DidChange(ctx, ¶ms); err != nil { 132 log.Printf("%v", err) 133 } 134 return true 135 case "textDocument/didClose": // notif 136 var params DidCloseTextDocumentParams 137 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 138 sendParseError(ctx, r, err) 139 return true 140 } 141 if err := h.server.DidClose(ctx, ¶ms); err != nil { 142 log.Printf("%v", err) 143 } 144 return true 145 case "textDocument/didSave": // notif 146 var params DidSaveTextDocumentParams 147 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 148 sendParseError(ctx, r, err) 149 return true 150 } 151 if err := h.server.DidSave(ctx, ¶ms); err != nil { 152 log.Printf("%v", err) 153 } 154 return true 155 case "textDocument/willSave": // notif 156 var params WillSaveTextDocumentParams 157 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 158 sendParseError(ctx, r, err) 159 return true 160 } 161 if err := h.server.WillSave(ctx, ¶ms); err != nil { 162 log.Printf("%v", err) 163 } 164 return true 165 case "workspace/didChangeWatchedFiles": // notif 166 var params DidChangeWatchedFilesParams 167 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 168 sendParseError(ctx, r, err) 169 return true 170 } 171 if err := h.server.DidChangeWatchedFiles(ctx, ¶ms); err != nil { 172 log.Printf("%v", err) 173 } 174 return true 175 case "$/progress": // notif 176 var params ProgressParams 177 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 178 sendParseError(ctx, r, err) 179 return true 180 } 181 if err := h.server.Progress(ctx, ¶ms); err != nil { 182 log.Printf("%v", err) 183 } 184 return true 185 case "$/setTraceNotification": // notif 186 var params SetTraceParams 187 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 188 sendParseError(ctx, r, err) 189 return true 190 } 191 if err := h.server.SetTraceNotification(ctx, ¶ms); err != nil { 192 log.Printf("%v", err) 193 } 194 return true 195 case "$/logTraceNotification": // notif 196 var params LogTraceParams 197 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 198 sendParseError(ctx, r, err) 199 return true 200 } 201 if err := h.server.LogTraceNotification(ctx, ¶ms); err != nil { 202 log.Printf("%v", err) 203 } 204 return true 205 case "textDocument/implementation": // req 206 var params ImplementationParams 207 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 208 sendParseError(ctx, r, err) 209 return true 210 } 211 resp, err := h.server.Implementation(ctx, ¶ms) 212 if err := r.Reply(ctx, resp, err); err != nil { 213 log.Printf("%v", err) 214 } 215 return true 216 case "textDocument/typeDefinition": // req 217 var params TypeDefinitionParams 218 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 219 sendParseError(ctx, r, err) 220 return true 221 } 222 resp, err := h.server.TypeDefinition(ctx, ¶ms) 223 if err := r.Reply(ctx, resp, err); err != nil { 224 log.Printf("%v", err) 225 } 226 return true 227 case "textDocument/documentColor": // req 228 var params DocumentColorParams 229 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 230 sendParseError(ctx, r, err) 231 return true 232 } 233 resp, err := h.server.DocumentColor(ctx, ¶ms) 234 if err := r.Reply(ctx, resp, err); err != nil { 235 log.Printf("%v", err) 236 } 237 return true 238 case "textDocument/colorPresentation": // req 239 var params ColorPresentationParams 240 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 241 sendParseError(ctx, r, err) 242 return true 243 } 244 resp, err := h.server.ColorPresentation(ctx, ¶ms) 245 if err := r.Reply(ctx, resp, err); err != nil { 246 log.Printf("%v", err) 247 } 248 return true 249 case "textDocument/foldingRange": // req 250 var params FoldingRangeParams 251 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 252 sendParseError(ctx, r, err) 253 return true 254 } 255 resp, err := h.server.FoldingRange(ctx, ¶ms) 256 if err := r.Reply(ctx, resp, err); err != nil { 257 log.Printf("%v", err) 258 } 259 return true 260 case "textDocument/declaration": // req 261 var params DeclarationParams 262 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 263 sendParseError(ctx, r, err) 264 return true 265 } 266 resp, err := h.server.Declaration(ctx, ¶ms) 267 if err := r.Reply(ctx, resp, err); err != nil { 268 log.Printf("%v", err) 269 } 270 return true 271 case "textDocument/selectionRange": // req 272 var params SelectionRangeParams 273 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 274 sendParseError(ctx, r, err) 275 return true 276 } 277 resp, err := h.server.SelectionRange(ctx, ¶ms) 278 if err := r.Reply(ctx, resp, err); err != nil { 279 log.Printf("%v", err) 280 } 281 return true 282 case "initialize": // req 283 var params ParamInitia 284 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 285 sendParseError(ctx, r, err) 286 return true 287 } 288 resp, err := h.server.Initialize(ctx, ¶ms) 289 if err := r.Reply(ctx, resp, err); err != nil { 290 log.Printf("%v", err) 291 } 292 return true 293 case "shutdown": // req 294 if r.Params != nil { 295 r.Reply(ctx, nil, jsonrpc2.NewErrorf(jsonrpc2.CodeInvalidParams, "Expected no params")) 296 return true 297 } 298 err := h.server.Shutdown(ctx) 299 if err := r.Reply(ctx, nil, err); err != nil { 300 log.Printf("%v", err) 301 } 302 return true 303 case "textDocument/willSaveWaitUntil": // req 304 var params WillSaveTextDocumentParams 305 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 306 sendParseError(ctx, r, err) 307 return true 308 } 309 resp, err := h.server.WillSaveWaitUntil(ctx, ¶ms) 310 if err := r.Reply(ctx, resp, err); err != nil { 311 log.Printf("%v", err) 312 } 313 return true 314 case "textDocument/completion": // req 315 var params CompletionParams 316 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 317 sendParseError(ctx, r, err) 318 return true 319 } 320 resp, err := h.server.Completion(ctx, ¶ms) 321 if err := r.Reply(ctx, resp, err); err != nil { 322 log.Printf("%v", err) 323 } 324 return true 325 case "completionItem/resolve": // req 326 var params CompletionItem 327 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 328 sendParseError(ctx, r, err) 329 return true 330 } 331 resp, err := h.server.Resolve(ctx, ¶ms) 332 if err := r.Reply(ctx, resp, err); err != nil { 333 log.Printf("%v", err) 334 } 335 return true 336 case "textDocument/hover": // req 337 var params HoverParams 338 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 339 sendParseError(ctx, r, err) 340 return true 341 } 342 resp, err := h.server.Hover(ctx, ¶ms) 343 if err := r.Reply(ctx, resp, err); err != nil { 344 log.Printf("%v", err) 345 } 346 return true 347 case "textDocument/signatureHelp": // req 348 var params SignatureHelpParams 349 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 350 sendParseError(ctx, r, err) 351 return true 352 } 353 resp, err := h.server.SignatureHelp(ctx, ¶ms) 354 if err := r.Reply(ctx, resp, err); err != nil { 355 log.Printf("%v", err) 356 } 357 return true 358 case "textDocument/definition": // req 359 var params DefinitionParams 360 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 361 sendParseError(ctx, r, err) 362 return true 363 } 364 resp, err := h.server.Definition(ctx, ¶ms) 365 if err := r.Reply(ctx, resp, err); err != nil { 366 log.Printf("%v", err) 367 } 368 return true 369 case "textDocument/references": // req 370 var params ReferenceParams 371 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 372 sendParseError(ctx, r, err) 373 return true 374 } 375 resp, err := h.server.References(ctx, ¶ms) 376 if err := r.Reply(ctx, resp, err); err != nil { 377 log.Printf("%v", err) 378 } 379 return true 380 case "textDocument/documentHighlight": // req 381 var params DocumentHighlightParams 382 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 383 sendParseError(ctx, r, err) 384 return true 385 } 386 resp, err := h.server.DocumentHighlight(ctx, ¶ms) 387 if err := r.Reply(ctx, resp, err); err != nil { 388 log.Printf("%v", err) 389 } 390 return true 391 case "textDocument/documentSymbol": // req 392 var params DocumentSymbolParams 393 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 394 sendParseError(ctx, r, err) 395 return true 396 } 397 resp, err := h.server.DocumentSymbol(ctx, ¶ms) 398 if err := r.Reply(ctx, resp, err); err != nil { 399 log.Printf("%v", err) 400 } 401 return true 402 case "textDocument/codeAction": // req 403 var params CodeActionParams 404 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 405 sendParseError(ctx, r, err) 406 return true 407 } 408 resp, err := h.server.CodeAction(ctx, ¶ms) 409 if err := r.Reply(ctx, resp, err); err != nil { 410 log.Printf("%v", err) 411 } 412 return true 413 case "workspace/symbol": // req 414 var params WorkspaceSymbolParams 415 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 416 sendParseError(ctx, r, err) 417 return true 418 } 419 resp, err := h.server.Symbol(ctx, ¶ms) 420 if err := r.Reply(ctx, resp, err); err != nil { 421 log.Printf("%v", err) 422 } 423 return true 424 case "textDocument/codeLens": // req 425 var params CodeLensParams 426 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 427 sendParseError(ctx, r, err) 428 return true 429 } 430 resp, err := h.server.CodeLens(ctx, ¶ms) 431 if err := r.Reply(ctx, resp, err); err != nil { 432 log.Printf("%v", err) 433 } 434 return true 435 case "codeLens/resolve": // req 436 var params CodeLens 437 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 438 sendParseError(ctx, r, err) 439 return true 440 } 441 resp, err := h.server.ResolveCodeLens(ctx, ¶ms) 442 if err := r.Reply(ctx, resp, err); err != nil { 443 log.Printf("%v", err) 444 } 445 return true 446 case "textDocument/documentLink": // req 447 var params DocumentLinkParams 448 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 449 sendParseError(ctx, r, err) 450 return true 451 } 452 resp, err := h.server.DocumentLink(ctx, ¶ms) 453 if err := r.Reply(ctx, resp, err); err != nil { 454 log.Printf("%v", err) 455 } 456 return true 457 case "documentLink/resolve": // req 458 var params DocumentLink 459 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 460 sendParseError(ctx, r, err) 461 return true 462 } 463 resp, err := h.server.ResolveDocumentLink(ctx, ¶ms) 464 if err := r.Reply(ctx, resp, err); err != nil { 465 log.Printf("%v", err) 466 } 467 return true 468 case "textDocument/formatting": // req 469 var params DocumentFormattingParams 470 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 471 sendParseError(ctx, r, err) 472 return true 473 } 474 resp, err := h.server.Formatting(ctx, ¶ms) 475 if err := r.Reply(ctx, resp, err); err != nil { 476 log.Printf("%v", err) 477 } 478 return true 479 case "textDocument/rangeFormatting": // req 480 var params DocumentRangeFormattingParams 481 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 482 sendParseError(ctx, r, err) 483 return true 484 } 485 resp, err := h.server.RangeFormatting(ctx, ¶ms) 486 if err := r.Reply(ctx, resp, err); err != nil { 487 log.Printf("%v", err) 488 } 489 return true 490 case "textDocument/onTypeFormatting": // req 491 var params DocumentOnTypeFormattingParams 492 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 493 sendParseError(ctx, r, err) 494 return true 495 } 496 resp, err := h.server.OnTypeFormatting(ctx, ¶ms) 497 if err := r.Reply(ctx, resp, err); err != nil { 498 log.Printf("%v", err) 499 } 500 return true 501 case "textDocument/rename": // req 502 var params RenameParams 503 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 504 sendParseError(ctx, r, err) 505 return true 506 } 507 resp, err := h.server.Rename(ctx, ¶ms) 508 if err := r.Reply(ctx, resp, err); err != nil { 509 log.Printf("%v", err) 510 } 511 return true 512 case "textDocument/prepareRename": // req 513 var params PrepareRenameParams 514 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 515 sendParseError(ctx, r, err) 516 return true 517 } 518 resp, err := h.server.PrepareRename(ctx, ¶ms) 519 if err := r.Reply(ctx, resp, err); err != nil { 520 log.Printf("%v", err) 521 } 522 return true 523 case "workspace/executeCommand": // req 524 var params ExecuteCommandParams 525 if err := json.Unmarshal(*r.Params, ¶ms); err != nil { 526 sendParseError(ctx, r, err) 527 return true 528 } 529 resp, err := h.server.ExecuteCommand(ctx, ¶ms) 530 if err := r.Reply(ctx, resp, err); err != nil { 531 log.Printf("%v", err) 532 } 533 return true 534 535 default: 536 return false 537 } 538} 539 540type serverDispatcher struct { 541 *jsonrpc2.Conn 542} 543 544func (s *serverDispatcher) DidChangeWorkspaceFolders(ctx context.Context, params *DidChangeWorkspaceFoldersParams) error { 545 return s.Conn.Notify(ctx, "workspace/didChangeWorkspaceFolders", params) 546} 547 548func (s *serverDispatcher) Initialized(ctx context.Context, params *InitializedParams) error { 549 return s.Conn.Notify(ctx, "initialized", params) 550} 551 552func (s *serverDispatcher) Exit(ctx context.Context) error { 553 return s.Conn.Notify(ctx, "exit", nil) 554} 555 556func (s *serverDispatcher) DidChangeConfiguration(ctx context.Context, params *DidChangeConfigurationParams) error { 557 return s.Conn.Notify(ctx, "workspace/didChangeConfiguration", params) 558} 559 560func (s *serverDispatcher) DidOpen(ctx context.Context, params *DidOpenTextDocumentParams) error { 561 return s.Conn.Notify(ctx, "textDocument/didOpen", params) 562} 563 564func (s *serverDispatcher) DidChange(ctx context.Context, params *DidChangeTextDocumentParams) error { 565 return s.Conn.Notify(ctx, "textDocument/didChange", params) 566} 567 568func (s *serverDispatcher) DidClose(ctx context.Context, params *DidCloseTextDocumentParams) error { 569 return s.Conn.Notify(ctx, "textDocument/didClose", params) 570} 571 572func (s *serverDispatcher) DidSave(ctx context.Context, params *DidSaveTextDocumentParams) error { 573 return s.Conn.Notify(ctx, "textDocument/didSave", params) 574} 575 576func (s *serverDispatcher) WillSave(ctx context.Context, params *WillSaveTextDocumentParams) error { 577 return s.Conn.Notify(ctx, "textDocument/willSave", params) 578} 579 580func (s *serverDispatcher) DidChangeWatchedFiles(ctx context.Context, params *DidChangeWatchedFilesParams) error { 581 return s.Conn.Notify(ctx, "workspace/didChangeWatchedFiles", params) 582} 583 584func (s *serverDispatcher) Progress(ctx context.Context, params *ProgressParams) error { 585 return s.Conn.Notify(ctx, "$/progress", params) 586} 587 588func (s *serverDispatcher) SetTraceNotification(ctx context.Context, params *SetTraceParams) error { 589 return s.Conn.Notify(ctx, "$/setTraceNotification", params) 590} 591 592func (s *serverDispatcher) LogTraceNotification(ctx context.Context, params *LogTraceParams) error { 593 return s.Conn.Notify(ctx, "$/logTraceNotification", params) 594} 595func (s *serverDispatcher) Implementation(ctx context.Context, params *ImplementationParams) ([]Location, error) { 596 var result []Location 597 if err := s.Conn.Call(ctx, "textDocument/implementation", params, &result); err != nil { 598 return nil, err 599 } 600 return result, nil 601} 602 603func (s *serverDispatcher) TypeDefinition(ctx context.Context, params *TypeDefinitionParams) ([]Location, error) { 604 var result []Location 605 if err := s.Conn.Call(ctx, "textDocument/typeDefinition", params, &result); err != nil { 606 return nil, err 607 } 608 return result, nil 609} 610 611func (s *serverDispatcher) DocumentColor(ctx context.Context, params *DocumentColorParams) ([]ColorInformation, error) { 612 var result []ColorInformation 613 if err := s.Conn.Call(ctx, "textDocument/documentColor", params, &result); err != nil { 614 return nil, err 615 } 616 return result, nil 617} 618 619func (s *serverDispatcher) ColorPresentation(ctx context.Context, params *ColorPresentationParams) ([]ColorPresentation, error) { 620 var result []ColorPresentation 621 if err := s.Conn.Call(ctx, "textDocument/colorPresentation", params, &result); err != nil { 622 return nil, err 623 } 624 return result, nil 625} 626 627func (s *serverDispatcher) FoldingRange(ctx context.Context, params *FoldingRangeParams) ([]FoldingRange, error) { 628 var result []FoldingRange 629 if err := s.Conn.Call(ctx, "textDocument/foldingRange", params, &result); err != nil { 630 return nil, err 631 } 632 return result, nil 633} 634 635func (s *serverDispatcher) Declaration(ctx context.Context, params *DeclarationParams) ([]DeclarationLink, error) { 636 var result []DeclarationLink 637 if err := s.Conn.Call(ctx, "textDocument/declaration", params, &result); err != nil { 638 return nil, err 639 } 640 return result, nil 641} 642 643func (s *serverDispatcher) SelectionRange(ctx context.Context, params *SelectionRangeParams) ([]SelectionRange, error) { 644 var result []SelectionRange 645 if err := s.Conn.Call(ctx, "textDocument/selectionRange", params, &result); err != nil { 646 return nil, err 647 } 648 return result, nil 649} 650 651func (s *serverDispatcher) Initialize(ctx context.Context, params *ParamInitia) (*InitializeResult, error) { 652 var result InitializeResult 653 if err := s.Conn.Call(ctx, "initialize", params, &result); err != nil { 654 return nil, err 655 } 656 return &result, nil 657} 658 659func (s *serverDispatcher) Shutdown(ctx context.Context) error { 660 return s.Conn.Call(ctx, "shutdown", nil, nil) 661} 662 663func (s *serverDispatcher) WillSaveWaitUntil(ctx context.Context, params *WillSaveTextDocumentParams) ([]TextEdit, error) { 664 var result []TextEdit 665 if err := s.Conn.Call(ctx, "textDocument/willSaveWaitUntil", params, &result); err != nil { 666 return nil, err 667 } 668 return result, nil 669} 670 671func (s *serverDispatcher) Completion(ctx context.Context, params *CompletionParams) (*CompletionList, error) { 672 var result CompletionList 673 if err := s.Conn.Call(ctx, "textDocument/completion", params, &result); err != nil { 674 return nil, err 675 } 676 return &result, nil 677} 678 679func (s *serverDispatcher) Resolve(ctx context.Context, params *CompletionItem) (*CompletionItem, error) { 680 var result CompletionItem 681 if err := s.Conn.Call(ctx, "completionItem/resolve", params, &result); err != nil { 682 return nil, err 683 } 684 return &result, nil 685} 686 687func (s *serverDispatcher) Hover(ctx context.Context, params *HoverParams) (*Hover, error) { 688 var result Hover 689 if err := s.Conn.Call(ctx, "textDocument/hover", params, &result); err != nil { 690 return nil, err 691 } 692 return &result, nil 693} 694 695func (s *serverDispatcher) SignatureHelp(ctx context.Context, params *SignatureHelpParams) (*SignatureHelp, error) { 696 var result SignatureHelp 697 if err := s.Conn.Call(ctx, "textDocument/signatureHelp", params, &result); err != nil { 698 return nil, err 699 } 700 return &result, nil 701} 702 703func (s *serverDispatcher) Definition(ctx context.Context, params *DefinitionParams) ([]Location, error) { 704 var result []Location 705 if err := s.Conn.Call(ctx, "textDocument/definition", params, &result); err != nil { 706 return nil, err 707 } 708 return result, nil 709} 710 711func (s *serverDispatcher) References(ctx context.Context, params *ReferenceParams) ([]Location, error) { 712 var result []Location 713 if err := s.Conn.Call(ctx, "textDocument/references", params, &result); err != nil { 714 return nil, err 715 } 716 return result, nil 717} 718 719func (s *serverDispatcher) DocumentHighlight(ctx context.Context, params *DocumentHighlightParams) ([]DocumentHighlight, error) { 720 var result []DocumentHighlight 721 if err := s.Conn.Call(ctx, "textDocument/documentHighlight", params, &result); err != nil { 722 return nil, err 723 } 724 return result, nil 725} 726 727func (s *serverDispatcher) DocumentSymbol(ctx context.Context, params *DocumentSymbolParams) ([]DocumentSymbol, error) { 728 var result []DocumentSymbol 729 if err := s.Conn.Call(ctx, "textDocument/documentSymbol", params, &result); err != nil { 730 return nil, err 731 } 732 return result, nil 733} 734 735func (s *serverDispatcher) CodeAction(ctx context.Context, params *CodeActionParams) ([]CodeAction, error) { 736 var result []CodeAction 737 if err := s.Conn.Call(ctx, "textDocument/codeAction", params, &result); err != nil { 738 return nil, err 739 } 740 return result, nil 741} 742 743func (s *serverDispatcher) Symbol(ctx context.Context, params *WorkspaceSymbolParams) ([]SymbolInformation, error) { 744 var result []SymbolInformation 745 if err := s.Conn.Call(ctx, "workspace/symbol", params, &result); err != nil { 746 return nil, err 747 } 748 return result, nil 749} 750 751func (s *serverDispatcher) CodeLens(ctx context.Context, params *CodeLensParams) ([]CodeLens, error) { 752 var result []CodeLens 753 if err := s.Conn.Call(ctx, "textDocument/codeLens", params, &result); err != nil { 754 return nil, err 755 } 756 return result, nil 757} 758 759func (s *serverDispatcher) ResolveCodeLens(ctx context.Context, params *CodeLens) (*CodeLens, error) { 760 var result CodeLens 761 if err := s.Conn.Call(ctx, "codeLens/resolve", params, &result); err != nil { 762 return nil, err 763 } 764 return &result, nil 765} 766 767func (s *serverDispatcher) DocumentLink(ctx context.Context, params *DocumentLinkParams) ([]DocumentLink, error) { 768 var result []DocumentLink 769 if err := s.Conn.Call(ctx, "textDocument/documentLink", params, &result); err != nil { 770 return nil, err 771 } 772 return result, nil 773} 774 775func (s *serverDispatcher) ResolveDocumentLink(ctx context.Context, params *DocumentLink) (*DocumentLink, error) { 776 var result DocumentLink 777 if err := s.Conn.Call(ctx, "documentLink/resolve", params, &result); err != nil { 778 return nil, err 779 } 780 return &result, nil 781} 782 783func (s *serverDispatcher) Formatting(ctx context.Context, params *DocumentFormattingParams) ([]TextEdit, error) { 784 var result []TextEdit 785 if err := s.Conn.Call(ctx, "textDocument/formatting", params, &result); err != nil { 786 return nil, err 787 } 788 return result, nil 789} 790 791func (s *serverDispatcher) RangeFormatting(ctx context.Context, params *DocumentRangeFormattingParams) ([]TextEdit, error) { 792 var result []TextEdit 793 if err := s.Conn.Call(ctx, "textDocument/rangeFormatting", params, &result); err != nil { 794 return nil, err 795 } 796 return result, nil 797} 798 799func (s *serverDispatcher) OnTypeFormatting(ctx context.Context, params *DocumentOnTypeFormattingParams) ([]TextEdit, error) { 800 var result []TextEdit 801 if err := s.Conn.Call(ctx, "textDocument/onTypeFormatting", params, &result); err != nil { 802 return nil, err 803 } 804 return result, nil 805} 806 807func (s *serverDispatcher) Rename(ctx context.Context, params *RenameParams) (*WorkspaceEdit, error) { 808 var result WorkspaceEdit 809 if err := s.Conn.Call(ctx, "textDocument/rename", params, &result); err != nil { 810 return nil, err 811 } 812 return &result, nil 813} 814 815func (s *serverDispatcher) PrepareRename(ctx context.Context, params *PrepareRenameParams) (*Range, error) { 816 var result Range 817 if err := s.Conn.Call(ctx, "textDocument/prepareRename", params, &result); err != nil { 818 return nil, err 819 } 820 return &result, nil 821} 822 823func (s *serverDispatcher) ExecuteCommand(ctx context.Context, params *ExecuteCommandParams) (interface{}, error) { 824 var result interface{} 825 if err := s.Conn.Call(ctx, "workspace/executeCommand", params, &result); err != nil { 826 return nil, err 827 } 828 return result, nil 829} 830 831type CancelParams struct { 832 /** 833 * The request id to cancel. 834 */ 835 ID jsonrpc2.ID `json:"id"` 836} 837 838// Types constructed to avoid structs as formal argument types 839type ParamInitia struct { 840 InitializeParams 841 WorkDoneProgressParams 842} 843