mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-29 21:11:38 +01:00
debt - no guessing-caching, better use of gc-signals, command converter using gc-signals, main side heap service
This commit is contained in:
@@ -12,7 +12,11 @@ import { ExtHostEditors } from 'vs/workbench/api/node/extHostEditors';
|
||||
import * as extHostTypes from 'vs/workbench/api/node/extHostTypes';
|
||||
import * as extHostTypeConverter from 'vs/workbench/api/node/extHostTypeConverters';
|
||||
import { cloneAndChange } from 'vs/base/common/objects';
|
||||
import { MainContext, MainThreadCommandsShape, ExtHostCommandsShape } from './extHost.protocol';
|
||||
import { MainContext, MainThreadCommandsShape, ExtHostCommandsShape, ObjectIdentifier } from './extHost.protocol';
|
||||
import { ExtHostHeapService } from 'vs/workbench/api/node/extHostHeapService';
|
||||
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
|
||||
import * as modes from 'vs/editor/common/modes';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
interface CommandHandler {
|
||||
callback: Function;
|
||||
@@ -25,14 +29,21 @@ export class ExtHostCommands extends ExtHostCommandsShape {
|
||||
private _commands: { [n: string]: CommandHandler } = Object.create(null);
|
||||
private _proxy: MainThreadCommandsShape;
|
||||
private _extHostEditors: ExtHostEditors;
|
||||
private _converter: CommandsConverter;
|
||||
|
||||
constructor(
|
||||
threadService: IThreadService,
|
||||
extHostEditors: ExtHostEditors
|
||||
extHostEditors: ExtHostEditors,
|
||||
heapService: ExtHostHeapService
|
||||
) {
|
||||
super();
|
||||
this._extHostEditors = extHostEditors;
|
||||
this._proxy = threadService.get(MainContext.MainThreadCommands);
|
||||
this._converter = new CommandsConverter(this, heapService);
|
||||
}
|
||||
|
||||
get converter(): CommandsConverter {
|
||||
return this._converter;
|
||||
}
|
||||
|
||||
registerCommand(id: string, callback: <T>(...args: any[]) => T | Thenable<T>, thisArg?: any, description?: ICommandHandlerDescription): extHostTypes.Disposable {
|
||||
@@ -137,3 +148,68 @@ export class ExtHostCommands extends ExtHostCommandsShape {
|
||||
return TPromise.as(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class CommandsConverter {
|
||||
|
||||
private _commands: ExtHostCommands;
|
||||
private _heap: ExtHostHeapService;
|
||||
|
||||
// --- conversion between internal and api commands
|
||||
constructor(commands: ExtHostCommands, heap: ExtHostHeapService) {
|
||||
|
||||
this._commands = commands;
|
||||
this._heap = heap;
|
||||
this._commands.registerCommand('_internal_command_delegation', this._executeConvertedCommand, this);
|
||||
}
|
||||
|
||||
toInternal(command: vscode.Command): modes.Command {
|
||||
|
||||
if (!command) {
|
||||
return;
|
||||
}
|
||||
|
||||
const result: modes.Command = {
|
||||
id: command.command,
|
||||
title: command.title
|
||||
};
|
||||
|
||||
if (!isFalsyOrEmpty(command.arguments)) {
|
||||
// we have a contributed command with arguments. that
|
||||
// means we don't want to send the arguments around
|
||||
|
||||
const id = this._heap.keep(command);
|
||||
ObjectIdentifier.mixin(result, id);
|
||||
|
||||
result.id = '_internal_command_delegation';
|
||||
result.arguments = [id];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
fromInternal(command: modes.Command): vscode.Command {
|
||||
|
||||
if (!command) {
|
||||
return;
|
||||
}
|
||||
|
||||
const id = ObjectIdentifier.of(command);
|
||||
if (typeof id === 'number') {
|
||||
return this._heap.get<vscode.Command>(id);
|
||||
|
||||
} else {
|
||||
return {
|
||||
command: command.id,
|
||||
title: command.title,
|
||||
arguments: command.arguments
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private _executeConvertedCommand([id]: number[]) {
|
||||
const actualCmd = this._heap.get<vscode.Command>(id);
|
||||
return this._commands.executeCommand(actualCmd.command, ...actualCmd.arguments);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user