github.com/powerman/golang-tools@v0.1.11-0.20220410185822-5ad214d8d803/internal/lsp/protocol/tsclient.go (about)

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