From eb87600bd377631217836c0e15ef1e0ea4b1bf82 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Wed, 7 Nov 2018 19:47:10 +0100 Subject: [PATCH] Use more URIs --- .../browser/services/codeEditorServiceImpl.ts | 12 +- src/vs/editor/common/editorCommon.ts | 6 +- .../services/decorationRenderOptions.test.ts | 6 +- .../workbench/api/node/extHostTextEditor.ts | 2 +- .../api/node/extHostTypeConverters.ts | 124 +++++++++++++++++- 5 files changed, 131 insertions(+), 19 deletions(-) diff --git a/src/vs/editor/browser/services/codeEditorServiceImpl.ts b/src/vs/editor/browser/services/codeEditorServiceImpl.ts index f832af4fcf6..3e03681e22b 100644 --- a/src/vs/editor/browser/services/codeEditorServiceImpl.ts +++ b/src/vs/editor/browser/services/codeEditorServiceImpl.ts @@ -401,11 +401,7 @@ class DecorationCSSRules { if (typeof opts !== 'undefined') { this.collectBorderSettingsCSSText(opts, cssTextArr); 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'))); - } + 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 @@ -432,11 +428,7 @@ class DecorationCSSRules { let cssTextArr: string[] = []; if (typeof opts.gutterIconPath !== 'undefined') { - 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, URI.revive(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 dfe4d127b73..909f6fb1e64 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -534,10 +534,10 @@ export interface IThemeDecorationRenderOptions { textDecoration?: string; cursor?: string; color?: string | ThemeColor; - opacity?: number; + opacity?: string; letterSpacing?: string; - gutterIconPath?: string | UriComponents; + gutterIconPath?: UriComponents; gutterIconSize?: string; overviewRulerColor?: string | ThemeColor; @@ -551,7 +551,7 @@ export interface IThemeDecorationRenderOptions { */ export interface IContentDecorationRenderOptions { contentText?: string; - contentIconPath?: string | UriComponents; + contentIconPath?: UriComponents; border?: string; borderColor?: string | ThemeColor; diff --git a/src/vs/editor/test/browser/services/decorationRenderOptions.test.ts b/src/vs/editor/test/browser/services/decorationRenderOptions.test.ts index e72956f57e7..feb3a465cf6 100644 --- a/src/vs/editor/test/browser/services/decorationRenderOptions.test.ts +++ b/src/vs/editor/test/browser/services/decorationRenderOptions.test.ts @@ -134,7 +134,7 @@ suite('Decoration Render Options', () => { // unix file path (used as string) let s = new TestCodeEditorServiceImpl(themeServiceMock, styleSheet); - s.registerDecorationType('example', { gutterIconPath: '/Users/foo/bar.png' }); + s.registerDecorationType('example', { gutterIconPath: URI.file('/Users/foo/bar.png') }); let sheet = readStyleSheet(styleSheet);//.innerHTML || styleSheet.sheet.toString(); assert( sheet.indexOf('background: url(\'file:///Users/foo/bar.png\') center center no-repeat;') > 0 @@ -143,7 +143,7 @@ suite('Decoration Render Options', () => { // windows file path (used as string) s = new TestCodeEditorServiceImpl(themeServiceMock, styleSheet); - s.registerDecorationType('example', { gutterIconPath: 'c:\\files\\miles\\more.png' }); + s.registerDecorationType('example', { gutterIconPath: URI.file('c:\\files\\miles\\more.png') }); sheet = readStyleSheet(styleSheet); // TODO@Alex test fails // assert( @@ -162,7 +162,7 @@ suite('Decoration Render Options', () => { // single quote must always be escaped/encoded s = new TestCodeEditorServiceImpl(themeServiceMock, styleSheet); - s.registerDecorationType('example', { gutterIconPath: '/Users/foo/b\'ar.png' }); + s.registerDecorationType('example', { gutterIconPath: URI.file('/Users/foo/b\'ar.png') }); sheet = readStyleSheet(styleSheet); assert( sheet.indexOf('background: url(\'file:///Users/foo/b%27ar.png\') center center no-repeat;') > 0 diff --git a/src/vs/workbench/api/node/extHostTextEditor.ts b/src/vs/workbench/api/node/extHostTextEditor.ts index 26d6f95843b..b9716f63542 100644 --- a/src/vs/workbench/api/node/extHostTextEditor.ts +++ b/src/vs/workbench/api/node/extHostTextEditor.ts @@ -25,7 +25,7 @@ export class TextEditorDecorationType implements vscode.TextEditorDecorationType constructor(proxy: MainThreadTextEditorsShape, options: vscode.DecorationRenderOptions) { this.key = TextEditorDecorationType._Keys.nextId(); this._proxy = proxy; - this._proxy.$registerTextEditorDecorationType(this.key, /* URI vs Uri */ options); + this._proxy.$registerTextEditorDecorationType(this.key, TypeConverters.DecorationRenderOptions.from(options)); } public dispose(): void { diff --git a/src/vs/workbench/api/node/extHostTypeConverters.ts b/src/vs/workbench/api/node/extHostTypeConverters.ts index 95133a90e81..de2d33911d8 100644 --- a/src/vs/workbench/api/node/extHostTypeConverters.ts +++ b/src/vs/workbench/api/node/extHostTypeConverters.ts @@ -8,8 +8,8 @@ import * as types from './extHostTypes'; import * as search from 'vs/workbench/parts/search/common/search'; import { ITextEditorOptions } from 'vs/platform/editor/common/editor'; import { EditorViewColumn } from 'vs/workbench/api/shared/editor'; -import { IDecorationOptions } from 'vs/editor/common/editorCommon'; -import { EndOfLineSequence } from 'vs/editor/common/model'; +import { IDecorationOptions, IThemeDecorationRenderOptions, IDecorationRenderOptions, IContentDecorationRenderOptions } from 'vs/editor/common/editorCommon'; +import { EndOfLineSequence, TrackedRangeStickiness } from 'vs/editor/common/model'; import * as vscode from 'vscode'; import { URI } from 'vs/base/common/uri'; import { ProgressLocation as MainProgressLocation } from 'vs/platform/progress/common/progress'; @@ -252,6 +252,126 @@ export function fromRangeOrRangeWithMessage(ranges: vscode.Range[] | vscode.Deco } } +function pathOrURIToURI(value: string | URI): URI { + if (typeof value === 'undefined') { + return value; + } + if (typeof value === 'string') { + return URI.file(value); + } else { + return value; + } +} + +export namespace ThemableDecorationAttachmentRenderOptions { + export function from(options: vscode.ThemableDecorationAttachmentRenderOptions): IContentDecorationRenderOptions { + if (typeof options === 'undefined') { + return options; + } + return { + contentText: options.contentText, + contentIconPath: pathOrURIToURI(options.contentIconPath), + border: options.border, + borderColor: options.borderColor, + fontStyle: options.fontStyle, + fontWeight: options.fontWeight, + textDecoration: options.textDecoration, + color: options.color, + backgroundColor: options.backgroundColor, + margin: options.margin, + width: options.width, + height: options.height, + }; + } +} + +export namespace ThemableDecorationRenderOptions { + export function from(options: vscode.ThemableDecorationRenderOptions): IThemeDecorationRenderOptions { + if (typeof options === 'undefined') { + return options; + } + return { + backgroundColor: options.backgroundColor, + outline: options.outline, + outlineColor: options.outlineColor, + outlineStyle: options.outlineStyle, + outlineWidth: options.outlineWidth, + border: options.border, + borderColor: options.borderColor, + borderRadius: options.borderRadius, + borderSpacing: options.borderSpacing, + borderStyle: options.borderStyle, + borderWidth: options.borderWidth, + fontStyle: options.fontStyle, + fontWeight: options.fontWeight, + textDecoration: options.textDecoration, + cursor: options.cursor, + color: options.color, + opacity: options.opacity, + letterSpacing: options.letterSpacing, + gutterIconPath: pathOrURIToURI(options.gutterIconPath), + gutterIconSize: options.gutterIconSize, + overviewRulerColor: options.overviewRulerColor, + before: ThemableDecorationAttachmentRenderOptions.from(options.before), + after: ThemableDecorationAttachmentRenderOptions.from(options.after), + }; + } +} + +export namespace DecorationRangeBehavior { + export function from(value: types.DecorationRangeBehavior): TrackedRangeStickiness { + if (typeof value === 'undefined') { + return value; + } + switch (value) { + case types.DecorationRangeBehavior.OpenOpen: + return TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges; + case types.DecorationRangeBehavior.ClosedClosed: + return TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges; + case types.DecorationRangeBehavior.OpenClosed: + return TrackedRangeStickiness.GrowsOnlyWhenTypingBefore; + case types.DecorationRangeBehavior.ClosedOpen: + return TrackedRangeStickiness.GrowsOnlyWhenTypingAfter; + } + } +} + +export namespace DecorationRenderOptions { + export function from(options: vscode.DecorationRenderOptions): IDecorationRenderOptions { + return { + isWholeLine: options.isWholeLine, + rangeBehavior: DecorationRangeBehavior.from(options.rangeBehavior), + overviewRulerLane: options.overviewRulerLane, + light: ThemableDecorationRenderOptions.from(options.light), + dark: ThemableDecorationRenderOptions.from(options.dark), + + backgroundColor: options.backgroundColor, + outline: options.outline, + outlineColor: options.outlineColor, + outlineStyle: options.outlineStyle, + outlineWidth: options.outlineWidth, + border: options.border, + borderColor: options.borderColor, + borderRadius: options.borderRadius, + borderSpacing: options.borderSpacing, + borderStyle: options.borderStyle, + borderWidth: options.borderWidth, + fontStyle: options.fontStyle, + fontWeight: options.fontWeight, + textDecoration: options.textDecoration, + cursor: options.cursor, + color: options.color, + opacity: options.opacity, + letterSpacing: options.letterSpacing, + gutterIconPath: pathOrURIToURI(options.gutterIconPath), + gutterIconSize: options.gutterIconSize, + overviewRulerColor: options.overviewRulerColor, + before: ThemableDecorationAttachmentRenderOptions.from(options.before), + after: ThemableDecorationAttachmentRenderOptions.from(options.after), + }; + } +} + export namespace TextEdit { export function from(edit: vscode.TextEdit): modes.TextEdit {