internal/lsp: generate RPC interface from Typescript source

The generated code adds some server methods that are unsupported, but were
prviously unimplemented, and makes small adjusments to some parameter types.

Change-Id: I3dd32cafa3e457193f0771e0f8e150c88b381c82
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173420
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Peter Weinberger 2019-04-23 10:05:23 -04:00
parent b9fed7929f
commit 08ecc9edd9
5 changed files with 712 additions and 578 deletions

View File

@ -190,7 +190,7 @@ func (c *baseClient) LogMessage(ctx context.Context, p *protocol.LogMessageParam
} }
return nil return nil
} }
func (c *baseClient) Telemetry(ctx context.Context, t interface{}) error { return nil } func (c *baseClient) Event(ctx context.Context, t *interface{}) error { return nil }
func (c *baseClient) RegisterCapability(ctx context.Context, p *protocol.RegistrationParams) error { func (c *baseClient) RegisterCapability(ctx context.Context, p *protocol.RegistrationParams) error {
return nil return nil
} }
@ -218,8 +218,8 @@ func (c *baseClient) Configuration(ctx context.Context, p *protocol.Configuratio
} }
return results, nil return results, nil
} }
func (c *baseClient) ApplyEdit(ctx context.Context, p *protocol.ApplyWorkspaceEditParams) (bool, error) { func (c *baseClient) ApplyEdit(ctx context.Context, p *protocol.ApplyWorkspaceEditParams) (*protocol.ApplyWorkspaceEditResponse, error) {
return false, nil return &protocol.ApplyWorkspaceEditResponse{Applied: false, FailureReason: "not implemented"}, nil
} }
func (c *baseClient) PublishDiagnostics(ctx context.Context, p *protocol.PublishDiagnosticsParams) error { func (c *baseClient) PublishDiagnostics(ctx context.Context, p *protocol.PublishDiagnosticsParams) error {
return nil return nil

View File

@ -1,9 +1,7 @@
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package protocol package protocol
//automatically generated
import ( import (
"context" "context"
"encoding/json" "encoding/json"
@ -14,15 +12,15 @@ import (
type Client interface { type Client interface {
ShowMessage(context.Context, *ShowMessageParams) error ShowMessage(context.Context, *ShowMessageParams) error
ShowMessageRequest(context.Context, *ShowMessageRequestParams) (*MessageActionItem, error)
LogMessage(context.Context, *LogMessageParams) error LogMessage(context.Context, *LogMessageParams) error
Telemetry(context.Context, interface{}) error Event(context.Context, *interface{}) error
RegisterCapability(context.Context, *RegistrationParams) error PublishDiagnostics(context.Context, *PublishDiagnosticsParams) error
UnregisterCapability(context.Context, *UnregistrationParams) error
WorkspaceFolders(context.Context) ([]WorkspaceFolder, error) WorkspaceFolders(context.Context) ([]WorkspaceFolder, error)
Configuration(context.Context, *ConfigurationParams) ([]interface{}, error) Configuration(context.Context, *ConfigurationParams) ([]interface{}, error)
ApplyEdit(context.Context, *ApplyWorkspaceEditParams) (bool, error) RegisterCapability(context.Context, *RegistrationParams) error
PublishDiagnostics(context.Context, *PublishDiagnosticsParams) error UnregisterCapability(context.Context, *UnregistrationParams) error
ShowMessageRequest(context.Context, *ShowMessageRequestParams) (*MessageActionItem, error)
ApplyEdit(context.Context, *ApplyWorkspaceEditParams) (*ApplyWorkspaceEditResponse, error)
} }
func clientHandler(log xlog.Logger, client Client) jsonrpc2.Handler { func clientHandler(log xlog.Logger, client Client) jsonrpc2.Handler {
@ -35,8 +33,7 @@ func clientHandler(log xlog.Logger, client Client) jsonrpc2.Handler {
return return
} }
conn.Cancel(params.ID) conn.Cancel(params.ID)
case "window/showMessage": // notif
case "window/showMessage":
var params ShowMessageParams var params ShowMessageParams
if err := json.Unmarshal(*r.Params, &params); err != nil { if err := json.Unmarshal(*r.Params, &params); err != nil {
sendParseError(ctx, log, conn, r, err) sendParseError(ctx, log, conn, r, err)
@ -45,19 +42,7 @@ func clientHandler(log xlog.Logger, client Client) jsonrpc2.Handler {
if err := client.ShowMessage(ctx, &params); err != nil { if err := client.ShowMessage(ctx, &params); err != nil {
log.Errorf(ctx, "%v", err) log.Errorf(ctx, "%v", err)
} }
case "window/logMessage": // notif
case "window/showMessageRequest":
var params ShowMessageRequestParams
if err := json.Unmarshal(*r.Params, &params); err != nil {
sendParseError(ctx, log, conn, r, err)
return
}
resp, err := client.ShowMessageRequest(ctx, &params)
if err := conn.Reply(ctx, r, resp, err); err != nil {
log.Errorf(ctx, "%v", err)
}
case "window/logMessage":
var params LogMessageParams var params LogMessageParams
if err := json.Unmarshal(*r.Params, &params); err != nil { if err := json.Unmarshal(*r.Params, &params); err != nil {
sendParseError(ctx, log, conn, r, err) sendParseError(ctx, log, conn, r, err)
@ -66,38 +51,25 @@ func clientHandler(log xlog.Logger, client Client) jsonrpc2.Handler {
if err := client.LogMessage(ctx, &params); err != nil { if err := client.LogMessage(ctx, &params); err != nil {
log.Errorf(ctx, "%v", err) log.Errorf(ctx, "%v", err)
} }
case "telemetry/event": // notif
case "telemetry/event":
var params interface{} var params interface{}
if err := json.Unmarshal(*r.Params, &params); err != nil { if err := json.Unmarshal(*r.Params, &params); err != nil {
sendParseError(ctx, log, conn, r, err) sendParseError(ctx, log, conn, r, err)
return return
} }
if err := client.Telemetry(ctx, &params); err != nil { if err := client.Event(ctx, &params); err != nil {
log.Errorf(ctx, "%v", err) log.Errorf(ctx, "%v", err)
} }
case "textDocument/publishDiagnostics": // notif
case "client/registerCapability": var params PublishDiagnosticsParams
var params RegistrationParams
if err := json.Unmarshal(*r.Params, &params); err != nil { if err := json.Unmarshal(*r.Params, &params); err != nil {
sendParseError(ctx, log, conn, r, err) sendParseError(ctx, log, conn, r, err)
return return
} }
if err := client.RegisterCapability(ctx, &params); err != nil { if err := client.PublishDiagnostics(ctx, &params); err != nil {
log.Errorf(ctx, "%v", err) log.Errorf(ctx, "%v", err)
} }
case "workspace/workspaceFolders": // req
case "client/unregisterCapability":
var params UnregistrationParams
if err := json.Unmarshal(*r.Params, &params); err != nil {
sendParseError(ctx, log, conn, r, err)
return
}
if err := client.UnregisterCapability(ctx, &params); err != nil {
log.Errorf(ctx, "%v", err)
}
case "workspace/workspaceFolders":
if r.Params != nil { if r.Params != nil {
conn.Reply(ctx, r, nil, jsonrpc2.NewErrorf(jsonrpc2.CodeInvalidParams, "Expected no params")) conn.Reply(ctx, r, nil, jsonrpc2.NewErrorf(jsonrpc2.CodeInvalidParams, "Expected no params"))
return return
@ -106,8 +78,7 @@ func clientHandler(log xlog.Logger, client Client) jsonrpc2.Handler {
if err := conn.Reply(ctx, r, resp, err); err != nil { if err := conn.Reply(ctx, r, resp, err); err != nil {
log.Errorf(ctx, "%v", err) log.Errorf(ctx, "%v", err)
} }
case "workspace/configuration": // req
case "workspace/configuration":
var params ConfigurationParams var params ConfigurationParams
if err := json.Unmarshal(*r.Params, &params); err != nil { if err := json.Unmarshal(*r.Params, &params); err != nil {
sendParseError(ctx, log, conn, r, err) sendParseError(ctx, log, conn, r, err)
@ -117,8 +88,35 @@ func clientHandler(log xlog.Logger, client Client) jsonrpc2.Handler {
if err := conn.Reply(ctx, r, resp, err); err != nil { if err := conn.Reply(ctx, r, resp, err); err != nil {
log.Errorf(ctx, "%v", err) log.Errorf(ctx, "%v", err)
} }
case "client/registerCapability": // req
case "workspace/applyEdit": var params RegistrationParams
if err := json.Unmarshal(*r.Params, &params); err != nil {
sendParseError(ctx, log, conn, r, err)
return
}
if err := client.RegisterCapability(ctx, &params); err != nil {
log.Errorf(ctx, "%v", err)
}
case "client/unregisterCapability": // req
var params UnregistrationParams
if err := json.Unmarshal(*r.Params, &params); err != nil {
sendParseError(ctx, log, conn, r, err)
return
}
if err := client.UnregisterCapability(ctx, &params); err != nil {
log.Errorf(ctx, "%v", err)
}
case "window/showMessageRequest": // req
var params ShowMessageRequestParams
if err := json.Unmarshal(*r.Params, &params); err != nil {
sendParseError(ctx, log, conn, r, err)
return
}
resp, err := client.ShowMessageRequest(ctx, &params)
if err := conn.Reply(ctx, r, resp, err); err != nil {
log.Errorf(ctx, "%v", err)
}
case "workspace/applyEdit": // req
var params ApplyWorkspaceEditParams var params ApplyWorkspaceEditParams
if err := json.Unmarshal(*r.Params, &params); err != nil { if err := json.Unmarshal(*r.Params, &params); err != nil {
sendParseError(ctx, log, conn, r, err) sendParseError(ctx, log, conn, r, err)
@ -129,16 +127,6 @@ func clientHandler(log xlog.Logger, client Client) jsonrpc2.Handler {
log.Errorf(ctx, "%v", err) log.Errorf(ctx, "%v", err)
} }
case "textDocument/publishDiagnostics":
var params PublishDiagnosticsParams
if err := json.Unmarshal(*r.Params, &params); err != nil {
sendParseError(ctx, log, conn, r, err)
return
}
if err := client.PublishDiagnostics(ctx, &params); err != nil {
log.Errorf(ctx, "%v", err)
}
default: default:
if r.IsNotify() { if r.IsNotify() {
conn.Reply(ctx, r, nil, jsonrpc2.NewErrorf(jsonrpc2.CodeMethodNotFound, "method %q not found", r.Method)) conn.Reply(ctx, r, nil, jsonrpc2.NewErrorf(jsonrpc2.CodeMethodNotFound, "method %q not found", r.Method))
@ -151,58 +139,57 @@ type clientDispatcher struct {
*jsonrpc2.Conn *jsonrpc2.Conn
} }
func (c *clientDispatcher) ShowMessage(ctx context.Context, params *ShowMessageParams) error { func (s *clientDispatcher) ShowMessage(ctx context.Context, params *ShowMessageParams) error {
return c.Conn.Notify(ctx, "window/showMessage", params) return s.Conn.Notify(ctx, "window/showMessage", params)
} }
func (c *clientDispatcher) ShowMessageRequest(ctx context.Context, params *ShowMessageRequestParams) (*MessageActionItem, error) { 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, error) {
var result []WorkspaceFolder
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 *ConfigurationParams) ([]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.Notify(ctx, "client/registerCapability", params) // Notify? (not Call?)
}
func (s *clientDispatcher) UnregisterCapability(ctx context.Context, params *UnregistrationParams) error {
return s.Conn.Notify(ctx, "client/unregisterCapability", params) // Notify? (not Call?)
}
func (s *clientDispatcher) ShowMessageRequest(ctx context.Context, params *ShowMessageRequestParams) (*MessageActionItem, error) {
var result MessageActionItem var result MessageActionItem
if err := c.Conn.Call(ctx, "window/showMessageRequest", params, &result); err != nil { if err := s.Conn.Call(ctx, "window/showMessageRequest", params, &result); err != nil {
return nil, err return nil, err
} }
return &result, nil return &result, nil
} }
func (c *clientDispatcher) LogMessage(ctx context.Context, params *LogMessageParams) error { func (s *clientDispatcher) ApplyEdit(ctx context.Context, params *ApplyWorkspaceEditParams) (*ApplyWorkspaceEditResponse, error) {
return c.Conn.Notify(ctx, "window/logMessage", params) var result ApplyWorkspaceEditResponse
} if err := s.Conn.Call(ctx, "workspace/applyEdit", params, &result); err != nil {
func (c *clientDispatcher) Telemetry(ctx context.Context, params interface{}) error {
return c.Conn.Notify(ctx, "telemetry/event", params)
}
func (c *clientDispatcher) RegisterCapability(ctx context.Context, params *RegistrationParams) error {
return c.Conn.Notify(ctx, "client/registerCapability", params)
}
func (c *clientDispatcher) UnregisterCapability(ctx context.Context, params *UnregistrationParams) error {
return c.Conn.Notify(ctx, "client/unregisterCapability", params)
}
func (c *clientDispatcher) WorkspaceFolders(ctx context.Context) ([]WorkspaceFolder, error) {
var result []WorkspaceFolder
if err := c.Conn.Call(ctx, "workspace/workspaceFolders", nil, &result); err != nil {
return nil, err return nil, err
} }
return result, nil return &result, nil
}
func (c *clientDispatcher) Configuration(ctx context.Context, params *ConfigurationParams) ([]interface{}, error) {
var result []interface{}
if err := c.Conn.Call(ctx, "workspace/configuration", params, &result); err != nil {
return nil, err
}
return result, nil
}
func (c *clientDispatcher) ApplyEdit(ctx context.Context, params *ApplyWorkspaceEditParams) (bool, error) {
var result bool
if err := c.Conn.Call(ctx, "workspace/applyEdit", params, &result); err != nil {
return false, err
}
return result, nil
}
func (c *clientDispatcher) PublishDiagnostics(ctx context.Context, params *PublishDiagnosticsParams) error {
return c.Conn.Notify(ctx, "textDocument/publishDiagnostics", params)
} }

View File

@ -3378,6 +3378,27 @@ type TextDocumentContentChangeEvent struct {
Text string `json:"text"` Text string `json:"text"`
} }
// SetTraceParams is
type SetTraceParams struct {
// Value is
Value TraceValues `json:"value"`
}
// LogTraceParams is
type LogTraceParams struct {
// Message is
Message string `json:"message"`
// Verbose is
Verbose string `json:"verbose,omitempty"`
}
// Tracer is
type Tracer struct {
}
// FoldingRangeKind defines constants // FoldingRangeKind defines constants
type FoldingRangeKind string type FoldingRangeKind string
@ -3435,6 +3456,24 @@ type CodeActionKind string
// TextDocumentSaveReason defines constants // TextDocumentSaveReason defines constants
type TextDocumentSaveReason float64 type TextDocumentSaveReason float64
// ErrorCodes defines constants
type ErrorCodes float64
// Touch defines constants
type Touch float64
// Trace defines constants
type Trace string
// TraceFormat defines constants
type TraceFormat string
// ConnectionErrors defines constants
type ConnectionErrors float64
// ConnectionState defines constants
type ConnectionState float64
const ( const (
/*Comment defined: /*Comment defined:
@ -3890,6 +3929,42 @@ const (
* When the editor lost focus. * When the editor lost focus.
*/ */
FocusOut TextDocumentSaveReason = 3 FocusOut TextDocumentSaveReason = 3
// MessageWriteError is
MessageWriteError ErrorCodes = 1
// MessageReadError is
MessageReadError ErrorCodes = 2
// First is
First Touch = 1
// Last is
Last Touch = 2
// JSON is
JSON TraceFormat = "json"
/*Closed defined:
* The connection is closed.
*/
Closed ConnectionErrors = 1
/*Disposed defined:
* The connection got disposed.
*/
Disposed ConnectionErrors = 2
/*AlreadyListening defined:
* The connection is already in listening mode.
*/
AlreadyListening ConnectionErrors = 3
// New is
New ConnectionState = 1
// Listening is
Listening ConnectionState = 2
) )
// DocumentFilter is a type // DocumentFilter is a type
@ -3949,3 +4024,12 @@ type DefinitionLink LocationLink
* by the client. * by the client.
*/ */
type DeclarationLink LocationLink type DeclarationLink LocationLink
// LSPMessageType is a type
/**
* A LSP Log Entry.
*/
type LSPMessageType string
// TraceValues is a type
type TraceValues string

View File

@ -206,16 +206,16 @@ func (s *Server) CodeLens(context.Context, *protocol.CodeLensParams) ([]protocol
return nil, nil // ignore return nil, nil // ignore
} }
func (s *Server) CodeLensResolve(context.Context, *protocol.CodeLens) (*protocol.CodeLens, error) { func (s *Server) ResolveCodeLens(context.Context, *protocol.CodeLens) (*protocol.CodeLens, error) {
return nil, notImplemented("CodeLensResolve") return nil, notImplemented("ResolveCodeLens")
} }
func (s *Server) DocumentLink(context.Context, *protocol.DocumentLinkParams) ([]protocol.DocumentLink, error) { func (s *Server) DocumentLink(context.Context, *protocol.DocumentLinkParams) ([]protocol.DocumentLink, error) {
return nil, nil // ignore return nil, nil // ignore
} }
func (s *Server) DocumentLinkResolve(context.Context, *protocol.DocumentLink) (*protocol.DocumentLink, error) { func (s *Server) ResolveDocumentLink(context.Context, *protocol.DocumentLink) (*protocol.DocumentLink, error) {
return nil, notImplemented("DocumentLinkResolve") return nil, notImplemented("ResolveDocumentLink")
} }
func (s *Server) DocumentColor(context.Context, *protocol.DocumentColorParams) ([]protocol.ColorInformation, error) { func (s *Server) DocumentColor(context.Context, *protocol.DocumentColorParams) ([]protocol.ColorInformation, error) {
@ -238,14 +238,37 @@ func (s *Server) OnTypeFormatting(context.Context, *protocol.DocumentOnTypeForma
return nil, notImplemented("OnTypeFormatting") return nil, notImplemented("OnTypeFormatting")
} }
func (s *Server) Rename(context.Context, *protocol.RenameParams) ([]protocol.WorkspaceEdit, error) { func (s *Server) Rename(context.Context, *protocol.RenameParams) (*protocol.WorkspaceEdit, error) {
return nil, notImplemented("Rename") return nil, notImplemented("Rename")
} }
func (s *Server) Declaration(context.Context, *protocol.TextDocumentPositionParams) ([]protocol.DeclarationLink, error) {
return nil, notImplemented("Declaration")
}
func (s *Server) FoldingRange(context.Context, *protocol.FoldingRangeParams) ([]protocol.FoldingRange, error) { func (s *Server) FoldingRange(context.Context, *protocol.FoldingRangeParams) ([]protocol.FoldingRange, error) {
return nil, notImplemented("FoldingRange") return nil, notImplemented("FoldingRange")
} }
func (s *Server) LogTraceNotification(context.Context, *protocol.LogTraceParams) error {
return notImplemented("LogtraceNotification")
}
func (s *Server) PrepareRename(context.Context, *protocol.TextDocumentPositionParams) (*protocol.Range, error) {
return nil, notImplemented("PrepareRename")
}
func (s *Server) Resolve(context.Context, *protocol.CompletionItem) (*protocol.CompletionItem, error) {
return nil, notImplemented("Resolve")
}
func (s *Server) SelectionRange(context.Context, *protocol.SelectionRangeParams) ([][]protocol.SelectionRange, error) {
return nil, notImplemented("SelectionRange")
}
func (s *Server) SetTraceNotification(context.Context, *protocol.SetTraceParams) error {
return notImplemented("SetTraceNotification")
}
func notImplemented(method string) *jsonrpc2.Error { func notImplemented(method string) *jsonrpc2.Error {
return jsonrpc2.NewErrorf(jsonrpc2.CodeMethodNotFound, "method %q not yet implemented", method) return jsonrpc2.NewErrorf(jsonrpc2.CodeMethodNotFound, "method %q not yet implemented", method)
} }