Skip to content

Commit

Permalink
Fixes for Vscode Vim extension
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Vinokur <[email protected]>
  • Loading branch information
vinokurig committed Dec 11, 2019
1 parent d5f0fcf commit 928e1e0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/common/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export class CommandRegistry implements CommandService {
return result;
}
const argsMessage = args && args.length > 0 ? ` (args: ${JSON.stringify(args)})` : '';
throw new Error(`The command '${commandId}' cannot be executed. There are no active handlers available for the command.${argsMessage}`);
throw Object.assign(new Error(`The command '${commandId}' cannot be executed. There are no active handlers available for the command.${argsMessage}`), { code: 'NO_ACTIVE_HANDLER' });
}

protected async fireWillExecuteCommand(commandId: string): Promise<void> {
Expand Down
5 changes: 5 additions & 0 deletions packages/monaco/src/browser/monaco-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ export class MonacoEditor extends MonacoEditorServices implements TextEditor {
this.toDispose.dispose();
}

// tslint:disable-next-line:no-any
trigger(source: string, handlerId: string, payload: any): void {
this.editor.trigger(source, handlerId, payload);
}

getControl(): IStandaloneCodeEditor {
return this.editor;
}
Expand Down
1 change: 1 addition & 0 deletions packages/monaco/src/typings/monaco/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ declare module monaco.editor {
export interface IStandaloneCodeEditor extends CommonCodeEditor {
setDecorations(decorationTypeKey: string, ranges: IDecorationOptions[]): void;
setDecorationsFast(decorationTypeKey: string, ranges: IRange[]): void;
trigger(source: string, handlerId: string, payload: any): void
}

// https://github.com/TypeFox/vscode/blob/monaco/0.18.0/src/vs/editor/browser/widget/codeEditorWidget.ts#L107
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"@theia/core": "^0.13.0",
"@theia/editor": "^0.13.0",
"@theia/monaco": "^0.13.0",
"@theia/plugin": "^0.13.0",
"@theia/plugin-ext": "^0.13.0",
"@theia/workspace": "^0.13.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { fromViewColumn, toDocumentSymbol } from '@theia/plugin-ext/lib/plugin/t
import { ViewColumn } from '@theia/plugin-ext/lib/plugin/types-impl';
import { WorkspaceCommands } from '@theia/workspace/lib/browser';
import { DiffService } from '@theia/workspace/lib/browser/diff-service';
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
import { inject, injectable } from 'inversify';
import URI from 'vscode-uri';

Expand Down Expand Up @@ -137,6 +138,14 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
commands.registerCommand({ id: 'workbench.action.files.openFolder' }, {
execute: () => commands.executeCommand(WorkspaceCommands.OPEN_FOLDER.id)
});
commands.registerCommand({ id: 'default:type' }, {
execute: args => {
const editor = MonacoEditor.getCurrent(this.editorManager);
if (editor) {
editor.trigger('keyboard', 'type', args);
}
}
});
commands.registerCommand({ id: 'workbench.action.files.save', }, {
execute: (uri?: monaco.Uri) => {
if (uri) {
Expand Down
16 changes: 14 additions & 2 deletions packages/plugin-ext/src/main/browser/command-registry-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,20 @@ export class CommandRegistryMainImpl implements CommandRegistryMain, Disposable
}

// tslint:disable-next-line:no-any
$executeCommand<T>(id: string, ...args: any[]): PromiseLike<T | undefined> {
return this.delegate.executeCommand(id, ...args);
async $executeCommand<T>(id: string, ...args: any[]): Promise<T | undefined> {
if (!this.delegate.getCommand(id)) {
throw new Error(`Command with id '${id}' is not registered.`);
}
try {
return await this.delegate.executeCommand(id, ...args);
} catch (e) {
// Command handler may be not active at the moment so the error must be caught. See https://github.com/eclipse-theia/theia/pull/6687#discussion_r354810079
if ('code' in e && e['code'] === 'NO_ACTIVE_HANDLER') {
return;
} else {
throw e;
}
}
}

$getKeyBinding(commandId: string): PromiseLike<theia.CommandKeyBinding[] | undefined> {
Expand Down

0 comments on commit 928e1e0

Please sign in to comment.