Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically add "restart" commands for language servers #3215

Merged
merged 1 commit into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/languages/src/browser/language-client-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ export abstract class BaseLanguageClientContribution implements LanguageClientCo
}));
}
}, options);

this.registerRestartCommand();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be available only if the server actually running, i.e. like in typescript extension right now.

We also need to remove an existing command from the typescript extension to avoid duplicate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be available only if the server actually running, i.e. like in typescript extension right now.

This is what this code does, doesn't it? activate is only called when starting the language client/server.

We also need to remove an existing command from the typescript extension to avoid duplicate.

Ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the language server stops, we should remove the command, but I don't know how to make a language server stop for good.

toDeactivate.push(Disposable.create(() => this.unregisterRestartCommand()));

return toDeactivate;
}

Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could implement isEnabled and isVisible in the same way for generic restart command that it is not visible while a server is restarting.

Copy link
Contributor Author

@simark simark Oct 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that.

isVisible: () => this.clientContribution.running
});
}

registerMenus(menus: MenuModelRegistry): void {
Expand Down