From e40d4ef7396af50418e94947b8aa47e93ba78f94 Mon Sep 17 00:00:00 2001 From: Jason Poon Date: Mon, 8 Jan 2018 11:03:52 -0800 Subject: [PATCH] fix: show cmd-line errors in status bar. add new E492 error --- src/cmd_line/commandLine.ts | 9 +++++++-- src/cmd_line/parser.ts | 3 ++- src/error.ts | 8 ++------ src/mode/modeHandler.ts | 12 +++++++----- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/cmd_line/commandLine.ts b/src/cmd_line/commandLine.ts index 567becb160e..cb231cc7a9a 100644 --- a/src/cmd_line/commandLine.ts +++ b/src/cmd_line/commandLine.ts @@ -6,6 +6,7 @@ import { VimState } from '../state/vimState'; import { StatusBar } from '../statusBar'; import * as parser from './parser'; import * as util from '../util'; +import { VimError, ErrorCode } from '../error'; export class CommandLine { public static async PromptAndRun(initialText: string, vimState: VimState): Promise { @@ -37,8 +38,12 @@ export class CommandLine { await cmd.execute(vimState.editor, vimState); } } catch (e) { - console.error(e); - await util.showError(`${e.message}`); + console.log(e); + if (e instanceof VimError) { + StatusBar.SetText(`${e.toString()}: ${command}`, vimState.currentMode, true); + } else { + util.showError(e.toString()); + } } } diff --git a/src/cmd_line/parser.ts b/src/cmd_line/parser.ts index c38c5e266da..9cd400783d3 100644 --- a/src/cmd_line/parser.ts +++ b/src/cmd_line/parser.ts @@ -2,6 +2,7 @@ import * as lexer from './lexer'; import * as node from './node'; import { commandParsers } from './subparser'; import * as token from './token'; +import { VimError, ErrorCode } from '../error'; interface IParseFunction { (state: ParserState, command: node.CommandLine): IParseFunction | null; @@ -52,7 +53,7 @@ function parseCommand(state: ParserState, commandLine: node.CommandLine): IParse case token.TokenType.CommandName: var commandParser = (commandParsers as any)[tok.content]; if (!commandParser) { - throw new Error('Not implemented or not a valid command'); + throw VimError.fromCode(ErrorCode.E492); } // TODO: Pass the args, but keep in mind there could be multiple // commands, not just one. diff --git a/src/error.ts b/src/error.ts index 6da7ab087d2..a0d0a9557d3 100644 --- a/src/error.ts +++ b/src/error.ts @@ -1,5 +1,3 @@ -import * as util from './util'; - interface IErrorMessage { [index: number]: string; } @@ -11,6 +9,7 @@ export enum ErrorCode { E348 = 348, E444 = 444, E488 = 488, + E492 = 492, } export const ErrorMessage: IErrorMessage = { @@ -19,6 +18,7 @@ export const ErrorMessage: IErrorMessage = { 208: 'Error writing to file', 348: 'No string under cursor', 444: 'Cannot close last window', + 492: 'Not an editor command', 488: 'Trailing characters', }; @@ -48,10 +48,6 @@ export class VimError extends Error { return this._message; } - display(): void { - util.showError(this.toString()); - } - toString(): string { return 'E' + this.code.toString() + ': ' + this.message; } diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 0a257e9b2d3..c7bded48c83 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -266,15 +266,15 @@ export class ModeHandler implements vscode.Disposable { async handleKeyEvent(key: string): Promise { const now = Number(new Date()); - // Rewrite commands. - // The conditions when you trigger a "copy" rather than a ctrl-c are - // too sophisticated to be covered by the "when" condition in package.json + // Rewrite commands if (Configuration.overrideCopy) { + // The conditions when you trigger a "copy" rather than a ctrl-c are + // too sophisticated to be covered by the "when" condition in package.json if (key === '') { key = ''; } - if (process.platform !== 'darwin' && key === '') { + if (key === '' && process.platform !== 'darwin') { if ( !Configuration.useCtrlKeys || this.vimState.currentMode === ModeName.Visual || @@ -1344,6 +1344,7 @@ export class ModeHandler implements vscode.Disposable { // Update all EasyMotion decorations this.vimState.easyMotion.updateDecorations(); } + this._renderStatusBar(); await vscode.commands.executeCommand( @@ -1385,7 +1386,8 @@ export class ModeHandler implements vscode.Disposable { text.push(macroText); } - StatusBar.SetText(text.join(' '), this.currentMode.name, true); + let forceUpdate = this.currentMode.name === ModeName.SearchInProgressMode; + StatusBar.SetText(text.join(' '), this.currentMode.name, forceUpdate); } async handleMultipleKeyEvents(keys: string[]): Promise {