Skip to content

Commit

Permalink
Added mappings from vscode commands to internal commands
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Pinkney <joshpinkney@gmail.com>
  • Loading branch information
JPinkney authored and che committed Nov 7, 2019
1 parent f2b3556 commit 4495b30
Show file tree
Hide file tree
Showing 14 changed files with 508 additions and 74 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Breaking changes:

- [task] changed `TaskSchemaUpdater.update()` from asynchronous to synchronous [#6483](https://github.com/eclipse-theia/theia/pull/6483)
- [monaco] monaco prefix has been removed from commands [#5590](https://github.com/eclipse-theia/theia/pull/5590)

## v0.12.0

Expand Down
11 changes: 2 additions & 9 deletions packages/monaco/src/browser/monaco-command-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,21 @@ export interface MonacoEditorCommandHandler {
@injectable()
export class MonacoCommandRegistry {

public static MONACO_COMMAND_PREFIX = 'monaco.';

@inject(MonacoEditorProvider)
protected readonly monacoEditors: MonacoEditorProvider;

@inject(CommandRegistry) protected readonly commands: CommandRegistry;

@inject(SelectionService) protected readonly selectionService: SelectionService;

protected prefix(command: string): string {
return MonacoCommandRegistry.MONACO_COMMAND_PREFIX + command;
}

validate(command: string): string | undefined {
const monacoCommand = this.prefix(command);
return this.commands.commandIds.indexOf(monacoCommand) !== -1 ? monacoCommand : undefined;
return this.commands.commandIds.indexOf(command) !== -1 ? command : undefined;
}

registerCommand(command: Command, handler: MonacoEditorCommandHandler): void {
this.commands.registerCommand({
...command,
id: this.prefix(command.id)
id: command.id
}, this.newHandler(handler));
}

Expand Down
5 changes: 5 additions & 0 deletions packages/monaco/src/browser/monaco-command-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export class MonacoCommandService implements ICommandService {
this._onWillExecuteCommand.fire({ commandId });
return handler.execute(...args);
}
return this.executeMonacoCommand(commandId, ...args);
}

// tslint:disable-next-line:no-any
async executeMonacoCommand(commandId: any, ...args: any[]): Promise<any> {
if (this.delegate) {
return this.delegate.executeCommand(commandId, ...args);
}
Expand Down
10 changes: 8 additions & 2 deletions packages/monaco/src/browser/monaco-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { EditorCommands } from '@theia/editor/lib/browser';
import { MonacoEditor } from './monaco-editor';
import { MonacoCommandRegistry, MonacoEditorCommandHandler } from './monaco-command-registry';
import MenuRegistry = monaco.actions.MenuRegistry;
import { MonacoCommandService } from './monaco-command-service';

export type MonacoCommand = Command & { delegate?: string };
export namespace MonacoCommands {
Expand Down Expand Up @@ -118,7 +119,7 @@ export class MonacoEditorCommandHandlers implements CommandContribution {
if (command.startsWith('_execute')) {
this.commandRegistry.registerCommand(
{
id: MonacoCommandRegistry.MONACO_COMMAND_PREFIX + command
id: command
},
{
// tslint:disable-next-line:no-any
Expand Down Expand Up @@ -273,7 +274,7 @@ export class MonacoEditorCommandHandlers implements CommandContribution {
}
protected newMonacoActionHandler(action: MonacoCommand): MonacoEditorCommandHandler {
const delegate = action.delegate;
return delegate ? this.newCommandHandler(delegate) : this.newActionHandler(action.id);
return delegate ? this.newDelegateHandler(delegate) : this.newActionHandler(action.id);
}

protected newKeyboardHandler(action: string): MonacoEditorCommandHandler {
Expand All @@ -292,5 +293,10 @@ export class MonacoEditorCommandHandlers implements CommandContribution {
isEnabled: editor => editor.isActionSupported(action)
};
}
protected newDelegateHandler(action: string): MonacoEditorCommandHandler {
return {
execute: (editor, ...args) => (editor.commandService as MonacoCommandService).executeMonacoCommand(action, ...args)
};
}

}
2 changes: 1 addition & 1 deletion packages/monaco/src/browser/monaco-editor-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class MonacoEditorProvider {
const formatOnSaveTimeout = this.editorPreferences.get({ preferenceName: 'editor.formatOnSaveTimeout', overrideIdentifier }, undefined, uri)!;
await Promise.race([
new Promise(reject => setTimeout(() => reject(new Error(`Aborted format on save after ${formatOnSaveTimeout}ms`)), formatOnSaveTimeout)),
await editor.commandService.executeCommand('monaco.editor.action.formatDocument')
await editor.commandService.executeCommand('editor.action.formatDocument')
]);
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
id: 'vscode.executeDocumentSymbolProvider'
},
{
execute: (resource: URI) => commands.executeCommand('monaco._executeDocumentSymbolProvider',
execute: (resource: URI) => commands.executeCommand('_executeDocumentSymbolProvider',
{ resource: monaco.Uri.parse(resource.toString()) }
).then((value: any) => {
if (!Array.isArray(value) || value === undefined) {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
export * from './plugin-protocol';
export * from './plugin-api-rpc';
export * from './plugin-ext-api-contribution';
export * from './known-commands';
Loading

0 comments on commit 4495b30

Please sign in to comment.