mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-07 07:16:41 +01:00
protocol: refactor to use enum for marshalled object ids
This commit is contained in:
@@ -17,15 +17,31 @@ export function parse(text: string): any {
|
||||
return data;
|
||||
}
|
||||
|
||||
export const enum MarshalledId {
|
||||
Uri = 1,
|
||||
Regexp,
|
||||
ScmResource,
|
||||
ScmResourceGroup,
|
||||
ScmProvider,
|
||||
CommentController,
|
||||
CommentThread,
|
||||
CommentThreadReply,
|
||||
CommentNode,
|
||||
CommentThreadNode,
|
||||
TimelineActionContext,
|
||||
NotebookCellActionContext,
|
||||
TestItemContext,
|
||||
}
|
||||
|
||||
export interface MarshalledObject {
|
||||
$mid: number;
|
||||
$mid: MarshalledId;
|
||||
}
|
||||
|
||||
function replacer(key: string, value: any): any {
|
||||
// URI is done via toJSON-member
|
||||
if (value instanceof RegExp) {
|
||||
return {
|
||||
$mid: 2,
|
||||
$mid: MarshalledId.Regexp,
|
||||
source: value.source,
|
||||
flags: regExpFlags(value),
|
||||
};
|
||||
@@ -49,8 +65,8 @@ export function revive<T = any>(obj: any, depth = 0): Revived<T> {
|
||||
if (typeof obj === 'object') {
|
||||
|
||||
switch ((<MarshalledObject>obj).$mid) {
|
||||
case 1: return <any>URI.revive(obj);
|
||||
case 2: return <any>new RegExp(obj.source, obj.flags);
|
||||
case MarshalledId.Uri: return <any>URI.revive(obj);
|
||||
case MarshalledId.Regexp: return <any>new RegExp(obj.source, obj.flags);
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
import { CharCode } from 'vs/base/common/charCode';
|
||||
import * as paths from 'vs/base/common/path';
|
||||
import { MarshalledId } from 'vs/base/common/marshalling';
|
||||
|
||||
const _schemePattern = /^\w[\w\d+.-]*$/;
|
||||
const _singleSlashStart = /^\//;
|
||||
@@ -406,7 +407,7 @@ export interface UriComponents {
|
||||
}
|
||||
|
||||
interface UriState extends UriComponents {
|
||||
$mid: number;
|
||||
$mid: MarshalledId.Uri;
|
||||
external: string;
|
||||
fsPath: string;
|
||||
_sep: 1 | undefined;
|
||||
@@ -441,7 +442,7 @@ class Uri extends URI {
|
||||
|
||||
override toJSON(): UriComponents {
|
||||
const res = <UriState>{
|
||||
$mid: 1
|
||||
$mid: MarshalledId.Uri
|
||||
};
|
||||
// cached state
|
||||
if (this._fsPath) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { MarshalledObject } from 'vs/base/common/marshalling';
|
||||
import { MarshalledId, MarshalledObject } from 'vs/base/common/marshalling';
|
||||
|
||||
export interface IURITransformer {
|
||||
transformIncoming(uri: UriComponents): UriComponents;
|
||||
@@ -118,7 +118,7 @@ function _transformIncomingURIs(obj: any, transformer: IURITransformer, revive:
|
||||
|
||||
if (typeof obj === 'object') {
|
||||
|
||||
if ((<MarshalledObject>obj).$mid === 1) {
|
||||
if ((<MarshalledObject>obj).$mid === MarshalledId.Uri) {
|
||||
return revive ? URI.revive(transformer.transformIncoming(obj)) : transformer.transformIncoming(obj);
|
||||
}
|
||||
|
||||
@@ -152,4 +152,4 @@ export function transformAndReviveIncomingURIs<T>(obj: T, transformer: IURITrans
|
||||
return obj;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneCont
|
||||
import { Codicon } from 'vs/base/common/codicons';
|
||||
import { registerIcon } from 'vs/platform/theme/common/iconRegistry';
|
||||
import { localize } from 'vs/nls';
|
||||
import { MarshalledId } from 'vs/base/common/marshalling';
|
||||
|
||||
|
||||
export class MainThreadCommentThread implements modes.CommentThread {
|
||||
@@ -154,7 +155,7 @@ export class MainThreadCommentThread implements modes.CommentThread {
|
||||
|
||||
toJSON(): any {
|
||||
return {
|
||||
$mid: 7,
|
||||
$mid: MarshalledId.CommentThread,
|
||||
commentControlHandle: this.controllerHandle,
|
||||
commentThreadHandle: this.commentThreadHandle,
|
||||
};
|
||||
@@ -347,7 +348,7 @@ export class MainThreadCommentController {
|
||||
|
||||
toJSON(): any {
|
||||
return {
|
||||
$mid: 6,
|
||||
$mid: MarshalledId.CommentController,
|
||||
handle: this.handle
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Command } from 'vs/editor/common/modes';
|
||||
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
|
||||
import { ISplice, Sequence } from 'vs/base/common/sequence';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { MarshalledId } from 'vs/base/common/marshalling';
|
||||
|
||||
class MainThreadSCMResourceGroup implements ISCMResourceGroup {
|
||||
|
||||
@@ -36,7 +37,7 @@ class MainThreadSCMResourceGroup implements ISCMResourceGroup {
|
||||
|
||||
toJSON(): any {
|
||||
return {
|
||||
$mid: 4,
|
||||
$mid: MarshalledId.ScmResourceGroup,
|
||||
sourceControlHandle: this.sourceControlHandle,
|
||||
groupHandle: this.handle
|
||||
};
|
||||
@@ -78,7 +79,7 @@ class MainThreadSCMResource implements ISCMResource {
|
||||
|
||||
toJSON(): any {
|
||||
return {
|
||||
$mid: 3,
|
||||
$mid: MarshalledId.ScmResource,
|
||||
sourceControlHandle: this.sourceControlHandle,
|
||||
groupHandle: this.groupHandle,
|
||||
handle: this.handle
|
||||
@@ -256,7 +257,7 @@ class MainThreadSCMProvider implements ISCMProvider {
|
||||
|
||||
toJSON(): any {
|
||||
return {
|
||||
$mid: 5,
|
||||
$mid: MarshalledId.ScmProvider,
|
||||
handle: this.handle
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { debounce } from 'vs/base/common/decorators';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { DisposableStore, IDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
|
||||
import { MarshalledId } from 'vs/base/common/marshalling';
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { IRange } from 'vs/editor/common/core/range';
|
||||
import * as modes from 'vs/editor/common/modes';
|
||||
@@ -41,7 +42,7 @@ export class ExtHostComments implements ExtHostCommentsShape, IDisposable {
|
||||
|
||||
commands.registerArgumentProcessor({
|
||||
processArgument: arg => {
|
||||
if (arg && arg.$mid === 6) {
|
||||
if (arg && arg.$mid === MarshalledId.CommentController) {
|
||||
const commentController = this._commentControllers.get(arg.handle);
|
||||
|
||||
if (!commentController) {
|
||||
@@ -49,7 +50,7 @@ export class ExtHostComments implements ExtHostCommentsShape, IDisposable {
|
||||
}
|
||||
|
||||
return commentController;
|
||||
} else if (arg && arg.$mid === 7) {
|
||||
} else if (arg && arg.$mid === MarshalledId.CommentThread) {
|
||||
const commentController = this._commentControllers.get(arg.commentControlHandle);
|
||||
|
||||
if (!commentController) {
|
||||
@@ -63,7 +64,7 @@ export class ExtHostComments implements ExtHostCommentsShape, IDisposable {
|
||||
}
|
||||
|
||||
return commentThread;
|
||||
} else if (arg && arg.$mid === 8) {
|
||||
} else if (arg && arg.$mid === MarshalledId.CommentThreadReply) {
|
||||
const commentController = this._commentControllers.get(arg.thread.commentControlHandle);
|
||||
|
||||
if (!commentController) {
|
||||
@@ -80,7 +81,7 @@ export class ExtHostComments implements ExtHostCommentsShape, IDisposable {
|
||||
thread: commentThread,
|
||||
text: arg.text
|
||||
};
|
||||
} else if (arg && arg.$mid === 9) {
|
||||
} else if (arg && arg.$mid === MarshalledId.CommentNode) {
|
||||
const commentController = this._commentControllers.get(arg.thread.commentControlHandle);
|
||||
|
||||
if (!commentController) {
|
||||
@@ -103,7 +104,7 @@ export class ExtHostComments implements ExtHostCommentsShape, IDisposable {
|
||||
|
||||
return comment;
|
||||
|
||||
} else if (arg && arg.$mid === 10) {
|
||||
} else if (arg && arg.$mid === MarshalledId.CommentThreadNode) {
|
||||
const commentController = this._commentControllers.get(arg.thread.commentControlHandle);
|
||||
|
||||
if (!commentController) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import { IRelativePattern } from 'vs/base/common/glob';
|
||||
import { hash } from 'vs/base/common/hash';
|
||||
import { DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { ResourceMap } from 'vs/base/common/map';
|
||||
import { MarshalledId } from 'vs/base/common/marshalling';
|
||||
import { isFalsyOrWhitespace } from 'vs/base/common/strings';
|
||||
import { assertIsDefined } from 'vs/base/common/types';
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
@@ -91,7 +92,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
|
||||
commands.registerArgumentProcessor({
|
||||
// Serialized INotebookCellActionContext
|
||||
processArgument: (arg) => {
|
||||
if (arg && arg.$mid === 12) {
|
||||
if (arg && arg.$mid === MarshalledId.NotebookCellActionContext) {
|
||||
const notebookUri = arg.notebookEditor?.notebookUri;
|
||||
const cellHandle = arg.cell.handle;
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
|
||||
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { MarshalledId } from 'vs/base/common/marshalling';
|
||||
|
||||
type ProviderHandle = number;
|
||||
type GroupHandle = number;
|
||||
@@ -660,7 +661,7 @@ export class ExtHostSCM implements ExtHostSCMShape {
|
||||
|
||||
_commands.registerArgumentProcessor({
|
||||
processArgument: arg => {
|
||||
if (arg && arg.$mid === 3) {
|
||||
if (arg && arg.$mid === MarshalledId.ScmResource) {
|
||||
const sourceControl = this._sourceControls.get(arg.sourceControlHandle);
|
||||
|
||||
if (!sourceControl) {
|
||||
@@ -674,7 +675,7 @@ export class ExtHostSCM implements ExtHostSCMShape {
|
||||
}
|
||||
|
||||
return group.getResourceState(arg.handle);
|
||||
} else if (arg && arg.$mid === 4) {
|
||||
} else if (arg && arg.$mid === MarshalledId.ScmResourceGroup) {
|
||||
const sourceControl = this._sourceControls.get(arg.sourceControlHandle);
|
||||
|
||||
if (!sourceControl) {
|
||||
@@ -682,7 +683,7 @@ export class ExtHostSCM implements ExtHostSCMShape {
|
||||
}
|
||||
|
||||
return sourceControl.getResourceGroup(arg.groupHandle);
|
||||
} else if (arg && arg.$mid === 5) {
|
||||
} else if (arg && arg.$mid === MarshalledId.ScmProvider) {
|
||||
const sourceControl = this._sourceControls.get(arg.handle);
|
||||
|
||||
if (!sourceControl) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { CommandsConverter, ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
|
||||
import { ThemeIcon } from 'vs/workbench/api/common/extHostTypes';
|
||||
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
|
||||
import { MarshalledId } from 'vs/base/common/marshalling';
|
||||
|
||||
export interface IExtHostTimeline extends ExtHostTimelineShape {
|
||||
readonly _serviceBrand: undefined;
|
||||
@@ -38,7 +39,7 @@ export class ExtHostTimeline implements IExtHostTimeline {
|
||||
|
||||
commands.registerArgumentProcessor({
|
||||
processArgument: arg => {
|
||||
if (arg && arg.$mid === 11) {
|
||||
if (arg && arg.$mid === MarshalledId.TimelineActionContext) {
|
||||
const uri = arg.uri === undefined ? undefined : URI.revive(arg.uri);
|
||||
return this._itemsBySourceAndUriMap.get(arg.source)?.get(getUriKey(uri))?.get(arg.handle);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import { MOUSE_CURSOR_TEXT_CSS_CLASS_NAME } from 'vs/base/browser/ui/mouseCursor
|
||||
import { ActionViewItem } from 'vs/base/browser/ui/actionbar/actionViewItems';
|
||||
import { DropdownMenuActionViewItem } from 'vs/base/browser/ui/dropdown/dropdownActionViewItem';
|
||||
import { Codicon } from 'vs/base/common/codicons';
|
||||
import { MarshalledId } from 'vs/base/common/marshalling';
|
||||
|
||||
export class CommentNode extends Disposable {
|
||||
private _domNode: HTMLElement;
|
||||
@@ -170,7 +171,7 @@ export class CommentNode extends Disposable {
|
||||
this.toolbar.context = {
|
||||
thread: this.commentThread,
|
||||
commentUniqueId: this.comment.uniqueIdInThread,
|
||||
$mid: 9
|
||||
$mid: MarshalledId.CommentNode
|
||||
};
|
||||
|
||||
this.registerActionBarListeners(this._actionsToolbarContainer);
|
||||
@@ -433,7 +434,7 @@ export class CommentNode extends Disposable {
|
||||
thread: this.commentThread,
|
||||
commentUniqueId: this.comment.uniqueIdInThread,
|
||||
text: text,
|
||||
$mid: 10
|
||||
$mid: MarshalledId.CommentThreadNode
|
||||
});
|
||||
|
||||
this.removeCommentEditor();
|
||||
|
||||
@@ -48,6 +48,7 @@ import { MOUSE_CURSOR_TEXT_CSS_CLASS_NAME } from 'vs/base/browser/ui/mouseCursor
|
||||
import { PANEL_BORDER } from 'vs/workbench/common/theme';
|
||||
import { registerIcon } from 'vs/platform/theme/common/iconRegistry';
|
||||
import { Codicon } from 'vs/base/common/codicons';
|
||||
import { MarshalledId } from 'vs/base/common/marshalling';
|
||||
|
||||
|
||||
const collapseIcon = registerIcon('review-comment-collapse', Codicon.chevronUp, nls.localize('collapseIcon', 'Icon to collapse a review comment.'));
|
||||
@@ -666,7 +667,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
|
||||
action.run({
|
||||
thread: this._commentThread,
|
||||
text: this._commentReplyComponent?.editor.getValue(),
|
||||
$mid: 8
|
||||
$mid: MarshalledId.CommentThreadReply
|
||||
});
|
||||
|
||||
this.hideReplyArea();
|
||||
|
||||
@@ -9,6 +9,7 @@ import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
|
||||
import { Action, IAction } from 'vs/base/common/actions';
|
||||
import { IMarkdownString } from 'vs/base/common/htmlContent';
|
||||
import { Disposable, DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
|
||||
import { MarshalledId } from 'vs/base/common/marshalling';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import * as nls from 'vs/nls';
|
||||
import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
|
||||
@@ -334,7 +335,7 @@ export class CellOutputElement extends Disposable {
|
||||
ui: true,
|
||||
cell: this.output.cellViewModel as ICellViewModel,
|
||||
notebookEditor: this.notebookEditor,
|
||||
$mid: 12
|
||||
$mid: MarshalledId.NotebookCellActionContext
|
||||
};
|
||||
|
||||
// TODO: This could probably be a real registered action, but it has to talk to this output element
|
||||
|
||||
@@ -14,6 +14,7 @@ import { Action, IAction } from 'vs/base/common/actions';
|
||||
import * as Codicons from 'vs/base/common/codicons';
|
||||
import { Color } from 'vs/base/common/color';
|
||||
import { combinedDisposable, Disposable, DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { MarshalledId } from 'vs/base/common/marshalling';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
|
||||
@@ -502,7 +503,7 @@ export class MarkupCellRenderer extends AbstractCellRenderer implements IListRen
|
||||
ui: true,
|
||||
cell: element,
|
||||
notebookEditor: this.notebookEditor,
|
||||
$mid: 12
|
||||
$mid: MarshalledId.NotebookCellActionContext
|
||||
};
|
||||
templateData.toolbar.context = toolbarContext;
|
||||
templateData.deleteToolbar.context = toolbarContext;
|
||||
@@ -1047,7 +1048,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
|
||||
cell: element,
|
||||
cellTemplate: templateData,
|
||||
notebookEditor: this.notebookEditor,
|
||||
$mid: 12
|
||||
$mid: MarshalledId.NotebookCellActionContext
|
||||
};
|
||||
templateData.toolbar.context = toolbarContext;
|
||||
templateData.runToolbar.context = toolbarContext;
|
||||
|
||||
@@ -45,6 +45,7 @@ import { ColorScheme } from 'vs/platform/theme/common/theme';
|
||||
import { Codicon } from 'vs/base/common/codicons';
|
||||
import { registerIcon } from 'vs/platform/theme/common/iconRegistry';
|
||||
import { API_OPEN_DIFF_EDITOR_COMMAND_ID, API_OPEN_EDITOR_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands';
|
||||
import { MarshalledId } from 'vs/base/common/marshalling';
|
||||
|
||||
const ItemHeight = 22;
|
||||
|
||||
@@ -1060,7 +1061,7 @@ class TimelineActionRunner extends ActionRunner {
|
||||
|
||||
await action.run(...[
|
||||
{
|
||||
$mid: 11,
|
||||
$mid: MarshalledId.TimelineActionContext,
|
||||
handle: item.handle,
|
||||
source: item.source,
|
||||
uri: uri
|
||||
|
||||
@@ -14,6 +14,7 @@ import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { LazyPromise } from 'vs/workbench/services/extensions/common/lazyPromise';
|
||||
import { IRPCProtocol, ProxyIdentifier, getStringIdentifierForProxy } from 'vs/workbench/services/extensions/common/proxyIdentifier';
|
||||
import { VSBuffer } from 'vs/base/common/buffer';
|
||||
import { MarshalledId } from 'vs/base/common/marshalling';
|
||||
|
||||
export interface JSONStringifyReplacer {
|
||||
(key: string, value: any): any;
|
||||
@@ -36,7 +37,7 @@ function createURIReplacer(transformer: IURITransformer | null): JSONStringifyRe
|
||||
return null;
|
||||
}
|
||||
return (key: string, value: any): any => {
|
||||
if (value && value.$mid === 1) {
|
||||
if (value && value.$mid === MarshalledId.Uri) {
|
||||
return transformer.transformOutgoing(value);
|
||||
}
|
||||
return value;
|
||||
|
||||
@@ -9,6 +9,7 @@ import * as types from 'vs/workbench/api/common/extHostTypes';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
import { assertType } from 'vs/base/common/types';
|
||||
import { Mimes } from 'vs/base/common/mime';
|
||||
import { MarshalledId } from 'vs/base/common/marshalling';
|
||||
|
||||
function assertToJSON(a: any, expected: any) {
|
||||
const raw = JSON.stringify(a);
|
||||
@@ -22,14 +23,14 @@ suite('ExtHostTypes', function () {
|
||||
|
||||
let uri = URI.parse('file:///path/test.file');
|
||||
assert.deepStrictEqual(uri.toJSON(), {
|
||||
$mid: 1,
|
||||
$mid: MarshalledId.Uri,
|
||||
scheme: 'file',
|
||||
path: '/path/test.file'
|
||||
});
|
||||
|
||||
assert.ok(uri.fsPath);
|
||||
assert.deepStrictEqual(uri.toJSON(), {
|
||||
$mid: 1,
|
||||
$mid: MarshalledId.Uri,
|
||||
scheme: 'file',
|
||||
path: '/path/test.file',
|
||||
fsPath: '/path/test.file'.replace(/\//g, isWindows ? '\\' : '/'),
|
||||
@@ -38,7 +39,7 @@ suite('ExtHostTypes', function () {
|
||||
|
||||
assert.ok(uri.toString());
|
||||
assert.deepStrictEqual(uri.toJSON(), {
|
||||
$mid: 1,
|
||||
$mid: MarshalledId.Uri,
|
||||
scheme: 'file',
|
||||
path: '/path/test.file',
|
||||
fsPath: '/path/test.file'.replace(/\//g, isWindows ? '\\' : '/'),
|
||||
|
||||
Reference in New Issue
Block a user