mirror of https://github.com/golang/go.git
internal/lsp: remove the CallCanceller
This required changing the jsonrpc.Conn.Call signature to also return the request ID so it can be cancelled. The protocol package now declares the Call function which wrapps up Conn.Call and then sends a cancel message if the context was cancelled during the call. There is a small chance that a context can be cancelled on a request that has already completed, but it is safe to do so. Change-Id: Ic8040c193e1dd4ef376ad21194b1d0ea82145976 Reviewed-on: https://go-review.googlesource.com/c/tools/+/227558 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
c92aeb7438
commit
ae9902aceb
|
|
@ -37,9 +37,9 @@ func MustReply(handler Handler) Handler {
|
|||
}
|
||||
}
|
||||
|
||||
// CancelHandler returns a handler that supports cancellation, and a canceller
|
||||
// CancelHandler returns a handler that supports cancellation, and a function
|
||||
// that can be used to trigger canceling in progress requests.
|
||||
func CancelHandler(handler Handler) (Handler, Canceller) {
|
||||
func CancelHandler(handler Handler) (Handler, func(id ID)) {
|
||||
var mu sync.Mutex
|
||||
handling := make(map[ID]context.CancelFunc)
|
||||
wrapped := func(ctx context.Context, req *Request) error {
|
||||
|
|
|
|||
|
|
@ -29,11 +29,10 @@ const (
|
|||
// Conn is a JSON RPC 2 client server connection.
|
||||
// Conn is bidirectional; it does not have a designated server or client end.
|
||||
type Conn struct {
|
||||
seq int64 // must only be accessed using atomic operations
|
||||
stream Stream
|
||||
pendingMu sync.Mutex // protects the pending map
|
||||
pending map[ID]chan *WireResponse
|
||||
onCancelled CallCanceller
|
||||
seq int64 // must only be accessed using atomic operations
|
||||
stream Stream
|
||||
pendingMu sync.Mutex // protects the pending map
|
||||
pending map[ID]chan *WireResponse
|
||||
}
|
||||
|
||||
// Request is sent to a server to represent a Call or Notify operaton.
|
||||
|
|
@ -47,13 +46,6 @@ type Request struct {
|
|||
WireRequest
|
||||
}
|
||||
|
||||
// Canceller is the type for a function that can cancel an in progress request.
|
||||
type Canceller func(id ID)
|
||||
|
||||
// CallCanceller is the type for a callback when an outgoing request is
|
||||
// has it's context cancelled.
|
||||
type CallCanceller func(context.Context, *Conn, ID)
|
||||
|
||||
type constError string
|
||||
|
||||
func (e constError) Error() string { return string(e) }
|
||||
|
|
@ -77,13 +69,6 @@ func NewConn(s Stream) *Conn {
|
|||
return conn
|
||||
}
|
||||
|
||||
// OnCancelled sets the callback used when an outgoing call request has
|
||||
// it's context cancelled when still in progress.
|
||||
// Only the last callback registered is used.
|
||||
func (c *Conn) OnCancelled(cancelled CallCanceller) {
|
||||
c.onCancelled = cancelled
|
||||
}
|
||||
|
||||
// Notify is called to send a notification request over the connection.
|
||||
// It will return as soon as the notification has been sent, as no response is
|
||||
// possible.
|
||||
|
|
@ -119,12 +104,12 @@ func (c *Conn) Notify(ctx context.Context, method string, params interface{}) (e
|
|||
// Call sends a request over the connection and then waits for a response.
|
||||
// If the response is not an error, it will be decoded into result.
|
||||
// result must be of a type you an pass to json.Unmarshal.
|
||||
func (c *Conn) Call(ctx context.Context, method string, params, result interface{}) (err error) {
|
||||
func (c *Conn) Call(ctx context.Context, method string, params, result interface{}) (_ ID, err error) {
|
||||
// generate a new request identifier
|
||||
id := ID{Number: atomic.AddInt64(&c.seq, 1)}
|
||||
jsonParams, err := marshalToRaw(params)
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshalling call parameters: %v", err)
|
||||
return id, fmt.Errorf("marshalling call parameters: %v", err)
|
||||
}
|
||||
request := &WireRequest{
|
||||
ID: &id,
|
||||
|
|
@ -134,7 +119,7 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface
|
|||
// marshal the request now it is complete
|
||||
data, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshalling call request: %v", err)
|
||||
return id, fmt.Errorf("marshalling call request: %v", err)
|
||||
}
|
||||
ctx, done := event.StartSpan(ctx, request.Method,
|
||||
tag.Method.Of(request.Method),
|
||||
|
|
@ -164,28 +149,24 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface
|
|||
event.Record(ctx, tag.SentBytes.Of(n))
|
||||
if err != nil {
|
||||
// sending failed, we will never get a response, so don't leave it pending
|
||||
return err
|
||||
return id, err
|
||||
}
|
||||
// now wait for the response
|
||||
select {
|
||||
case response := <-rchan:
|
||||
// is it an error response?
|
||||
if response.Error != nil {
|
||||
return response.Error
|
||||
return id, response.Error
|
||||
}
|
||||
if result == nil || response.Result == nil {
|
||||
return nil
|
||||
return id, nil
|
||||
}
|
||||
if err := json.Unmarshal(*response.Result, result); err != nil {
|
||||
return fmt.Errorf("unmarshalling result: %v", err)
|
||||
return id, fmt.Errorf("unmarshalling result: %v", err)
|
||||
}
|
||||
return nil
|
||||
return id, nil
|
||||
case <-ctx.Done():
|
||||
// Allow the handler to propagate the cancel.
|
||||
if c.onCancelled != nil {
|
||||
c.onCancelled(ctx, c, id)
|
||||
}
|
||||
return ctx.Err()
|
||||
return id, ctx.Err()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,11 +63,11 @@ func TestPlainCall(t *testing.T) {
|
|||
a, b := prepare(ctx, t, false)
|
||||
for _, test := range callTests {
|
||||
results := test.newResults()
|
||||
if err := a.Call(ctx, test.method, test.params, results); err != nil {
|
||||
if _, err := a.Call(ctx, test.method, test.params, results); err != nil {
|
||||
t.Fatalf("%v:Call failed: %v", test.method, err)
|
||||
}
|
||||
test.verifyResults(t, results)
|
||||
if err := b.Call(ctx, test.method, test.params, results); err != nil {
|
||||
if _, err := b.Call(ctx, test.method, test.params, results); err != nil {
|
||||
t.Fatalf("%v:Call failed: %v", test.method, err)
|
||||
}
|
||||
test.verifyResults(t, results)
|
||||
|
|
@ -79,11 +79,11 @@ func TestHeaderCall(t *testing.T) {
|
|||
a, b := prepare(ctx, t, true)
|
||||
for _, test := range callTests {
|
||||
results := test.newResults()
|
||||
if err := a.Call(ctx, test.method, test.params, results); err != nil {
|
||||
if _, err := a.Call(ctx, test.method, test.params, results); err != nil {
|
||||
t.Fatalf("%v:Call failed: %v", test.method, err)
|
||||
}
|
||||
test.verifyResults(t, results)
|
||||
if err := b.Call(ctx, test.method, test.params, results); err != nil {
|
||||
if _, err := b.Call(ctx, test.method, test.params, results); err != nil {
|
||||
t.Fatalf("%v:Call failed: %v", test.method, err)
|
||||
}
|
||||
test.verifyResults(t, results)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ func TestTestServer(t *testing.T) {
|
|||
conn := test.connector.Connect(ctx)
|
||||
go conn.Run(ctx, jsonrpc2.MethodNotFound)
|
||||
var got msg
|
||||
if err := conn.Call(ctx, "ping", &msg{"ping"}, &got); err != nil {
|
||||
if _, err := conn.Call(ctx, "ping", &msg{"ping"}, &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want := "pong"; got.Msg != want {
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ func QueryServerState(ctx context.Context, network, address string) (*ServerStat
|
|||
serverConn := jsonrpc2.NewConn(jsonrpc2.NewHeaderStream(netConn, netConn))
|
||||
go serverConn.Run(ctx, jsonrpc2.MethodNotFound)
|
||||
var state ServerState
|
||||
if err := serverConn.Call(ctx, sessionsMethod, nil, &state); err != nil {
|
||||
if err := protocol.Call(ctx, serverConn, sessionsMethod, nil, &state); err != nil {
|
||||
return nil, fmt.Errorf("querying server state: %v", err)
|
||||
}
|
||||
return &state, nil
|
||||
|
|
@ -281,7 +281,7 @@ func (f *Forwarder) ServeStream(ctx context.Context, stream jsonrpc2.Stream) err
|
|||
hreq.Logfile = di.Logfile
|
||||
hreq.DebugAddr = di.ListenedDebugAddress
|
||||
}
|
||||
if err := serverConn.Call(ctx, handshakeMethod, hreq, &hresp); err != nil {
|
||||
if err := protocol.Call(ctx, serverConn, handshakeMethod, hreq, &hresp); err != nil {
|
||||
event.Error(ctx, "forwarder: gopls handshake failed", err)
|
||||
}
|
||||
if hresp.GoplsPath != f.goplsPath {
|
||||
|
|
|
|||
|
|
@ -22,14 +22,12 @@ const (
|
|||
// ClientDispatcher returns a Client that dispatches LSP requests across the
|
||||
// given jsonrpc2 connection.
|
||||
func ClientDispatcher(conn *jsonrpc2.Conn) Client {
|
||||
conn.OnCancelled(cancelCall)
|
||||
return &clientDispatcher{Conn: conn}
|
||||
}
|
||||
|
||||
// ServerDispatcher returns a Server that dispatches LSP requests across the
|
||||
// given jsonrpc2 connection.
|
||||
func ServerDispatcher(conn *jsonrpc2.Conn) Server {
|
||||
conn.OnCancelled(cancelCall)
|
||||
return &serverDispatcher{Conn: conn}
|
||||
}
|
||||
|
||||
|
|
@ -63,6 +61,14 @@ func CancelHandler(handler jsonrpc2.Handler) jsonrpc2.Handler {
|
|||
}
|
||||
}
|
||||
|
||||
func Call(ctx context.Context, conn *jsonrpc2.Conn, method string, params interface{}, result interface{}) error {
|
||||
id, err := conn.Call(ctx, method, params, result)
|
||||
if ctx.Err() != nil {
|
||||
cancelCall(ctx, conn, id)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func cancelCall(ctx context.Context, conn *jsonrpc2.Conn, id jsonrpc2.ID) {
|
||||
ctx = xcontext.Detach(ctx)
|
||||
ctx, done := event.StartSpan(ctx, "protocol.canceller")
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ func (s *clientDispatcher) Progress(ctx context.Context, params *ProgressParams)
|
|||
}
|
||||
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 {
|
||||
if err := Call(ctx, s.Conn, "workspace/workspaceFolders", nil, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -160,27 +160,27 @@ func (s *clientDispatcher) WorkspaceFolders(ctx context.Context) ([]WorkspaceFol
|
|||
|
||||
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 {
|
||||
if err := Call(ctx, s.Conn, "workspace/configuration", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *clientDispatcher) WorkDoneProgressCreate(ctx context.Context, params *WorkDoneProgressCreateParams) error {
|
||||
return s.Conn.Call(ctx, "window/workDoneProgress/create", params, nil) // Call, not Notify
|
||||
return Call(ctx, s.Conn, "window/workDoneProgress/create", params, nil) // Call, not Notify
|
||||
}
|
||||
|
||||
func (s *clientDispatcher) RegisterCapability(ctx context.Context, params *RegistrationParams) error {
|
||||
return s.Conn.Call(ctx, "client/registerCapability", params, nil) // Call, not Notify
|
||||
return Call(ctx, s.Conn, "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
|
||||
return Call(ctx, s.Conn, "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 {
|
||||
if err := Call(ctx, s.Conn, "window/showMessageRequest", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -188,7 +188,7 @@ func (s *clientDispatcher) ShowMessageRequest(ctx context.Context, params *ShowM
|
|||
|
||||
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 {
|
||||
if err := Call(ctx, s.Conn, "workspace/applyEdit", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
|
|||
|
|
@ -481,7 +481,7 @@ func (s *serverDispatcher) LogTraceNotification(ctx context.Context, params *Log
|
|||
}
|
||||
func (s *serverDispatcher) Implementation(ctx context.Context, params *ImplementationParams) (Definition /*Definition | DefinitionLink[] | null*/, error) {
|
||||
var result Definition /*Definition | DefinitionLink[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/implementation", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/implementation", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -489,7 +489,7 @@ func (s *serverDispatcher) Implementation(ctx context.Context, params *Implement
|
|||
|
||||
func (s *serverDispatcher) TypeDefinition(ctx context.Context, params *TypeDefinitionParams) (Definition /*Definition | DefinitionLink[] | null*/, error) {
|
||||
var result Definition /*Definition | DefinitionLink[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/typeDefinition", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/typeDefinition", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -497,7 +497,7 @@ func (s *serverDispatcher) TypeDefinition(ctx context.Context, params *TypeDefin
|
|||
|
||||
func (s *serverDispatcher) DocumentColor(ctx context.Context, params *DocumentColorParams) ([]ColorInformation, error) {
|
||||
var result []ColorInformation
|
||||
if err := s.Conn.Call(ctx, "textDocument/documentColor", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/documentColor", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -505,7 +505,7 @@ func (s *serverDispatcher) DocumentColor(ctx context.Context, params *DocumentCo
|
|||
|
||||
func (s *serverDispatcher) ColorPresentation(ctx context.Context, params *ColorPresentationParams) ([]ColorPresentation, error) {
|
||||
var result []ColorPresentation
|
||||
if err := s.Conn.Call(ctx, "textDocument/colorPresentation", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/colorPresentation", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -513,7 +513,7 @@ func (s *serverDispatcher) ColorPresentation(ctx context.Context, params *ColorP
|
|||
|
||||
func (s *serverDispatcher) FoldingRange(ctx context.Context, params *FoldingRangeParams) ([]FoldingRange /*FoldingRange[] | null*/, error) {
|
||||
var result []FoldingRange /*FoldingRange[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/foldingRange", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/foldingRange", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -521,7 +521,7 @@ func (s *serverDispatcher) FoldingRange(ctx context.Context, params *FoldingRang
|
|||
|
||||
func (s *serverDispatcher) Declaration(ctx context.Context, params *DeclarationParams) (Declaration /*Declaration | DeclarationLink[] | null*/, error) {
|
||||
var result Declaration /*Declaration | DeclarationLink[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/declaration", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/declaration", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -529,7 +529,7 @@ func (s *serverDispatcher) Declaration(ctx context.Context, params *DeclarationP
|
|||
|
||||
func (s *serverDispatcher) SelectionRange(ctx context.Context, params *SelectionRangeParams) ([]SelectionRange /*SelectionRange[] | null*/, error) {
|
||||
var result []SelectionRange /*SelectionRange[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/selectionRange", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/selectionRange", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -537,19 +537,19 @@ func (s *serverDispatcher) SelectionRange(ctx context.Context, params *Selection
|
|||
|
||||
func (s *serverDispatcher) Initialize(ctx context.Context, params *ParamInitialize) (*InitializeResult, error) {
|
||||
var result *InitializeResult
|
||||
if err := s.Conn.Call(ctx, "initialize", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "initialize", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) Shutdown(ctx context.Context) error {
|
||||
return s.Conn.Call(ctx, "shutdown", nil, nil)
|
||||
return Call(ctx, s.Conn, "shutdown", nil, nil)
|
||||
}
|
||||
|
||||
func (s *serverDispatcher) WillSaveWaitUntil(ctx context.Context, params *WillSaveTextDocumentParams) ([]TextEdit /*TextEdit[] | null*/, error) {
|
||||
var result []TextEdit /*TextEdit[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/willSaveWaitUntil", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/willSaveWaitUntil", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -557,7 +557,7 @@ func (s *serverDispatcher) WillSaveWaitUntil(ctx context.Context, params *WillSa
|
|||
|
||||
func (s *serverDispatcher) Completion(ctx context.Context, params *CompletionParams) (*CompletionList /*CompletionItem[] | CompletionList | null*/, error) {
|
||||
var result *CompletionList /*CompletionItem[] | CompletionList | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/completion", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/completion", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -565,7 +565,7 @@ func (s *serverDispatcher) Completion(ctx context.Context, params *CompletionPar
|
|||
|
||||
func (s *serverDispatcher) Resolve(ctx context.Context, params *CompletionItem) (*CompletionItem, error) {
|
||||
var result *CompletionItem
|
||||
if err := s.Conn.Call(ctx, "completionItem/resolve", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "completionItem/resolve", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -573,7 +573,7 @@ func (s *serverDispatcher) Resolve(ctx context.Context, params *CompletionItem)
|
|||
|
||||
func (s *serverDispatcher) Hover(ctx context.Context, params *HoverParams) (*Hover /*Hover | null*/, error) {
|
||||
var result *Hover /*Hover | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/hover", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/hover", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -581,7 +581,7 @@ func (s *serverDispatcher) Hover(ctx context.Context, params *HoverParams) (*Hov
|
|||
|
||||
func (s *serverDispatcher) SignatureHelp(ctx context.Context, params *SignatureHelpParams) (*SignatureHelp /*SignatureHelp | null*/, error) {
|
||||
var result *SignatureHelp /*SignatureHelp | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/signatureHelp", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/signatureHelp", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -589,7 +589,7 @@ func (s *serverDispatcher) SignatureHelp(ctx context.Context, params *SignatureH
|
|||
|
||||
func (s *serverDispatcher) Definition(ctx context.Context, params *DefinitionParams) (Definition /*Definition | DefinitionLink[] | null*/, error) {
|
||||
var result Definition /*Definition | DefinitionLink[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/definition", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/definition", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -597,7 +597,7 @@ func (s *serverDispatcher) Definition(ctx context.Context, params *DefinitionPar
|
|||
|
||||
func (s *serverDispatcher) References(ctx context.Context, params *ReferenceParams) ([]Location /*Location[] | null*/, error) {
|
||||
var result []Location /*Location[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/references", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/references", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -605,7 +605,7 @@ func (s *serverDispatcher) References(ctx context.Context, params *ReferencePara
|
|||
|
||||
func (s *serverDispatcher) DocumentHighlight(ctx context.Context, params *DocumentHighlightParams) ([]DocumentHighlight /*DocumentHighlight[] | null*/, error) {
|
||||
var result []DocumentHighlight /*DocumentHighlight[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/documentHighlight", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/documentHighlight", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -613,7 +613,7 @@ func (s *serverDispatcher) DocumentHighlight(ctx context.Context, params *Docume
|
|||
|
||||
func (s *serverDispatcher) DocumentSymbol(ctx context.Context, params *DocumentSymbolParams) ([]interface{} /*SymbolInformation[] | DocumentSymbol[] | null*/, error) {
|
||||
var result []interface{} /*SymbolInformation[] | DocumentSymbol[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/documentSymbol", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/documentSymbol", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -621,7 +621,7 @@ func (s *serverDispatcher) DocumentSymbol(ctx context.Context, params *DocumentS
|
|||
|
||||
func (s *serverDispatcher) CodeAction(ctx context.Context, params *CodeActionParams) ([]CodeAction /*(Command | CodeAction)[] | null*/, error) {
|
||||
var result []CodeAction /*(Command | CodeAction)[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/codeAction", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/codeAction", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -629,7 +629,7 @@ func (s *serverDispatcher) CodeAction(ctx context.Context, params *CodeActionPar
|
|||
|
||||
func (s *serverDispatcher) Symbol(ctx context.Context, params *WorkspaceSymbolParams) ([]SymbolInformation /*SymbolInformation[] | null*/, error) {
|
||||
var result []SymbolInformation /*SymbolInformation[] | null*/
|
||||
if err := s.Conn.Call(ctx, "workspace/symbol", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "workspace/symbol", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -637,7 +637,7 @@ func (s *serverDispatcher) Symbol(ctx context.Context, params *WorkspaceSymbolPa
|
|||
|
||||
func (s *serverDispatcher) CodeLens(ctx context.Context, params *CodeLensParams) ([]CodeLens /*CodeLens[] | null*/, error) {
|
||||
var result []CodeLens /*CodeLens[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/codeLens", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/codeLens", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -645,7 +645,7 @@ func (s *serverDispatcher) CodeLens(ctx context.Context, params *CodeLensParams)
|
|||
|
||||
func (s *serverDispatcher) ResolveCodeLens(ctx context.Context, params *CodeLens) (*CodeLens, error) {
|
||||
var result *CodeLens
|
||||
if err := s.Conn.Call(ctx, "codeLens/resolve", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "codeLens/resolve", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -653,7 +653,7 @@ func (s *serverDispatcher) ResolveCodeLens(ctx context.Context, params *CodeLens
|
|||
|
||||
func (s *serverDispatcher) DocumentLink(ctx context.Context, params *DocumentLinkParams) ([]DocumentLink /*DocumentLink[] | null*/, error) {
|
||||
var result []DocumentLink /*DocumentLink[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/documentLink", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/documentLink", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -661,7 +661,7 @@ func (s *serverDispatcher) DocumentLink(ctx context.Context, params *DocumentLin
|
|||
|
||||
func (s *serverDispatcher) ResolveDocumentLink(ctx context.Context, params *DocumentLink) (*DocumentLink, error) {
|
||||
var result *DocumentLink
|
||||
if err := s.Conn.Call(ctx, "documentLink/resolve", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "documentLink/resolve", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -669,7 +669,7 @@ func (s *serverDispatcher) ResolveDocumentLink(ctx context.Context, params *Docu
|
|||
|
||||
func (s *serverDispatcher) Formatting(ctx context.Context, params *DocumentFormattingParams) ([]TextEdit /*TextEdit[] | null*/, error) {
|
||||
var result []TextEdit /*TextEdit[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/formatting", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/formatting", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -677,7 +677,7 @@ func (s *serverDispatcher) Formatting(ctx context.Context, params *DocumentForma
|
|||
|
||||
func (s *serverDispatcher) RangeFormatting(ctx context.Context, params *DocumentRangeFormattingParams) ([]TextEdit /*TextEdit[] | null*/, error) {
|
||||
var result []TextEdit /*TextEdit[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/rangeFormatting", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/rangeFormatting", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -685,7 +685,7 @@ func (s *serverDispatcher) RangeFormatting(ctx context.Context, params *Document
|
|||
|
||||
func (s *serverDispatcher) OnTypeFormatting(ctx context.Context, params *DocumentOnTypeFormattingParams) ([]TextEdit /*TextEdit[] | null*/, error) {
|
||||
var result []TextEdit /*TextEdit[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/onTypeFormatting", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/onTypeFormatting", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -693,7 +693,7 @@ func (s *serverDispatcher) OnTypeFormatting(ctx context.Context, params *Documen
|
|||
|
||||
func (s *serverDispatcher) Rename(ctx context.Context, params *RenameParams) (*WorkspaceEdit /*WorkspaceEdit | null*/, error) {
|
||||
var result *WorkspaceEdit /*WorkspaceEdit | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/rename", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/rename", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -701,7 +701,7 @@ func (s *serverDispatcher) Rename(ctx context.Context, params *RenameParams) (*W
|
|||
|
||||
func (s *serverDispatcher) PrepareRename(ctx context.Context, params *PrepareRenameParams) (*Range /*Range | { range: Range, placeholder: string } | null*/, error) {
|
||||
var result *Range /*Range | { range: Range, placeholder: string } | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/prepareRename", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/prepareRename", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -709,7 +709,7 @@ func (s *serverDispatcher) PrepareRename(ctx context.Context, params *PrepareRen
|
|||
|
||||
func (s *serverDispatcher) ExecuteCommand(ctx context.Context, params *ExecuteCommandParams) (interface{} /*any | null*/, error) {
|
||||
var result interface{} /*any | null*/
|
||||
if err := s.Conn.Call(ctx, "workspace/executeCommand", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "workspace/executeCommand", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -717,7 +717,7 @@ func (s *serverDispatcher) ExecuteCommand(ctx context.Context, params *ExecuteCo
|
|||
|
||||
func (s *serverDispatcher) PrepareCallHierarchy(ctx context.Context, params *CallHierarchyPrepareParams) ([]CallHierarchyItem /*CallHierarchyItem[] | null*/, error) {
|
||||
var result []CallHierarchyItem /*CallHierarchyItem[] | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/prepareCallHierarchy", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/prepareCallHierarchy", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -725,7 +725,7 @@ func (s *serverDispatcher) PrepareCallHierarchy(ctx context.Context, params *Cal
|
|||
|
||||
func (s *serverDispatcher) IncomingCalls(ctx context.Context, params *CallHierarchyIncomingCallsParams) ([]CallHierarchyIncomingCall /*CallHierarchyIncomingCall[] | null*/, error) {
|
||||
var result []CallHierarchyIncomingCall /*CallHierarchyIncomingCall[] | null*/
|
||||
if err := s.Conn.Call(ctx, "callHierarchy/incomingCalls", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "callHierarchy/incomingCalls", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -733,7 +733,7 @@ func (s *serverDispatcher) IncomingCalls(ctx context.Context, params *CallHierar
|
|||
|
||||
func (s *serverDispatcher) OutgoingCalls(ctx context.Context, params *CallHierarchyOutgoingCallsParams) ([]CallHierarchyOutgoingCall /*CallHierarchyOutgoingCall[] | null*/, error) {
|
||||
var result []CallHierarchyOutgoingCall /*CallHierarchyOutgoingCall[] | null*/
|
||||
if err := s.Conn.Call(ctx, "callHierarchy/outgoingCalls", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "callHierarchy/outgoingCalls", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -741,7 +741,7 @@ func (s *serverDispatcher) OutgoingCalls(ctx context.Context, params *CallHierar
|
|||
|
||||
func (s *serverDispatcher) SemanticTokens(ctx context.Context, params *SemanticTokensParams) (*SemanticTokens /*SemanticTokens | null*/, error) {
|
||||
var result *SemanticTokens /*SemanticTokens | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/semanticTokens", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/semanticTokens", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -749,7 +749,7 @@ func (s *serverDispatcher) SemanticTokens(ctx context.Context, params *SemanticT
|
|||
|
||||
func (s *serverDispatcher) SemanticTokensEdits(ctx context.Context, params *SemanticTokensEditsParams) (interface{} /* SemanticTokens | SemanticTokensEdits | nil*/, error) {
|
||||
var result interface{} /* SemanticTokens | SemanticTokensEdits | nil*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/semanticTokens/edits", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/semanticTokens/edits", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -757,7 +757,7 @@ func (s *serverDispatcher) SemanticTokensEdits(ctx context.Context, params *Sema
|
|||
|
||||
func (s *serverDispatcher) SemanticTokensRange(ctx context.Context, params *SemanticTokensRangeParams) (*SemanticTokens /*SemanticTokens | null*/, error) {
|
||||
var result *SemanticTokens /*SemanticTokens | null*/
|
||||
if err := s.Conn.Call(ctx, "textDocument/semanticTokens/range", params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, "textDocument/semanticTokens/range", params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
@ -765,7 +765,7 @@ func (s *serverDispatcher) SemanticTokensRange(ctx context.Context, params *Sema
|
|||
|
||||
func (s *serverDispatcher) NonstandardRequest(ctx context.Context, method string, params interface{}) (interface{}, error) {
|
||||
var result interface{}
|
||||
if err := s.Conn.Call(ctx, method, params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, method, params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
|
|||
|
|
@ -977,19 +977,19 @@ function goReq(side: side, m: string) {
|
|||
side.cases.push(`${caseHdr}\n${case1}\n${case2}`);
|
||||
|
||||
const callHdr = `func (s *${side.name}Dispatcher) ${sig(nm, a, b, true)} {`;
|
||||
let callBody = `return s.Conn.Call(ctx, "${m}", nil, nil)\n}`;
|
||||
let callBody = `return Call(ctx, s.Conn, "${m}", nil, nil)\n}`;
|
||||
if (b != '' && b != 'void') {
|
||||
const p2 = a == '' ? 'nil' : 'params';
|
||||
const returnType = indirect(b) ? `*${b}` : b;
|
||||
callBody = `var result ${returnType}
|
||||
if err := s.Conn.Call(ctx, "${m}", ${
|
||||
if err := Call(ctx, s.Conn, "${m}", ${
|
||||
p2}, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}`;
|
||||
} else if (a != '') {
|
||||
callBody = `return s.Conn.Call(ctx, "${m}", params, nil) // Call, not Notify
|
||||
callBody = `return Call(ctx, s.Conn, "${m}", params, nil) // Call, not Notify
|
||||
}`
|
||||
}
|
||||
side.calls.push(`${callHdr}\n${callBody}\n`);
|
||||
|
|
@ -1107,7 +1107,7 @@ function nonstandardRequests() {
|
|||
server.calls.push(
|
||||
`func (s *serverDispatcher) NonstandardRequest(ctx context.Context, method string, params interface{}) (interface{}, error) {
|
||||
var result interface{}
|
||||
if err := s.Conn.Call(ctx, method, params, &result); err != nil {
|
||||
if err := Call(ctx, s.Conn, method, params, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func TestHoverSerialization(t *testing.T) {
|
|||
params.Position.Line = 3
|
||||
params.Position.Character = 0
|
||||
var resp json.RawMessage
|
||||
if err := env.Conn.Call(env.Ctx, "textDocument/hover", ¶ms, &resp); err != nil {
|
||||
if err := protocol.Call(env.Ctx, env.Conn, "textDocument/hover", ¶ms, &resp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(string(resp)) > 0 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue