|
11 | 11 | */ |
12 | 12 |
|
13 | 13 | import { prepareExecutable } from './javaServerStarter'; |
14 | | -import { LanguageClientOptions, RevealOutputChannelOn, LanguageClient, DidChangeConfigurationNotification, RequestType, TextDocumentPositionParams, ReferencesRequest, NotificationType, MessageType, ConfigurationRequest, ConfigurationParams } from 'vscode-languageclient'; |
| 14 | +import { |
| 15 | + LanguageClientOptions, |
| 16 | + RevealOutputChannelOn, |
| 17 | + LanguageClient, |
| 18 | + DidChangeConfigurationNotification, |
| 19 | + RequestType, |
| 20 | + TextDocumentPositionParams, |
| 21 | + ReferencesRequest, |
| 22 | + NotificationType, |
| 23 | + MessageType, |
| 24 | + ConfigurationRequest, |
| 25 | + ConfigurationParams, |
| 26 | + ExecuteCommandParams, |
| 27 | + CancellationToken, |
| 28 | + ExecuteCommandRequest |
| 29 | +} from 'vscode-languageclient'; |
15 | 30 | import * as requirements from './requirements'; |
16 | 31 | import { languages, IndentAction, workspace, window, commands, ExtensionContext, TextDocument, Position, LanguageConfiguration, Uri, extensions, Command, TextEditor } from "vscode"; |
17 | 32 | import * as path from 'path'; |
@@ -114,6 +129,10 @@ export interface XMLExtensionApi { |
114 | 129 |
|
115 | 130 | } |
116 | 131 |
|
| 132 | +namespace ExecuteClientCommandRequest { |
| 133 | + export const type: RequestType<ExecuteCommandParams, any, void, void> = new RequestType('xml/executeClientCommand') |
| 134 | +} |
| 135 | + |
117 | 136 | namespace TagCloseRequest { |
118 | 137 | export const type: RequestType<TextDocumentPositionParams, AutoCloseResult, any, any> = new RequestType('xml/closeTag'); |
119 | 138 | } |
@@ -240,6 +259,30 @@ export function activate(context: ExtensionContext) { |
240 | 259 |
|
241 | 260 | setupActionableNotificationListener(languageClient); |
242 | 261 |
|
| 262 | + // Handler for 'xml/executeClientCommand` request message that executes a command on the client |
| 263 | + languageClient.onRequest(ExecuteClientCommandRequest.type, async (params: ExecuteCommandParams) => { |
| 264 | + return await commands.executeCommand(params.command, ...params.arguments); |
| 265 | + }); |
| 266 | + |
| 267 | + // Register client command to execute custom XML Language Server command |
| 268 | + context.subscriptions.push(commands.registerCommand(Commands.EXECUTE_WORKSPACE_COMMAND, (command, ...rest) => { |
| 269 | + let token: CancellationToken; |
| 270 | + let commandArgs: any[] = rest; |
| 271 | + if (rest && rest.length && CancellationToken.is(rest[rest.length - 1])) { |
| 272 | + token = rest[rest.length - 1]; |
| 273 | + commandArgs = rest.slice(0, rest.length - 1); |
| 274 | + } |
| 275 | + const params: ExecuteCommandParams = { |
| 276 | + command, |
| 277 | + arguments: commandArgs |
| 278 | + }; |
| 279 | + if (token) { |
| 280 | + return languageClient.sendRequest(ExecuteCommandRequest.type, params, token); |
| 281 | + } else { |
| 282 | + return languageClient.sendRequest(ExecuteCommandRequest.type, params); |
| 283 | + } |
| 284 | + })); |
| 285 | + |
243 | 286 | context.subscriptions.push(commands.registerCommand(Commands.OPEN_SETTINGS, async (settingId?: string) => { |
244 | 287 | commands.executeCommand('workbench.action.openSettings', settingId); |
245 | 288 | })); |
|
0 commit comments