mirror of
https://github.com/golang/go
synced 2024-11-19 04:34:39 -07:00
5091d647ee
Code generation has been unified, so that tsprotocol.go and tsserver.go are produced by the same program. tsprotocol.go is about 900 lines shorter, partly from removing boilerplate comments that golint no longer requires. (And partly by generating fewer unneeded types.) The choice made for a union type is commented with the set of types. There is no Go equivalent for union types, but making themn all interface{} would replace type checking at unmarshalling with checking runtime conversions. Intersection types (A&B) are sometimes embedded (struct{A;B;}, and sometimes expanded, as they have to be if A and B have fields with the same names. There are fewer embedded structs, which had been verbose and confusing to initialize. They have been replaced by types whose names end in Gn. Essentially all the generated *structs have been removed. This makes no difference in what the client sends, and the server may send a {} where it previously might have sent nothing. The benefit is that some nil tests can be removed. Thus 'omitempty' in json tags is just documentation that the element is optional in the protocol. The files that generate this code will be submitted later, but soon. Change-Id: I52b997d9c58de3d733fc8c6ce061e47ce2bdb100 Reviewed-on: https://go-review.googlesource.com/c/tools/+/207598 Run-TryBot: Peter Weinberger <pjw@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
211 lines
6.8 KiB
Go
211 lines
6.8 KiB
Go
package protocol
|
|
|
|
// Package protocol contains data types and code for LSP jsonrpcs
|
|
// generated automatically from vscode-languageserver-node
|
|
// commit: 635ab1fe6f8c57ce9402e573d007f24d6d290fd3
|
|
// last fetched Sun Oct 13 2019 10:14:32 GMT-0400 (Eastern Daylight Time)
|
|
|
|
// Code generated (see typescript/README.md) DO NOT EDIT.
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"golang.org/x/tools/internal/jsonrpc2"
|
|
"golang.org/x/tools/internal/telemetry/log"
|
|
"golang.org/x/tools/internal/xcontext"
|
|
)
|
|
|
|
type Client interface {
|
|
ShowMessage(context.Context, *ShowMessageParams) error
|
|
LogMessage(context.Context, *LogMessageParams) error
|
|
Event(context.Context, *interface{}) error
|
|
PublishDiagnostics(context.Context, *PublishDiagnosticsParams) error
|
|
WorkspaceFolders(context.Context) ([]WorkspaceFolder /*WorkspaceFolder[] | null*/, error)
|
|
Configuration(context.Context, *ParamConfiguration) ([]interface{}, error)
|
|
RegisterCapability(context.Context, *RegistrationParams) error
|
|
UnregisterCapability(context.Context, *UnregistrationParams) error
|
|
ShowMessageRequest(context.Context, *ShowMessageRequestParams) (*MessageActionItem /*MessageActionItem | null*/, error)
|
|
ApplyEdit(context.Context, *ApplyWorkspaceEditParams) (*ApplyWorkspaceEditResponse, error)
|
|
}
|
|
|
|
func (h clientHandler) Deliver(ctx context.Context, r *jsonrpc2.Request, delivered bool) bool {
|
|
if delivered {
|
|
return false
|
|
}
|
|
if ctx.Err() != nil {
|
|
ctx := xcontext.Detach(ctx)
|
|
r.Reply(ctx, nil, jsonrpc2.NewErrorf(RequestCancelledError, ""))
|
|
return true
|
|
}
|
|
switch r.Method {
|
|
case "window/showMessage": // notif
|
|
var params ShowMessageParams
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
|
sendParseError(ctx, r, err)
|
|
return true
|
|
}
|
|
if err := h.client.ShowMessage(ctx, ¶ms); err != nil {
|
|
log.Error(ctx, "", err)
|
|
}
|
|
return true
|
|
case "window/logMessage": // notif
|
|
var params LogMessageParams
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
|
sendParseError(ctx, r, err)
|
|
return true
|
|
}
|
|
if err := h.client.LogMessage(ctx, ¶ms); err != nil {
|
|
log.Error(ctx, "", err)
|
|
}
|
|
return true
|
|
case "telemetry/event": // notif
|
|
var params interface{}
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
|
sendParseError(ctx, r, err)
|
|
return true
|
|
}
|
|
if err := h.client.Event(ctx, ¶ms); err != nil {
|
|
log.Error(ctx, "", err)
|
|
}
|
|
return true
|
|
case "textDocument/publishDiagnostics": // notif
|
|
var params PublishDiagnosticsParams
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
|
sendParseError(ctx, r, err)
|
|
return true
|
|
}
|
|
if err := h.client.PublishDiagnostics(ctx, ¶ms); err != nil {
|
|
log.Error(ctx, "", err)
|
|
}
|
|
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 {
|
|
log.Error(ctx, "", err)
|
|
}
|
|
return true
|
|
case "workspace/configuration": // req
|
|
var params ParamConfiguration
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
|
sendParseError(ctx, r, err)
|
|
return true
|
|
}
|
|
resp, err := h.client.Configuration(ctx, ¶ms)
|
|
if err := r.Reply(ctx, resp, err); err != nil {
|
|
log.Error(ctx, "", err)
|
|
}
|
|
return true
|
|
case "client/registerCapability": // req
|
|
var params RegistrationParams
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
|
sendParseError(ctx, r, err)
|
|
return true
|
|
}
|
|
err := h.client.RegisterCapability(ctx, ¶ms)
|
|
if err := r.Reply(ctx, nil, err); err != nil {
|
|
log.Error(ctx, "", err)
|
|
}
|
|
return true
|
|
case "client/unregisterCapability": // req
|
|
var params UnregistrationParams
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
|
sendParseError(ctx, r, err)
|
|
return true
|
|
}
|
|
err := h.client.UnregisterCapability(ctx, ¶ms)
|
|
if err := r.Reply(ctx, nil, err); err != nil {
|
|
log.Error(ctx, "", err)
|
|
}
|
|
return true
|
|
case "window/showMessageRequest": // req
|
|
var params ShowMessageRequestParams
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
|
sendParseError(ctx, r, err)
|
|
return true
|
|
}
|
|
resp, err := h.client.ShowMessageRequest(ctx, ¶ms)
|
|
if err := r.Reply(ctx, resp, err); err != nil {
|
|
log.Error(ctx, "", err)
|
|
}
|
|
return true
|
|
case "workspace/applyEdit": // req
|
|
var params ApplyWorkspaceEditParams
|
|
if err := json.Unmarshal(*r.Params, ¶ms); err != nil {
|
|
sendParseError(ctx, r, err)
|
|
return true
|
|
}
|
|
resp, err := h.client.ApplyEdit(ctx, ¶ms)
|
|
if err := r.Reply(ctx, resp, err); err != nil {
|
|
log.Error(ctx, "", err)
|
|
}
|
|
return true
|
|
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
type clientDispatcher struct {
|
|
*jsonrpc2.Conn
|
|
}
|
|
|
|
func (s *clientDispatcher) ShowMessage(ctx context.Context, params *ShowMessageParams) error {
|
|
return s.Conn.Notify(ctx, "window/showMessage", params)
|
|
}
|
|
|
|
func (s *clientDispatcher) LogMessage(ctx context.Context, params *LogMessageParams) error {
|
|
return s.Conn.Notify(ctx, "window/logMessage", params)
|
|
}
|
|
|
|
func (s *clientDispatcher) Event(ctx context.Context, params *interface{}) error {
|
|
return s.Conn.Notify(ctx, "telemetry/event", params)
|
|
}
|
|
|
|
func (s *clientDispatcher) PublishDiagnostics(ctx context.Context, params *PublishDiagnosticsParams) error {
|
|
return s.Conn.Notify(ctx, "textDocument/publishDiagnostics", params)
|
|
}
|
|
func (s *clientDispatcher) WorkspaceFolders(ctx context.Context) ([]WorkspaceFolder /*WorkspaceFolder[] | null*/, error) {
|
|
var result []WorkspaceFolder /*WorkspaceFolder[] | null*/
|
|
if err := s.Conn.Call(ctx, "workspace/workspaceFolders", nil, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (s *clientDispatcher) Configuration(ctx context.Context, params *ParamConfiguration) ([]interface{}, error) {
|
|
var result []interface{}
|
|
if err := s.Conn.Call(ctx, "workspace/configuration", params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (s *clientDispatcher) RegisterCapability(ctx context.Context, params *RegistrationParams) error {
|
|
return s.Conn.Call(ctx, "client/registerCapability", params, nil) // Call, not Notify
|
|
}
|
|
|
|
func (s *clientDispatcher) UnregisterCapability(ctx context.Context, params *UnregistrationParams) error {
|
|
return s.Conn.Call(ctx, "client/unregisterCapability", params, nil) // Call, not Notify
|
|
}
|
|
|
|
func (s *clientDispatcher) ShowMessageRequest(ctx context.Context, params *ShowMessageRequestParams) (*MessageActionItem /*MessageActionItem | null*/, error) {
|
|
var result MessageActionItem /*MessageActionItem | null*/
|
|
if err := s.Conn.Call(ctx, "window/showMessageRequest", params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
func (s *clientDispatcher) ApplyEdit(ctx context.Context, params *ApplyWorkspaceEditParams) (*ApplyWorkspaceEditResponse, error) {
|
|
var result ApplyWorkspaceEditResponse
|
|
if err := s.Conn.Call(ctx, "workspace/applyEdit", params, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|