Skip to content

Commit eb87600

Browse files
committed
Use more URIs
1 parent 0129eda commit eb87600

5 files changed

Lines changed: 131 additions & 19 deletions

File tree

src/vs/editor/browser/services/codeEditorServiceImpl.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,7 @@ class DecorationCSSRules {
401401
if (typeof opts !== 'undefined') {
402402
this.collectBorderSettingsCSSText(opts, cssTextArr);
403403
if (typeof opts.contentIconPath !== 'undefined') {
404-
if (typeof opts.contentIconPath === 'string') {
405-
cssTextArr.push(strings.format(_CSS_MAP.contentIconPath, URI.file(opts.contentIconPath).toString().replace(/'/g, '%27')));
406-
} else {
407-
cssTextArr.push(strings.format(_CSS_MAP.contentIconPath, URI.revive(opts.contentIconPath).toString(true).replace(/'/g, '%27')));
408-
}
404+
cssTextArr.push(strings.format(_CSS_MAP.contentIconPath, URI.revive(opts.contentIconPath).toString(true).replace(/'/g, '%27')));
409405
}
410406
if (typeof opts.contentText === 'string') {
411407
const truncated = opts.contentText.match(/^.*$/m)![0]; // only take first line
@@ -432,11 +428,7 @@ class DecorationCSSRules {
432428
let cssTextArr: string[] = [];
433429

434430
if (typeof opts.gutterIconPath !== 'undefined') {
435-
if (typeof opts.gutterIconPath === 'string') {
436-
cssTextArr.push(strings.format(_CSS_MAP.gutterIconPath, URI.file(opts.gutterIconPath).toString()));
437-
} else {
438-
cssTextArr.push(strings.format(_CSS_MAP.gutterIconPath, URI.revive(opts.gutterIconPath).toString(true).replace(/'/g, '%27')));
439-
}
431+
cssTextArr.push(strings.format(_CSS_MAP.gutterIconPath, URI.revive(opts.gutterIconPath).toString(true).replace(/'/g, '%27')));
440432
if (typeof opts.gutterIconSize !== 'undefined') {
441433
cssTextArr.push(strings.format(_CSS_MAP.gutterIconSize, opts.gutterIconSize));
442434
}

src/vs/editor/common/editorCommon.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,10 @@ export interface IThemeDecorationRenderOptions {
534534
textDecoration?: string;
535535
cursor?: string;
536536
color?: string | ThemeColor;
537-
opacity?: number;
537+
opacity?: string;
538538
letterSpacing?: string;
539539

540-
gutterIconPath?: string | UriComponents;
540+
gutterIconPath?: UriComponents;
541541
gutterIconSize?: string;
542542

543543
overviewRulerColor?: string | ThemeColor;
@@ -551,7 +551,7 @@ export interface IThemeDecorationRenderOptions {
551551
*/
552552
export interface IContentDecorationRenderOptions {
553553
contentText?: string;
554-
contentIconPath?: string | UriComponents;
554+
contentIconPath?: UriComponents;
555555

556556
border?: string;
557557
borderColor?: string | ThemeColor;

src/vs/editor/test/browser/services/decorationRenderOptions.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ suite('Decoration Render Options', () => {
134134

135135
// unix file path (used as string)
136136
let s = new TestCodeEditorServiceImpl(themeServiceMock, styleSheet);
137-
s.registerDecorationType('example', { gutterIconPath: '/Users/foo/bar.png' });
137+
s.registerDecorationType('example', { gutterIconPath: URI.file('/Users/foo/bar.png') });
138138
let sheet = readStyleSheet(styleSheet);//.innerHTML || styleSheet.sheet.toString();
139139
assert(
140140
sheet.indexOf('background: url(\'file:///Users/foo/bar.png\') center center no-repeat;') > 0
@@ -143,7 +143,7 @@ suite('Decoration Render Options', () => {
143143

144144
// windows file path (used as string)
145145
s = new TestCodeEditorServiceImpl(themeServiceMock, styleSheet);
146-
s.registerDecorationType('example', { gutterIconPath: 'c:\\files\\miles\\more.png' });
146+
s.registerDecorationType('example', { gutterIconPath: URI.file('c:\\files\\miles\\more.png') });
147147
sheet = readStyleSheet(styleSheet);
148148
// TODO@Alex test fails
149149
// assert(
@@ -162,7 +162,7 @@ suite('Decoration Render Options', () => {
162162

163163
// single quote must always be escaped/encoded
164164
s = new TestCodeEditorServiceImpl(themeServiceMock, styleSheet);
165-
s.registerDecorationType('example', { gutterIconPath: '/Users/foo/b\'ar.png' });
165+
s.registerDecorationType('example', { gutterIconPath: URI.file('/Users/foo/b\'ar.png') });
166166
sheet = readStyleSheet(styleSheet);
167167
assert(
168168
sheet.indexOf('background: url(\'file:///Users/foo/b%27ar.png\') center center no-repeat;') > 0

src/vs/workbench/api/node/extHostTextEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class TextEditorDecorationType implements vscode.TextEditorDecorationType
2525
constructor(proxy: MainThreadTextEditorsShape, options: vscode.DecorationRenderOptions) {
2626
this.key = TextEditorDecorationType._Keys.nextId();
2727
this._proxy = proxy;
28-
this._proxy.$registerTextEditorDecorationType(this.key, <any>/* URI vs Uri */ options);
28+
this._proxy.$registerTextEditorDecorationType(this.key, TypeConverters.DecorationRenderOptions.from(options));
2929
}
3030

3131
public dispose(): void {

src/vs/workbench/api/node/extHostTypeConverters.ts

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import * as types from './extHostTypes';
88
import * as search from 'vs/workbench/parts/search/common/search';
99
import { ITextEditorOptions } from 'vs/platform/editor/common/editor';
1010
import { EditorViewColumn } from 'vs/workbench/api/shared/editor';
11-
import { IDecorationOptions } from 'vs/editor/common/editorCommon';
12-
import { EndOfLineSequence } from 'vs/editor/common/model';
11+
import { IDecorationOptions, IThemeDecorationRenderOptions, IDecorationRenderOptions, IContentDecorationRenderOptions } from 'vs/editor/common/editorCommon';
12+
import { EndOfLineSequence, TrackedRangeStickiness } from 'vs/editor/common/model';
1313
import * as vscode from 'vscode';
1414
import { URI } from 'vs/base/common/uri';
1515
import { ProgressLocation as MainProgressLocation } from 'vs/platform/progress/common/progress';
@@ -252,6 +252,126 @@ export function fromRangeOrRangeWithMessage(ranges: vscode.Range[] | vscode.Deco
252252
}
253253
}
254254

255+
function pathOrURIToURI(value: string | URI): URI {
256+
if (typeof value === 'undefined') {
257+
return value;
258+
}
259+
if (typeof value === 'string') {
260+
return URI.file(value);
261+
} else {
262+
return value;
263+
}
264+
}
265+
266+
export namespace ThemableDecorationAttachmentRenderOptions {
267+
export function from(options: vscode.ThemableDecorationAttachmentRenderOptions): IContentDecorationRenderOptions {
268+
if (typeof options === 'undefined') {
269+
return options;
270+
}
271+
return {
272+
contentText: options.contentText,
273+
contentIconPath: pathOrURIToURI(options.contentIconPath),
274+
border: options.border,
275+
borderColor: <string | types.ThemeColor>options.borderColor,
276+
fontStyle: options.fontStyle,
277+
fontWeight: options.fontWeight,
278+
textDecoration: options.textDecoration,
279+
color: <string | types.ThemeColor>options.color,
280+
backgroundColor: <string | types.ThemeColor>options.backgroundColor,
281+
margin: options.margin,
282+
width: options.width,
283+
height: options.height,
284+
};
285+
}
286+
}
287+
288+
export namespace ThemableDecorationRenderOptions {
289+
export function from(options: vscode.ThemableDecorationRenderOptions): IThemeDecorationRenderOptions {
290+
if (typeof options === 'undefined') {
291+
return options;
292+
}
293+
return {
294+
backgroundColor: <string | types.ThemeColor>options.backgroundColor,
295+
outline: options.outline,
296+
outlineColor: <string | types.ThemeColor>options.outlineColor,
297+
outlineStyle: options.outlineStyle,
298+
outlineWidth: options.outlineWidth,
299+
border: options.border,
300+
borderColor: <string | types.ThemeColor>options.borderColor,
301+
borderRadius: options.borderRadius,
302+
borderSpacing: options.borderSpacing,
303+
borderStyle: options.borderStyle,
304+
borderWidth: options.borderWidth,
305+
fontStyle: options.fontStyle,
306+
fontWeight: options.fontWeight,
307+
textDecoration: options.textDecoration,
308+
cursor: options.cursor,
309+
color: <string | types.ThemeColor>options.color,
310+
opacity: options.opacity,
311+
letterSpacing: options.letterSpacing,
312+
gutterIconPath: pathOrURIToURI(options.gutterIconPath),
313+
gutterIconSize: options.gutterIconSize,
314+
overviewRulerColor: <string | types.ThemeColor>options.overviewRulerColor,
315+
before: ThemableDecorationAttachmentRenderOptions.from(options.before),
316+
after: ThemableDecorationAttachmentRenderOptions.from(options.after),
317+
};
318+
}
319+
}
320+
321+
export namespace DecorationRangeBehavior {
322+
export function from(value: types.DecorationRangeBehavior): TrackedRangeStickiness {
323+
if (typeof value === 'undefined') {
324+
return value;
325+
}
326+
switch (value) {
327+
case types.DecorationRangeBehavior.OpenOpen:
328+
return TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges;
329+
case types.DecorationRangeBehavior.ClosedClosed:
330+
return TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges;
331+
case types.DecorationRangeBehavior.OpenClosed:
332+
return TrackedRangeStickiness.GrowsOnlyWhenTypingBefore;
333+
case types.DecorationRangeBehavior.ClosedOpen:
334+
return TrackedRangeStickiness.GrowsOnlyWhenTypingAfter;
335+
}
336+
}
337+
}
338+
339+
export namespace DecorationRenderOptions {
340+
export function from(options: vscode.DecorationRenderOptions): IDecorationRenderOptions {
341+
return {
342+
isWholeLine: options.isWholeLine,
343+
rangeBehavior: DecorationRangeBehavior.from(options.rangeBehavior),
344+
overviewRulerLane: options.overviewRulerLane,
345+
light: ThemableDecorationRenderOptions.from(options.light),
346+
dark: ThemableDecorationRenderOptions.from(options.dark),
347+
348+
backgroundColor: <string | types.ThemeColor>options.backgroundColor,
349+
outline: options.outline,
350+
outlineColor: <string | types.ThemeColor>options.outlineColor,
351+
outlineStyle: options.outlineStyle,
352+
outlineWidth: options.outlineWidth,
353+
border: options.border,
354+
borderColor: <string | types.ThemeColor>options.borderColor,
355+
borderRadius: options.borderRadius,
356+
borderSpacing: options.borderSpacing,
357+
borderStyle: options.borderStyle,
358+
borderWidth: options.borderWidth,
359+
fontStyle: options.fontStyle,
360+
fontWeight: options.fontWeight,
361+
textDecoration: options.textDecoration,
362+
cursor: options.cursor,
363+
color: <string | types.ThemeColor>options.color,
364+
opacity: options.opacity,
365+
letterSpacing: options.letterSpacing,
366+
gutterIconPath: pathOrURIToURI(options.gutterIconPath),
367+
gutterIconSize: options.gutterIconSize,
368+
overviewRulerColor: <string | types.ThemeColor>options.overviewRulerColor,
369+
before: ThemableDecorationAttachmentRenderOptions.from(options.before),
370+
after: ThemableDecorationAttachmentRenderOptions.from(options.after),
371+
};
372+
}
373+
}
374+
255375
export namespace TextEdit {
256376

257377
export function from(edit: vscode.TextEdit): modes.TextEdit {

0 commit comments

Comments
 (0)