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

Fixes for VsCode Vim extension #6687

Merged
merged 1 commit into from
Dec 11, 2019
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
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 {
akosyakov marked this conversation as resolved.
Show resolved Hide resolved
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;
akosyakov marked this conversation as resolved.
Show resolved Hide resolved
} else {
throw e;
}
}
}

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