diff --git a/packages/languages/src/browser/language-client-contribution.ts b/packages/languages/src/browser/language-client-contribution.ts index 2938d258eda3f..8474c3245bcf5 100644 --- a/packages/languages/src/browser/language-client-contribution.ts +++ b/packages/languages/src/browser/language-client-contribution.ts @@ -112,6 +112,10 @@ export abstract class BaseLanguageClientContribution implements LanguageClientCo })); } }, options); + + this.registerRestartCommand(); + toDeactivate.push(Disposable.create(() => this.unregisterRestartCommand())); + return toDeactivate; } @@ -228,4 +232,34 @@ export abstract class BaseLanguageClientContribution implements LanguageClientCo }); } + /** + * Return the id of the "restart" command for this language client. + */ + private restartCommandId(): string { + return `languages.${this.id}.restart`; + } + + /** + * Register a command that lets the user restart the language server this + * client is connected to. + */ + protected registerRestartCommand(): void { + this.registry.registerCommand( + { + id: this.restartCommandId(), + label: `${this.name}: Restart Language Server`, + }, + { + execute: () => this.restart(), + isEnabled: () => this.running, + isVisible: () => this.running, + }); + } + + /** + * Unregister the command registered by `registerRestartCommand`. + */ + protected unregisterRestartCommand(): void { + this.registry.unregisterCommand(this.restartCommandId()); + } } diff --git a/packages/typescript/src/browser/typescript-frontend-contribution.ts b/packages/typescript/src/browser/typescript-frontend-contribution.ts index f7727b9f9434e..25b0733392e44 100644 --- a/packages/typescript/src/browser/typescript-frontend-contribution.ts +++ b/packages/typescript/src/browser/typescript-frontend-contribution.ts @@ -40,10 +40,6 @@ export namespace TypeScriptCommands { label: 'TypeScript: Open Server Log', id: 'typescript.server.openLog' }; - export const restartServer: Command = { - label: 'TypeScript: Restart Server', - id: 'typescript.server.restart' - }; } @injectable() @@ -83,11 +79,6 @@ export class TypeScriptFrontendContribution implements CommandContribution, Menu isEnabled: () => !!this.clientContribution.logFileUri, isVisible: () => !!this.clientContribution.logFileUri }); - commands.registerCommand(TypeScriptCommands.restartServer, { - execute: () => this.clientContribution.restart(), - isEnabled: () => this.clientContribution.running, - isVisible: () => this.clientContribution.running - }); } registerMenus(menus: MenuModelRegistry): void {