Skip to content

Commit

Permalink
fix(languages): avoid error when complete command not exists
Browse files Browse the repository at this point in the history
Closes #2955
  • Loading branch information
chemzqm committed Mar 9, 2021
1 parent f92a055 commit d09f354
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 2 additions & 8 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,8 @@ export class CommandManager implements Disposable {
*/
public executeCommand(command: string, ...rest: any[]): Promise<any> {
let cmd = this.commands.get(command)
if (!cmd) {
window.showMessage(`Command: ${command} not found`, 'error')
return
}
return Promise.resolve(cmd.execute.apply(cmd, rest)).catch(e => {
window.showMessage(`Command error: ${e.message}`, 'error')
logger.error(e.stack)
})
if (!cmd) throw new Error(`Command: ${command} not found`)
return Promise.resolve(cmd.execute.apply(cmd, rest))
}

public async addRecent(cmd: string): Promise<void> {
Expand Down
4 changes: 3 additions & 1 deletion src/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,9 @@ class Languages {
}
await this.applyAdditionalEdits(additionalTextEdits, opt.bufnr, isSnippet)
if (isSnippet) await snippetManager.selectCurrentPlaceholder()
if (item.command) commands.execute(item.command)
if (item.command && commands.has(item.command.command)) {
commands.execute(item.command)
}
} catch (e) {
logger.error('Error on CompleteDone:', e)
}
Expand Down

0 comments on commit d09f354

Please sign in to comment.