MCPcopy Index your code
hub / github.com/microsoft/vscode-languageserver-node / ExecuteCommandFeature

Class ExecuteCommandFeature

client/src/client.ts:2129–2188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2127}
2128
2129class ExecuteCommandFeature implements DynamicFeature<ExecuteCommandRegistrationOptions> {
2130
2131 private _commands: Map<string, Disposable[]> = new Map<string, Disposable[]>();
2132
2133 constructor(private _client: BaseLanguageClient) {
2134 }
2135
2136 public get messages(): RPCMessageType {
2137 return ExecuteCommandRequest.type;
2138 }
2139
2140 public fillClientCapabilities(capabilities: ClientCapabilities): void {
2141 ensure(ensure(capabilities, 'workspace')!, 'executeCommand')!.dynamicRegistration = true;
2142 }
2143
2144 public initialize(capabilities: ServerCapabilities): void {
2145 if (!capabilities.executeCommandProvider) {
2146 return;
2147 }
2148 this.register(this.messages, {
2149 id: UUID.generateUuid(),
2150 registerOptions: Object.assign({}, capabilities.executeCommandProvider)
2151 });
2152 }
2153
2154 public register(_message: RPCMessageType, data: RegistrationData<ExecuteCommandRegistrationOptions>): void {
2155 let client = this._client;
2156 if (data.registerOptions.commands) {
2157 let disposeables: Disposable[] = [];
2158 for (const command of data.registerOptions.commands) {
2159 disposeables.push(Commands.registerCommand(command, (...args: any[]) => {
2160 let params: ExecuteCommandParams = {
2161 command,
2162 arguments: args
2163 };
2164 return client.sendRequest(ExecuteCommandRequest.type, params).then(
2165 undefined,
2166 (error) => {
2167 client.logFailedRequest(ExecuteCommandRequest.type, error);
2168 }
2169 );
2170 }));
2171 }
2172 this._commands.set(data.id, disposeables);
2173 }
2174 }
2175
2176 public unregister(id: string): void {
2177 let disposeables = this._commands.get(id);
2178 if (disposeables) {
2179 disposeables.forEach(disposable => disposable.dispose());
2180 }
2181 }
2182
2183 public dispose(): void {
2184 this._commands.forEach((value) => {
2185 value.forEach(disposable => disposable.dispose());
2186 });

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected