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`); + }); });