Split up ext host <-> main thread communication to separate files

This commit is contained in:
Alex Dima
2016-06-27 14:58:03 +02:00
parent fa9d70718c
commit d285fe05e1
43 changed files with 2370 additions and 2196 deletions

View File

@@ -6,14 +6,14 @@
import {IThreadService} from 'vs/workbench/services/thread/common/threadService';
import {validateConstraint} from 'vs/base/common/types';
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {IKeybindingService, ICommandHandlerDescription} from 'vs/platform/keybinding/common/keybindingService';
import {ICommandHandlerDescription} from 'vs/platform/keybinding/common/keybindingService';
import {TPromise} from 'vs/base/common/winjs.base';
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, ExtHostContext} from './extHostProtocol';
import {MainContext} from './extHostProtocol';
import {MainThreadCommands} from './mainThreadCommands';
interface CommandHandler {
callback: Function;
@@ -126,95 +126,3 @@ export class ExtHostCommands {
return TPromise.as(result);
}
}
export class MainThreadCommands {
private _threadService: IThreadService;
private _keybindingService: IKeybindingService;
private _proxy: ExtHostCommands;
constructor(
@IThreadService threadService: IThreadService,
@IKeybindingService keybindingService: IKeybindingService
) {
this._threadService = threadService;
this._keybindingService = keybindingService;
this._proxy = this._threadService.get(ExtHostContext.ExtHostCommands);
}
$registerCommand(id: string): TPromise<any> {
KeybindingsRegistry.registerCommandDesc({
id,
handler: (serviceAccessor, ...args: any[]) => {
return this._proxy.$executeContributedCommand(id, ...args);
},
weight: undefined,
when: undefined,
win: undefined,
mac: undefined,
linux: undefined,
primary: undefined,
secondary: undefined
});
return undefined;
}
$executeCommand<T>(id: string, args: any[]): Thenable<T> {
return this._keybindingService.executeCommand(id, ...args);
}
$getCommands(): Thenable<string[]> {
return TPromise.as(Object.keys(KeybindingsRegistry.getCommands()));
}
}
// --- command doc
KeybindingsRegistry.registerCommandDesc({
id: '_generateCommandsDocumentation',
handler: function(accessor) {
return accessor.get(IThreadService).get(ExtHostContext.ExtHostCommands).$getContributedCommandHandlerDescriptions().then(result => {
// add local commands
const commands = KeybindingsRegistry.getCommands();
for (let id in commands) {
let {description} = commands[id];
if (description) {
result[id] = description;
}
}
// print all as markdown
const all: string[] = [];
for (let id in result) {
all.push('`' + id + '` - ' + _generateMarkdown(result[id]));
}
console.log(all.join('\n'));
});
},
when: undefined,
weight: KeybindingsRegistry.WEIGHT.builtinExtension(0),
primary: undefined
});
function _generateMarkdown(description: string | ICommandHandlerDescription): string {
if (typeof description === 'string') {
return description;
} else {
let parts = [description.description];
parts.push('\n\n');
if (description.args) {
for (let arg of description.args) {
parts.push(`* _${arg.name}_ ${arg.description || ''}\n`);
}
}
if (description.returns) {
parts.push(`* _(returns)_ ${description.returns}`);
}
parts.push('\n\n');
return parts.join('');
}
}