Skip to content

Commit

Permalink
fix: show cmd-line errors in status bar. add new E492 error
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoon committed Jan 8, 2018
1 parent 4c1f49f commit fceb8dd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
9 changes: 7 additions & 2 deletions src/cmd_line/commandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down Expand Up @@ -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());
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/cmd_line/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum ErrorCode {
E208 = 208,
E348 = 348,
E444 = 444,
E492 = 492,
E488 = 488,
}

Expand All @@ -19,6 +20,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',
};

Expand Down Expand Up @@ -48,10 +50,6 @@ export class VimError extends Error {
return this._message;
}

display(): void {
util.showError(this.toString());
}

toString(): string {
return 'E' + this.code.toString() + ': ' + this.message;
}
Expand Down
12 changes: 7 additions & 5 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ export class ModeHandler implements vscode.Disposable {
async handleKeyEvent(key: string): Promise<Boolean> {
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 === '<D-c>') {
key = '<copy>';
}

if (process.platform !== 'darwin' && key === '<C-c>') {
if (key === '<C-c>' && process.platform !== 'darwin') {
if (
!Configuration.useCtrlKeys ||
this.vimState.currentMode === ModeName.Visual ||
Expand Down Expand Up @@ -1344,6 +1344,7 @@ export class ModeHandler implements vscode.Disposable {
// Update all EasyMotion decorations
this.vimState.easyMotion.updateDecorations();
}

this._renderStatusBar();

await vscode.commands.executeCommand(
Expand Down Expand Up @@ -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<void> {
Expand Down

0 comments on commit fceb8dd

Please sign in to comment.