From 1ec2438d57fefc8216f14b44573fde84418d10fa Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Wed, 13 Dec 2017 17:01:09 +0100 Subject: [PATCH] Remove usage of CustomMarshaller for MainThreadEditors (#40169) --- .../editor/browser/services/codeEditorServiceImpl.ts | 12 +++++++----- src/vs/editor/common/editorCommon.ts | 6 +++--- .../api/electron-browser/mainThreadEditors.ts | 9 +++++---- src/vs/workbench/api/node/extHost.protocol.ts | 10 +++++----- src/vs/workbench/api/node/extHostTextEditor.ts | 2 +- .../api/extHostDocumentSaveParticipant.test.ts | 5 +++-- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/vs/editor/browser/services/codeEditorServiceImpl.ts b/src/vs/editor/browser/services/codeEditorServiceImpl.ts index 5dfe1c8c4c5..72900c38be9 100644 --- a/src/vs/editor/browser/services/codeEditorServiceImpl.ts +++ b/src/vs/editor/browser/services/codeEditorServiceImpl.ts @@ -372,10 +372,12 @@ class DecorationCSSRules { if (typeof opts !== 'undefined') { this.collectBorderSettingsCSSText(opts, cssTextArr); - if (typeof opts.contentIconPath === 'string') { - cssTextArr.push(strings.format(_CSS_MAP.contentIconPath, URI.file(opts.contentIconPath).toString().replace(/'/g, '%27'))); - } else if (opts.contentIconPath instanceof URI) { - cssTextArr.push(strings.format(_CSS_MAP.contentIconPath, opts.contentIconPath.toString(true).replace(/'/g, '%27'))); + if (typeof opts.contentIconPath !== 'undefined') { + if (typeof opts.contentIconPath === 'string') { + cssTextArr.push(strings.format(_CSS_MAP.contentIconPath, URI.file(opts.contentIconPath).toString().replace(/'/g, '%27'))); + } else { + cssTextArr.push(strings.format(_CSS_MAP.contentIconPath, URI.revive(opts.contentIconPath).toString(true).replace(/'/g, '%27'))); + } } if (typeof opts.contentText === 'string') { const truncated = opts.contentText.match(/^.*$/m)[0]; // only take first line @@ -405,7 +407,7 @@ class DecorationCSSRules { if (typeof opts.gutterIconPath === 'string') { cssTextArr.push(strings.format(_CSS_MAP.gutterIconPath, URI.file(opts.gutterIconPath).toString())); } else { - cssTextArr.push(strings.format(_CSS_MAP.gutterIconPath, opts.gutterIconPath.toString(true).replace(/'/g, '%27'))); + cssTextArr.push(strings.format(_CSS_MAP.gutterIconPath, URI.revive(opts.gutterIconPath).toString(true).replace(/'/g, '%27'))); } if (typeof opts.gutterIconSize !== 'undefined') { cssTextArr.push(strings.format(_CSS_MAP.gutterIconSize, opts.gutterIconSize)); diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index 6a67ca9f218..063bf5aad09 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -5,7 +5,7 @@ 'use strict'; import { IMarkdownString } from 'vs/base/common/htmlContent'; -import URI from 'vs/base/common/uri'; +import URI, { UriComponents } from 'vs/base/common/uri'; import { TPromise } from 'vs/base/common/winjs.base'; import { LanguageId, LanguageIdentifier } from 'vs/editor/common/modes'; import { LineTokens } from 'vs/editor/common/core/lineTokens'; @@ -1565,7 +1565,7 @@ export interface IThemeDecorationRenderOptions { color?: string | ThemeColor; letterSpacing?: string; - gutterIconPath?: string | URI; + gutterIconPath?: string | UriComponents; gutterIconSize?: string; overviewRulerColor?: string | ThemeColor; @@ -1579,7 +1579,7 @@ export interface IThemeDecorationRenderOptions { */ export interface IContentDecorationRenderOptions { contentText?: string; - contentIconPath?: string | URI; + contentIconPath?: string | UriComponents; border?: string; borderColor?: string | ThemeColor; diff --git a/src/vs/workbench/api/electron-browser/mainThreadEditors.ts b/src/vs/workbench/api/electron-browser/mainThreadEditors.ts index a2928052ac8..ed13fafb7ce 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadEditors.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadEditors.ts @@ -176,11 +176,11 @@ export class MainThreadEditors implements MainThreadEditorsShape { return TPromise.as(null); } - $trySetDecorationsFast(id: string, key: string, ranges: string): TPromise { + $trySetDecorationsFast(id: string, key: string, ranges: number[]): TPromise { if (!this._documentsAndEditors.getEditor(id)) { return TPromise.wrapError(disposed(`TextEditor(${id})`)); } - this._documentsAndEditors.getEditor(id).setDecorationsFast(key, /*TODO: marshaller is too slow*/JSON.parse(ranges)); + this._documentsAndEditors.getEditor(id).setDecorationsFast(key, ranges); return TPromise.as(null); } @@ -213,7 +213,8 @@ export class MainThreadEditors implements MainThreadEditorsShape { for (let i = 0, len = workspaceResourceEdits.length; i < len; i++) { const workspaceResourceEdit = workspaceResourceEdits[i]; if (workspaceResourceEdit.modelVersionId) { - let model = this._modelService.getModel(workspaceResourceEdit.resource); + const uri = URI.revive(workspaceResourceEdit.resource); + let model = this._modelService.getModel(uri); if (model && model.getVersionId() !== workspaceResourceEdit.modelVersionId) { // model changed in the meantime return TPromise.as(false); @@ -225,7 +226,7 @@ export class MainThreadEditors implements MainThreadEditorsShape { let resourceEdits: IResourceEdit[] = []; for (let i = 0, len = workspaceResourceEdits.length; i < len; i++) { const workspaceResourceEdit = workspaceResourceEdits[i]; - const uri = workspaceResourceEdit.resource; + const uri = URI.revive(workspaceResourceEdit.resource); const edits = workspaceResourceEdit.edits; for (let j = 0, lenJ = edits.length; j < lenJ; j++) { diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 1385a5226ea..3896616d934 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -14,7 +14,7 @@ import { import * as vscode from 'vscode'; -import URI from 'vs/base/common/uri'; +import URI, { UriComponents } from 'vs/base/common/uri'; import Severity from 'vs/base/common/severity'; import { TPromise } from 'vs/base/common/winjs.base'; @@ -200,7 +200,7 @@ export interface ITextDocumentShowOptions { } export interface IWorkspaceResourceEdit { - resource: URI; + resource: UriComponents; modelVersionId?: number; edits: { range?: IRange; @@ -210,14 +210,14 @@ export interface IWorkspaceResourceEdit { } export interface MainThreadEditorsShape extends IDisposable { - $tryShowTextDocument(resource: URI, options: ITextDocumentShowOptions): TPromise; + $tryShowTextDocument(resource: UriComponents, options: ITextDocumentShowOptions): TPromise; $registerTextEditorDecorationType(key: string, options: editorCommon.IDecorationRenderOptions): void; $removeTextEditorDecorationType(key: string): void; $tryShowEditor(id: string, position: EditorPosition): TPromise; $tryHideEditor(id: string): TPromise; $trySetOptions(id: string, options: ITextEditorConfigurationUpdate): TPromise; $trySetDecorations(id: string, key: string, ranges: editorCommon.IDecorationOptions[]): TPromise; - $trySetDecorationsFast(id: string, key: string, ranges: string): TPromise; + $trySetDecorationsFast(id: string, key: string, ranges: number[]): TPromise; $tryRevealRange(id: string, range: IRange, revealType: TextEditorRevealType): TPromise; $trySetSelections(id: string, selections: ISelection[]): TPromise; $tryApplyEdits(id: string, modelVersionId: number, edits: editorCommon.ISingleEditOperation[], opts: IApplyEditsOptions): TPromise; @@ -673,7 +673,7 @@ export const MainContext = { MainThreadDialogs: createMainId('MainThreadDiaglogs', ProxyType.CustomMarshaller), MainThreadDocuments: createMainId('MainThreadDocuments', ProxyType.CustomMarshaller), MainThreadDocumentContentProviders: createMainId('MainThreadDocumentContentProviders', ProxyType.CustomMarshaller), - MainThreadEditors: createMainId('MainThreadEditors', ProxyType.CustomMarshaller), + MainThreadEditors: createMainId('MainThreadEditors'), MainThreadErrors: createMainId('MainThreadErrors', ProxyType.CustomMarshaller), MainThreadTreeViews: createMainId('MainThreadTreeViews', ProxyType.CustomMarshaller), MainThreadLanguageFeatures: createMainId('MainThreadLanguageFeatures', ProxyType.CustomMarshaller), diff --git a/src/vs/workbench/api/node/extHostTextEditor.ts b/src/vs/workbench/api/node/extHostTextEditor.ts index 0f70aa99ad0..aaf41d4a9bd 100644 --- a/src/vs/workbench/api/node/extHostTextEditor.ts +++ b/src/vs/workbench/api/node/extHostTextEditor.ts @@ -435,7 +435,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { return this._proxy.$trySetDecorationsFast( this._id, decorationType.key, - /*TODO: marshaller is too slow*/JSON.stringify(_ranges) + _ranges ); } } diff --git a/src/vs/workbench/test/electron-browser/api/extHostDocumentSaveParticipant.test.ts b/src/vs/workbench/test/electron-browser/api/extHostDocumentSaveParticipant.test.ts index 7782fcff951..fd74eede73c 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostDocumentSaveParticipant.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostDocumentSaveParticipant.test.ts @@ -324,15 +324,16 @@ suite('ExtHostDocumentSaveParticipant', () => { $tryApplyWorkspaceEdit(_edits: IWorkspaceResourceEdit[]) { for (const { resource, edits } of _edits) { + const uri = URI.revive(resource); for (const { newText, range } of edits) { - documents.$acceptModelChanged(resource.toString(), { + documents.$acceptModelChanged(uri.toString(), { changes: [{ range, rangeLength: undefined, text: newText }], eol: undefined, - versionId: documents.getDocumentData(resource).version + 1 + versionId: documents.getDocumentData(uri).version + 1 }, true); } } -- GitLab