mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 11:38:51 +01:00
commands: allow transferring arraybuffers/uint8arrays over commands
This commit is contained in:
@@ -140,7 +140,7 @@ export interface MainThreadClipboardShape extends IDisposable {
|
||||
export interface MainThreadCommandsShape extends IDisposable {
|
||||
$registerCommand(id: string): void;
|
||||
$unregisterCommand(id: string): void;
|
||||
$executeCommand<T>(id: string, args: any[], retry: boolean): Promise<T | undefined>;
|
||||
$executeCommand<T>(id: string, args: any[] | SerializableObjectWithBuffers<any[]>, retry: boolean): Promise<T | undefined>;
|
||||
$getCommands(): Promise<string[]>;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
|
||||
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
|
||||
import { ISelection } from 'vs/editor/common/core/selection';
|
||||
import { TestItemImpl } from 'vs/workbench/api/common/extHostTestingPrivateApi';
|
||||
import { VSBuffer } from 'vs/base/common/buffer';
|
||||
import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier';
|
||||
|
||||
interface CommandHandler {
|
||||
callback: Function;
|
||||
@@ -84,6 +86,9 @@ export class ExtHostCommands implements ExtHostCommandsShape {
|
||||
if (Range.isIRange((obj as modes.Location).range) && URI.isUri((obj as modes.Location).uri)) {
|
||||
return extHostTypeConverter.location.to(obj);
|
||||
}
|
||||
if (obj instanceof VSBuffer) {
|
||||
return obj.buffer.buffer;
|
||||
}
|
||||
if (!Array.isArray(obj)) {
|
||||
return obj;
|
||||
}
|
||||
@@ -164,6 +169,7 @@ export class ExtHostCommands implements ExtHostCommandsShape {
|
||||
|
||||
} else {
|
||||
// automagically convert some argument types
|
||||
let hasBuffers = false;
|
||||
const toArgs = cloneAndChange(args, function (value) {
|
||||
if (value instanceof extHostTypes.Position) {
|
||||
return extHostTypeConverter.Position.from(value);
|
||||
@@ -173,6 +179,12 @@ export class ExtHostCommands implements ExtHostCommandsShape {
|
||||
return extHostTypeConverter.location.from(value);
|
||||
} else if (extHostTypes.NotebookRange.isNotebookRange(value)) {
|
||||
return extHostTypeConverter.NotebookRange.from(value);
|
||||
} else if (value instanceof ArrayBuffer) {
|
||||
hasBuffers = true;
|
||||
return VSBuffer.wrap(new Uint8Array(value));
|
||||
} else if (value instanceof Uint8Array) {
|
||||
hasBuffers = true;
|
||||
return VSBuffer.wrap(value);
|
||||
}
|
||||
if (!Array.isArray(value)) {
|
||||
return value;
|
||||
@@ -180,7 +192,7 @@ export class ExtHostCommands implements ExtHostCommandsShape {
|
||||
});
|
||||
|
||||
try {
|
||||
const result = await this._proxy.$executeCommand<T>(id, toArgs, retry);
|
||||
const result = await this._proxy.$executeCommand<T>(id, hasBuffers ? new SerializableObjectWithBuffers(toArgs) : toArgs, retry);
|
||||
return revive<any>(result);
|
||||
} catch (e) {
|
||||
// Rerun the command when it wasn't known, had arguments, and when retry
|
||||
|
||||
Reference in New Issue
Block a user