|
| 1 | +// Copyright 2024 The Go Language Server Authors |
| 2 | +// SPDX-License-Identifier: BSD-3-Clause |
| 3 | + |
| 4 | +package protocol |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + |
| 9 | + "go.lsp.dev/jsonrpc2" |
| 10 | +) |
| 11 | + |
| 12 | +const ( |
| 13 | + MethodClientCancelRequest ClientMethod = "$/cancelRequest" // bidirect client notification |
| 14 | + MethodClientProgress ClientMethod = "$/progress" // bidirect client notification |
| 15 | + MethodLogTrace ClientMethod = "$/logTrace" // client notification |
| 16 | + MethodTelemetryEvent ClientMethod = "telemetry/event" // client notification |
| 17 | + MethodTextDocumentPublishDiagnostics ClientMethod = "textDocument/publishDiagnostics" // client notification |
| 18 | + MethodWindowLogMessage ClientMethod = "window/logMessage" // client notification |
| 19 | + MethodWindowShowMessage ClientMethod = "window/showMessage" // client notification |
| 20 | + MethodClientRegisterCapability ClientMethod = "client/registerCapability" // client request |
| 21 | + MethodClientUnregisterCapability ClientMethod = "client/unregisterCapability" // client request |
| 22 | + MethodWindowShowDocument ClientMethod = "window/showDocument" // client request |
| 23 | + MethodWindowShowMessageRequest ClientMethod = "window/showMessageRequest" // client request |
| 24 | + MethodWindowWorkDoneProgressCreate ClientMethod = "window/workDoneProgress/create" // client request |
| 25 | + MethodWorkspaceApplyEdit ClientMethod = "workspace/applyEdit" // client request |
| 26 | + MethodWorkspaceCodeLensRefresh ClientMethod = "workspace/codeLens/refresh" // client request |
| 27 | + MethodWorkspaceConfiguration ClientMethod = "workspace/configuration" // client request |
| 28 | + MethodWorkspaceDiagnosticRefresh ClientMethod = "workspace/diagnostic/refresh" // client request |
| 29 | + MethodWorkspaceFoldingRangeRefresh ClientMethod = "workspace/foldingRange/refresh" // client request |
| 30 | + MethodWorkspaceInlayHintRefresh ClientMethod = "workspace/inlayHint/refresh" // client request |
| 31 | + MethodWorkspaceInlineValueRefresh ClientMethod = "workspace/inlineValue/refresh" // client request |
| 32 | + MethodWorkspaceSemanticTokensRefresh ClientMethod = "workspace/semanticTokens/refresh" // client request |
| 33 | + MethodWorkspaceWorkspaceFolders ClientMethod = "workspace/workspaceFolders" // client request |
| 34 | +) |
| 35 | + |
| 36 | +type Client interface { |
| 37 | + CancelRequest(ctx context.Context, params *CancelParams) error |
| 38 | + |
| 39 | + Progress(ctx context.Context, params *ProgressParams) error |
| 40 | + |
| 41 | + LogTrace(ctx context.Context, params *LogTraceParams) error |
| 42 | + |
| 43 | + // TelemetryEvent the telemetry event notification is sent from the server to the client to ask the client to log telemetry data. |
| 44 | + TelemetryEvent(ctx context.Context, params any) error |
| 45 | + |
| 46 | + // TextDocumentPublishDiagnostics diagnostics notification are sent from the server to the client to signal results of validation runs. |
| 47 | + TextDocumentPublishDiagnostics(ctx context.Context, params *PublishDiagnosticsParams) error |
| 48 | + |
| 49 | + // WindowLogMessage the log message notification is sent from the server to the client to ask the client to log a particular message. |
| 50 | + WindowLogMessage(ctx context.Context, params *LogMessageParams) error |
| 51 | + |
| 52 | + // WindowShowMessage the show message notification is sent from a server to a client to ask the client to display a particular message in the user interface. |
| 53 | + WindowShowMessage(ctx context.Context, params *ShowMessageParams) error |
| 54 | + // ClientRegisterCapability the `client/registerCapability` request is sent from the server to the client to register a new capability handler on the client side. |
| 55 | + ClientRegisterCapability(ctx context.Context, params *RegistrationParams) error |
| 56 | + |
| 57 | + // ClientUnregisterCapability the `client/unregisterCapability` request is sent from the server to the client to unregister a previously registered capability handler on the client side. |
| 58 | + ClientUnregisterCapability(ctx context.Context, params *UnregistrationParams) error |
| 59 | + |
| 60 | + // WindowShowDocument a request to show a document. This request might open an external program depending on the value of the URI to open. For example a request to open `https://code.visualstudio.com/` will very likely open the URI in a WEB browser. |
| 61 | + // |
| 62 | + // @since 3.16.0 |
| 63 | + WindowShowDocument(ctx context.Context, params *ShowDocumentParams) (*ShowDocumentResult, error) |
| 64 | + |
| 65 | + // WindowShowMessageRequest the show message request is sent from the server to the client to show a message and a set of options actions to the user. |
| 66 | + WindowShowMessageRequest(ctx context.Context, params *ShowMessageRequestParams) (*MessageActionItem, error) |
| 67 | + |
| 68 | + // WindowWorkDoneProgressCreate the `window/workDoneProgress/create` request is sent from the server to the client to initiate progress reporting from the server. |
| 69 | + WindowWorkDoneProgressCreate(ctx context.Context, params *WorkDoneProgressCreateParams) error |
| 70 | + |
| 71 | + // WorkspaceApplyEdit a request sent from the server to the client to modified certain resources. |
| 72 | + WorkspaceApplyEdit(ctx context.Context, params *ApplyWorkspaceEditParams) (*ApplyWorkspaceEditResult, error) |
| 73 | + |
| 74 | + // WorkspaceCodeLensRefresh a request to refresh all code actions |
| 75 | + // |
| 76 | + // @since 3.16.0 |
| 77 | + WorkspaceCodeLensRefresh(ctx context.Context) error |
| 78 | + |
| 79 | + // WorkspaceConfiguration the 'workspace/configuration' request is sent from the server to the client to fetch a certain configuration setting. This pull model replaces the old push model were the client signaled configuration |
| 80 | + // change via an event. If the server still needs to react to configuration changes (since the server caches the result of `workspace/configuration` requests) the server should register for an empty configuration change event and empty the cache if such an event is received. |
| 81 | + WorkspaceConfiguration(ctx context.Context, params *ConfigurationParams) ([]any, error) |
| 82 | + |
| 83 | + // WorkspaceDiagnosticRefresh the diagnostic refresh request definition. |
| 84 | + // |
| 85 | + // @since 3.17.0 |
| 86 | + WorkspaceDiagnosticRefresh(ctx context.Context) error |
| 87 | + |
| 88 | + // WorkspaceFoldingRangeRefresh. |
| 89 | + // |
| 90 | + // @since 3.18.0 proposed |
| 91 | + WorkspaceFoldingRangeRefresh(ctx context.Context) error |
| 92 | + |
| 93 | + // WorkspaceInlayHintRefresh. |
| 94 | + // |
| 95 | + // @since 3.17.0 |
| 96 | + WorkspaceInlayHintRefresh(ctx context.Context) error |
| 97 | + |
| 98 | + // WorkspaceInlineValueRefresh. |
| 99 | + // |
| 100 | + // @since 3.17.0 |
| 101 | + WorkspaceInlineValueRefresh(ctx context.Context) error |
| 102 | + |
| 103 | + // WorkspaceSemanticTokensRefresh. |
| 104 | + // |
| 105 | + // @since 3.16.0 |
| 106 | + WorkspaceSemanticTokensRefresh(ctx context.Context) error |
| 107 | + |
| 108 | + // WorkspaceWorkspaceFolders the `workspace/workspaceFolders` is sent from the server to the client to fetch the open workspace folders. |
| 109 | + WorkspaceWorkspaceFolders(ctx context.Context) ([]*WorkspaceFolder, error) |
| 110 | +} |
| 111 | + |
| 112 | +// UnimplementedClient should be embedded to have forward compatible implementations. |
| 113 | +type UnimplementedClient struct{} |
| 114 | + |
| 115 | +func (UnimplementedClient) CancelRequest(ctx context.Context, params *CancelParams) error { |
| 116 | + return jsonrpc2.ErrInternal |
| 117 | +} |
| 118 | + |
| 119 | +func (UnimplementedClient) Progress(ctx context.Context, params *ProgressParams) error { |
| 120 | + return jsonrpc2.ErrInternal |
| 121 | +} |
| 122 | + |
| 123 | +func (UnimplementedClient) LogTrace(ctx context.Context, params *LogTraceParams) error { |
| 124 | + return jsonrpc2.ErrInternal |
| 125 | +} |
| 126 | + |
| 127 | +func (UnimplementedClient) TelemetryEvent(ctx context.Context, params any) error { |
| 128 | + return jsonrpc2.ErrInternal |
| 129 | +} |
| 130 | + |
| 131 | +func (UnimplementedClient) TextDocumentPublishDiagnostics(ctx context.Context, params *PublishDiagnosticsParams) error { |
| 132 | + return jsonrpc2.ErrInternal |
| 133 | +} |
| 134 | + |
| 135 | +func (UnimplementedClient) WindowLogMessage(ctx context.Context, params *LogMessageParams) error { |
| 136 | + return jsonrpc2.ErrInternal |
| 137 | +} |
| 138 | + |
| 139 | +func (UnimplementedClient) WindowShowMessage(ctx context.Context, params *ShowMessageParams) error { |
| 140 | + return jsonrpc2.ErrInternal |
| 141 | +} |
| 142 | + |
| 143 | +func (UnimplementedClient) ClientRegisterCapability(ctx context.Context, params *RegistrationParams) error { |
| 144 | + return jsonrpc2.ErrInternal |
| 145 | +} |
| 146 | + |
| 147 | +func (UnimplementedClient) ClientUnregisterCapability(ctx context.Context, params *UnregistrationParams) error { |
| 148 | + return jsonrpc2.ErrInternal |
| 149 | +} |
| 150 | + |
| 151 | +func (UnimplementedClient) WindowShowDocument(ctx context.Context, params *ShowDocumentParams) (*ShowDocumentResult, error) { |
| 152 | + return nil, jsonrpc2.ErrInternal |
| 153 | +} |
| 154 | + |
| 155 | +func (UnimplementedClient) WindowShowMessageRequest(ctx context.Context, params *ShowMessageRequestParams) (*MessageActionItem, error) { |
| 156 | + return nil, jsonrpc2.ErrInternal |
| 157 | +} |
| 158 | + |
| 159 | +func (UnimplementedClient) WindowWorkDoneProgressCreate(ctx context.Context, params *WorkDoneProgressCreateParams) error { |
| 160 | + return jsonrpc2.ErrInternal |
| 161 | +} |
| 162 | + |
| 163 | +func (UnimplementedClient) WorkspaceApplyEdit(ctx context.Context, params *ApplyWorkspaceEditParams) (*ApplyWorkspaceEditResult, error) { |
| 164 | + return nil, jsonrpc2.ErrInternal |
| 165 | +} |
| 166 | + |
| 167 | +func (UnimplementedClient) WorkspaceCodeLensRefresh(ctx context.Context) error { |
| 168 | + return jsonrpc2.ErrInternal |
| 169 | +} |
| 170 | + |
| 171 | +func (UnimplementedClient) WorkspaceConfiguration(ctx context.Context, params *ConfigurationParams) ([]any, error) { |
| 172 | + return nil, jsonrpc2.ErrInternal |
| 173 | +} |
| 174 | + |
| 175 | +func (UnimplementedClient) WorkspaceDiagnosticRefresh(ctx context.Context) error { |
| 176 | + return jsonrpc2.ErrInternal |
| 177 | +} |
| 178 | + |
| 179 | +func (UnimplementedClient) WorkspaceFoldingRangeRefresh(ctx context.Context) error { |
| 180 | + return jsonrpc2.ErrInternal |
| 181 | +} |
| 182 | + |
| 183 | +func (UnimplementedClient) WorkspaceInlayHintRefresh(ctx context.Context) error { |
| 184 | + return jsonrpc2.ErrInternal |
| 185 | +} |
| 186 | + |
| 187 | +func (UnimplementedClient) WorkspaceInlineValueRefresh(ctx context.Context) error { |
| 188 | + return jsonrpc2.ErrInternal |
| 189 | +} |
| 190 | + |
| 191 | +func (UnimplementedClient) WorkspaceSemanticTokensRefresh(ctx context.Context) error { |
| 192 | + return jsonrpc2.ErrInternal |
| 193 | +} |
| 194 | + |
| 195 | +func (UnimplementedClient) WorkspaceWorkspaceFolders(ctx context.Context) ([]*WorkspaceFolder, error) { |
| 196 | + return nil, jsonrpc2.ErrInternal |
| 197 | +} |
0 commit comments