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

fix: show cmd-line errors in status bar. add new E492 error #2272

Merged
merged 1 commit into from
Jan 8, 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
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
8 changes: 2 additions & 6 deletions src/error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as util from './util';

interface IErrorMessage {
[index: number]: string;
}
Expand All @@ -11,6 +9,7 @@ export enum ErrorCode {
E348 = 348,
E444 = 444,
E488 = 488,
E492 = 492,
}

export const ErrorMessage: IErrorMessage = {
Expand All @@ -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',
};

Expand Down Expand Up @@ -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;
}
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