From 55825e9ad2aa4b4b3f8b2290a54a517bc454a7a5 Mon Sep 17 00:00:00 2001 From: Pine Wu Date: Mon, 9 Sep 2019 15:56:36 -0700 Subject: [PATCH] Fix #80536 --- .../services/preferences/common/preferencesModels.ts | 7 +++++++ .../preferences/test/common/preferencesModel.test.ts | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/vs/workbench/services/preferences/common/preferencesModels.ts b/src/vs/workbench/services/preferences/common/preferencesModels.ts index 2f334c3ca5a..e0f621a144a 100644 --- a/src/vs/workbench/services/preferences/common/preferencesModels.ts +++ b/src/vs/workbench/services/preferences/common/preferencesModels.ts @@ -1043,6 +1043,13 @@ export function createValidator(prop: IConfigurationPropertySchema): (value: any const stringArrayValue = value as string[]; + if (prop.uniqueItems) { + if (new Set(stringArrayValue).size < stringArrayValue.length) { + message += nls.localize('validations.stringArrayUniqueItems', 'Array has duplicate items'); + message += '\n'; + } + } + if (prop.minItems && stringArrayValue.length < prop.minItems) { message += nls.localize('validations.stringArrayMinItem', 'Array must have at least {0} items', prop.minItems); message += '\n'; diff --git a/src/vs/workbench/services/preferences/test/common/preferencesModel.test.ts b/src/vs/workbench/services/preferences/test/common/preferencesModel.test.ts index b02e29c0c96..9fbfb467a2b 100644 --- a/src/vs/workbench/services/preferences/test/common/preferencesModel.test.ts +++ b/src/vs/workbench/services/preferences/test/common/preferencesModel.test.ts @@ -328,4 +328,10 @@ suite('Preferences Model test', () => { arr.rejects(['a']).withMessage(`err: must be friendly`); }); + + test('uniqueItems', () => { + const arr = new ArrayTester({ type: 'array', items: { type: 'string' }, uniqueItems: true }); + + arr.rejects(['a', 'a']).withMessage(`Array has duplicate items`); + }); });