Skip to content

Commit

Permalink
[commands] log warning if a command is already registered instead of …
Browse files Browse the repository at this point in the history
…throwing

this happens e.g. with `java.edit.organizeImports`, where commands are registered to be used for menus, but JDT LS will register the same command.

Signed-off-by: Alex Tugarev <alex.tugarev@typefox.io>
  • Loading branch information
AlexTugarev committed Apr 25, 2018
1 parent 4c18a8a commit e869d72
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/core/src/common/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ export class CommandRegistry implements CommandService {
* Throw if a command is already registered for the given command identifier.
*/
registerCommand(command: Command, handler?: CommandHandler): Disposable {
if (this._commands[command.id]) {
console.warn(`A command ${command.id} is already registered.`);
return Disposable.NULL;
}
if (handler) {
const toDispose = new DisposableCollection();
toDispose.push(this.doRegisterCommand(command));
Expand All @@ -111,9 +115,6 @@ export class CommandRegistry implements CommandService {
}

protected doRegisterCommand(command: Command): Disposable {
if (this._commands[command.id]) {
throw Error(`A command ${command.id} is already registered.`);
}
this._commands[command.id] = command;
return {
dispose: () => {
Expand Down

0 comments on commit e869d72

Please sign in to comment.