提交 cb865f93 编写于 作者: J Johannes Rieken

remove extHostHeapService, use normal cache in commands converter, #74846

上级 8e91c0db
......@@ -473,7 +473,7 @@ export class ExtHostApiCommands {
});
}
private _executeCodeActionProvider(resource: URI, range: types.Range, kind?: string): Promise<(vscode.CodeAction | vscode.Command)[] | undefined> {
private _executeCodeActionProvider(resource: URI, range: types.Range, kind?: string): Promise<(vscode.CodeAction | vscode.Command | undefined)[] | undefined> {
const args = {
resource,
range: typeConverters.Range.from(range),
......
......@@ -9,7 +9,6 @@ import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import * as extHostTypeConverter from 'vs/workbench/api/common/extHostTypeConverters';
import { cloneAndChange } from 'vs/base/common/objects';
import { MainContext, MainThreadCommandsShape, ExtHostCommandsShape, ObjectIdentifier, IMainContext, CommandDto } from './extHost.protocol';
import { ExtHostHeapService } from 'vs/workbench/api/common/extHostHeapService';
import { isNonEmptyArray } from 'vs/base/common/arrays';
import * as modes from 'vs/editor/common/modes';
import * as vscode from 'vscode';
......@@ -40,12 +39,11 @@ export class ExtHostCommands implements ExtHostCommandsShape {
constructor(
mainContext: IMainContext,
heapService: ExtHostHeapService,
logService: ILogService
) {
this._proxy = mainContext.getProxy(MainContext.MainThreadCommands);
this._logService = logService;
this._converter = new CommandsConverter(this, heapService);
this._converter = new CommandsConverter(this);
this._argumentProcessors = [
{
processArgument(a) {
......@@ -201,14 +199,14 @@ export class ExtHostCommands implements ExtHostCommandsShape {
export class CommandsConverter {
private readonly _delegatingCommandId: string;
private _commands: ExtHostCommands;
private _heap: ExtHostHeapService;
private readonly _commands: ExtHostCommands;
private readonly _cache = new Map<number, vscode.Command>();
private _cachIdPool = 0;
// --- conversion between internal and api commands
constructor(commands: ExtHostCommands, heap: ExtHostHeapService) {
constructor(commands: ExtHostCommands) {
this._delegatingCommandId = `_internal_command_delegation_${Date.now()}`;
this._commands = commands;
this._heap = heap;
this._commands.registerCommand(true, this._delegatingCommandId, this._executeConvertedCommand, this);
}
......@@ -229,8 +227,9 @@ export class CommandsConverter {
// we have a contributed command with arguments. that
// means we don't want to send the arguments around
const id = this._heap.keep(command);
disposables.add(toDisposable(() => this._heap.delete(id)));
const id = ++this._cachIdPool;
this._cache.set(id, command);
disposables.add(toDisposable(() => this._cache.delete(id)));
result.$ident = id;
result.id = this._delegatingCommandId;
......@@ -260,7 +259,8 @@ export class CommandsConverter {
// we have a contributed command with arguments. that
// means we don't want to send the arguments around
const id = this._heap.keep(command);
const id = ++this._cachIdPool;
this._cache.set(id, command);
result.$ident = id;
result.id = this._delegatingCommandId;
......@@ -274,11 +274,11 @@ export class CommandsConverter {
return result;
}
fromInternal(command: modes.Command): vscode.Command {
fromInternal(command: modes.Command): vscode.Command | undefined {
const id = ObjectIdentifier.of(command);
if (typeof id === 'number') {
return this._heap.get<vscode.Command>(id);
return this._cache.get(id);
} else {
return {
......@@ -290,7 +290,10 @@ export class CommandsConverter {
}
private _executeConvertedCommand<R>(...args: any[]): Promise<R> {
const actualCmd = this._heap.get<vscode.Command>(args[0]);
const actualCmd = this._cache.get(args[0]);
if (!actualCmd) {
return Promise.reject('actual command NOT FOUND');
}
return this._commands.executeCommand(actualCmd.command, ...(actualCmd.arguments || []));
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ExtHostHeapServiceShape } from './extHost.protocol';
export class ExtHostHeapService implements ExtHostHeapServiceShape {
private static _idPool = 0;
private _data = new Map<number, any>();
keep(obj: any): number {
const id = ExtHostHeapService._idPool++;
this._data.set(id, obj);
return id;
}
delete(id: number): boolean {
return this._data.delete(id);
}
get<T>(id: number): T {
return this._data.get(id);
}
$onGarbageCollection(ids: number[]): void {
for (const id of ids) {
this.delete(id);
}
}
}
......@@ -33,7 +33,6 @@ import { ExtensionActivatedByAPI } from 'vs/workbench/api/common/extHostExtensio
import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService';
import { ExtHostFileSystem } from 'vs/workbench/api/common/extHostFileSystem';
import { ExtHostFileSystemEventService } from 'vs/workbench/api/common/extHostFileSystemEventService';
import { ExtHostHeapService } from 'vs/workbench/api/common/extHostHeapService';
import { ExtHostLanguageFeatures } from 'vs/workbench/api/common/extHostLanguageFeatures';
import { ExtHostLanguages } from 'vs/workbench/api/common/extHostLanguages';
import { ExtHostLogService } from 'vs/workbench/api/common/extHostLogService';
......@@ -97,7 +96,6 @@ export function createApiFactory(
// Addressable instances
rpcProtocol.set(ExtHostContext.ExtHostLogService, extHostLogService);
const extHostHeapService = rpcProtocol.set(ExtHostContext.ExtHostHeapService, new ExtHostHeapService());
const extHostDecorations = rpcProtocol.set(ExtHostContext.ExtHostDecorations, new ExtHostDecorations(rpcProtocol));
const extHostWebviews = rpcProtocol.set(ExtHostContext.ExtHostWebviews, new ExtHostWebviews(rpcProtocol));
const extHostUrls = rpcProtocol.set(ExtHostContext.ExtHostUrls, new ExtHostUrls(rpcProtocol));
......@@ -106,7 +104,7 @@ export function createApiFactory(
const extHostDocumentContentProviders = rpcProtocol.set(ExtHostContext.ExtHostDocumentContentProviders, new ExtHostDocumentContentProvider(rpcProtocol, extHostDocumentsAndEditors, extHostLogService));
const extHostDocumentSaveParticipant = rpcProtocol.set(ExtHostContext.ExtHostDocumentSaveParticipant, new ExtHostDocumentSaveParticipant(extHostLogService, extHostDocuments, rpcProtocol.getProxy(MainContext.MainThreadTextEditors)));
const extHostEditors = rpcProtocol.set(ExtHostContext.ExtHostEditors, new ExtHostEditors(rpcProtocol, extHostDocumentsAndEditors));
const extHostCommands = rpcProtocol.set(ExtHostContext.ExtHostCommands, new ExtHostCommands(rpcProtocol, extHostHeapService, extHostLogService));
const extHostCommands = rpcProtocol.set(ExtHostContext.ExtHostCommands, new ExtHostCommands(rpcProtocol, extHostLogService));
const extHostTreeViews = rpcProtocol.set(ExtHostContext.ExtHostTreeViews, new ExtHostTreeViews(rpcProtocol.getProxy(MainContext.MainThreadTreeViews), extHostCommands, extHostLogService));
rpcProtocol.set(ExtHostContext.ExtHostWorkspace, extHostWorkspace);
rpcProtocol.set(ExtHostContext.ExtHostConfiguration, extHostConfiguration);
......
......@@ -18,7 +18,6 @@ import { ExtHostLanguageFeatures } from 'vs/workbench/api/common/extHostLanguage
import { MainThreadLanguageFeatures } from 'vs/workbench/api/browser/mainThreadLanguageFeatures';
import { ExtHostApiCommands } from 'vs/workbench/api/common/extHostApiCommands';
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
import { ExtHostHeapService } from 'vs/workbench/api/common/extHostHeapService';
import { MainThreadCommands } from 'vs/workbench/api/browser/mainThreadCommands';
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
......@@ -107,9 +106,7 @@ suite('ExtHostLanguageFeatureCommands', function () {
const extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
rpcProtocol.set(ExtHostContext.ExtHostDocuments, extHostDocuments);
const heapService = new ExtHostHeapService();
commands = new ExtHostCommands(rpcProtocol, heapService, new NullLogService());
commands = new ExtHostCommands(rpcProtocol, new NullLogService());
rpcProtocol.set(ExtHostContext.ExtHostCommands, commands);
rpcProtocol.set(MainContext.MainThreadCommands, inst.createInstance(MainThreadCommands, rpcProtocol));
ExtHostApiCommands.register(commands);
......
......@@ -26,7 +26,7 @@ suite('ExtHostCommands', function () {
}
};
const commands = new ExtHostCommands(SingleProxyRPCProtocol(shape), undefined!, new NullLogService());
const commands = new ExtHostCommands(SingleProxyRPCProtocol(shape), new NullLogService());
commands.registerCommand(true, 'foo', (): any => { }).dispose();
assert.equal(lastUnregister!, 'foo');
assert.equal(CommandsRegistry.getCommand('foo'), undefined);
......@@ -46,7 +46,7 @@ suite('ExtHostCommands', function () {
}
};
const commands = new ExtHostCommands(SingleProxyRPCProtocol(shape), undefined!, new NullLogService());
const commands = new ExtHostCommands(SingleProxyRPCProtocol(shape), new NullLogService());
const reg = commands.registerCommand(true, 'foo', (): any => { });
reg.dispose();
reg.dispose();
......
......@@ -36,7 +36,6 @@ import { getDocumentFormattingEditsUntilResult, getDocumentRangeFormattingEditsU
import { getLinks } from 'vs/editor/contrib/links/getLinks';
import { MainContext, ExtHostContext } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostDiagnostics } from 'vs/workbench/api/common/extHostDiagnostics';
import { ExtHostHeapService } from 'vs/workbench/api/common/extHostHeapService';
import * as vscode from 'vscode';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { NullLogService } from 'vs/platform/log/common/log';
......@@ -100,9 +99,7 @@ suite('ExtHostLanguageFeatures', function () {
const extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
rpcProtocol.set(ExtHostContext.ExtHostDocuments, extHostDocuments);
const heapService = new ExtHostHeapService();
const commands = new ExtHostCommands(rpcProtocol, heapService, new NullLogService());
const commands = new ExtHostCommands(rpcProtocol, new NullLogService());
rpcProtocol.set(ExtHostContext.ExtHostCommands, commands);
rpcProtocol.set(MainContext.MainThreadCommands, inst.createInstance(MainThreadCommands, rpcProtocol));
......
......@@ -11,7 +11,6 @@ import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
import { MainThreadTreeViewsShape, MainContext } from 'vs/workbench/api/common/extHost.protocol';
import { TreeDataProvider, TreeItem } from 'vscode';
import { TestRPCProtocol } from './testRPCProtocol';
import { ExtHostHeapService } from 'vs/workbench/api/common/extHostHeapService';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { MainThreadCommands } from 'vs/workbench/api/browser/mainThreadCommands';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
......@@ -72,7 +71,7 @@ suite('ExtHostTreeView', function () {
rpcProtocol.set(MainContext.MainThreadCommands, inst.createInstance(MainThreadCommands, rpcProtocol));
target = new RecordingShape();
testObject = new ExtHostTreeViews(target, new ExtHostCommands(rpcProtocol, new ExtHostHeapService(), new NullLogService()), new NullLogService());
testObject = new ExtHostTreeViews(target, new ExtHostCommands(rpcProtocol, new NullLogService()), new NullLogService());
onDidChangeTreeNode = new Emitter<{ key: string }>();
onDidChangeTreeNodeWithId = new Emitter<{ key: string }>();
testObject.createTreeView('testNodeTreeProvider', { treeDataProvider: aNodeTreeDataProvider() }, { enableProposedApi: true } as IExtensionDescription);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册