vscode-languageclient/node#ExecuteCommandSignature TypeScript Examples

The following examples show how to use vscode-languageclient/node#ExecuteCommandSignature. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: extension.ts    From macro-executor with MIT License 4 votes vote down vote up
export function activate(context: ExtensionContext) {

	// The server is implemented in node
	let serverModule = context.asAbsolutePath(
		path.join('server', 'out', 'server.js')
	);

	let debugOptions = { execArgv: ['--nolazy', '--inspect=6011'], cwd: process.cwd() };
	let serverOptions: ServerOptions = {
		run: { module: serverModule, transport: TransportKind.ipc, options: { cwd: process.cwd() } },
		debug: {
			module: serverModule,
			transport: TransportKind.ipc,
			options: debugOptions
		}
	};

	let clientOptions: LanguageClientOptions = {
		documentSelector: [{ language: 'macro', scheme: 'file' }],
		initializationOptions: workspace.getConfiguration('macro'),
		synchronize: {
			fileEvents: workspace.createFileSystemWatcher('**/*.{[sS][rR][cC],[dD][eE][fF],[lL][nN][kK]}')
		},		
		diagnosticCollectionName: 'macro',
		progressOnInitialization: true,
		revealOutputChannelOn: RevealOutputChannelOn.Never,	
		middleware: {

			executeCommand: async (command:string, args:any[], next:ExecuteCommandSignature) => {
				if (command === 'macro.codelens.references') {
					const arg:CodeLensReferenceArgument = args[0];


					const position = client.protocol2CodeConverter.asPosition(arg.position);
					const locations:Location[] = [];
					for (const location of arg.locations){
						locations.push(client.protocol2CodeConverter.asLocation(location));
					}

					if (Window.activeTextEditor) {
						commands.executeCommand('editor.action.showReferences', Window.activeTextEditor.document.uri, position, locations);
					}
				}
				else if (command === 'macro.action.refactorsequeces' || command === 'macro.action.addsequeces') {
					function validate(input:string): string | null {
						return Number.isInteger(Number(input)) ? null : 'Integer expected';
					}

					const config = workspace.getConfiguration('macro');
					let start = undefined;
					if (command === 'macro.action.refactorsequeces') {
						start = await Window.showInputBox({
							prompt: 'Start sequence number',
							value: config.sequence.base,
							validateInput: validate
						});
					}
		
					const increment = await Window.showInputBox({
						prompt: 'Sequence number increment',
						value: config.sequence.increment,
						validateInput: validate
					});

					if (Window.activeTextEditor) {
						if (command === 'macro.action.addsequeces' && increment) {
							return next(command, [Window.activeTextEditor.document.uri.toString(), Window.activeTextEditor.selection.start, increment]);
						} 
						else if (command === 'macro.action.refactorsequeces' && start && increment) {
							return next(command, [Window.activeTextEditor.document.uri.toString(), Window.activeTextEditor.selection.start, start, increment]);
						}
					}
				}
			},
			workspace : {
				configuration: async (params, _token, _next): Promise<any[]> => {
					if (params.items === undefined) {
						return [];
					}
					const result: (ConfigurationSettings | null)[] = [];
					for (const item of params.items) {
						if (item.section || !item.scopeUri) {
							result.push(null);
							continue;
						}
						const resource = client.protocol2CodeConverter.asUri(item.scopeUri);
						const workspaceFolder = Workspace.getWorkspaceFolder(resource);
						const config = workspace.getConfiguration('macro', workspaceFolder);
						const settings: ConfigurationSettings = {
							codelens: config.get('codelens'),
							lint:config.get('lint', {}),
							sequence: config.get('sequence'),
							validate: config.get('validate'),
							keywords: config.get('keywords'),
						};
		
						if (workspaceFolder !== undefined) {
							settings.workspaceFolder = {
								name: workspaceFolder.name,
								uri: client.code2ProtocolConverter.asUri(workspaceFolder.uri),
							};
						}
						result.push(settings);
					}
					return result;
				}
			}
		} as any
	};


	// Create the language client and start the client.
	client = new LanguageClient(
		'macroLanguageServer',
		'Macro Language Server',
		serverOptions,
		clientOptions
	);

	disposables.add(registerCommands());
	context.subscriptions.push(disposables);
	context.subscriptions.push(client.start());
}