diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index dbeee792583..e04fa081ed3 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -9,6 +9,7 @@ import { IRelativePattern } from 'vs/base/common/glob'; import { MarkdownString as BaseMarkdownString } from 'vs/base/common/htmlContent'; import { ResourceMap } from 'vs/base/common/map'; import { Mimes, normalizeMimeType } from 'vs/base/common/mime'; +import { nextCharLength } from 'vs/base/common/strings'; import { isArray, isStringArray } from 'vs/base/common/types'; import { URI } from 'vs/base/common/uri'; import { generateUuid } from 'vs/base/common/uuid'; @@ -2910,13 +2911,20 @@ export enum ExtensionKind { export class FileDecoration { - static validate(d: FileDecoration): void { - if (d.badge && d.badge.length !== 1 && d.badge.length !== 2) { - throw new Error(`The 'badge'-property must be undefined or a short character`); + static validate(d: FileDecoration): boolean { + if (d.badge) { + let len = nextCharLength(d.badge, 0); + if (len < d.badge.length) { + len += nextCharLength(d.badge, len); + } + if (d.badge.length > len) { + throw new Error(`The 'badge'-property must be undefined or a short character`); + } } if (!d.color && !d.badge && !d.tooltip) { throw new Error(`The decoration is empty`); } + return true; } badge?: string; diff --git a/src/vs/workbench/test/browser/api/extHostTypes.test.ts b/src/vs/workbench/test/browser/api/extHostTypes.test.ts index 5b16216a937..d28ec25ea62 100644 --- a/src/vs/workbench/test/browser/api/extHostTypes.test.ts +++ b/src/vs/workbench/test/browser/api/extHostTypes.test.ts @@ -692,4 +692,20 @@ suite('ExtHostTypes', function () { assert.strictEqual(item.mime, 'foo/bar'); assert.deepStrictEqual(item.data, new TextEncoder().encode('Hęłlö')); }); + + test('FileDecoration#validate', function () { + + assert.ok(types.FileDecoration.validate({ badge: 'u' })); + assert.ok(types.FileDecoration.validate({ badge: 'ü' })); + assert.ok(types.FileDecoration.validate({ badge: '1' })); + assert.ok(types.FileDecoration.validate({ badge: 'ãã' })); + assert.ok(types.FileDecoration.validate({ badge: '👋' })); + assert.ok(types.FileDecoration.validate({ badge: '👋👋' })); + assert.ok(types.FileDecoration.validate({ badge: '👩‍👩‍👧‍👧' })); + assert.ok(types.FileDecoration.validate({ badge: 'போ' })); + assert.throws(() => types.FileDecoration.validate({ badge: 'hel' })); + assert.throws(() => types.FileDecoration.validate({ badge: '👋👋👋' })); + assert.throws(() => types.FileDecoration.validate({ badge: 'புன்சிரிப்போடு' })); + assert.throws(() => types.FileDecoration.validate({ badge: 'ããã' })); + }); });