Merge commit 'be3e8236086165e5e45a5a10783823874b3f3ebd' as 'lib/vscode'

This commit is contained in:
Joe Previte
2020-12-15 15:52:33 -07:00
4649 changed files with 1311795 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as Types from 'vs/base/common/types';
import * as Assert from 'vs/base/common/assert';
export interface IRegistry {
/**
* Adds the extension functions and properties defined by data to the
* platform. The provided id must be unique.
* @param id a unique identifier
* @param data a contribution
*/
add(id: string, data: any): void;
/**
* Returns true iff there is an extension with the provided id.
* @param id an extension identifier
*/
knows(id: string): boolean;
/**
* Returns the extension functions and properties defined by the specified key or null.
* @param id an extension identifier
*/
as<T>(id: string): T;
}
class RegistryImpl implements IRegistry {
private readonly data = new Map<string, any>();
public add(id: string, data: any): void {
Assert.ok(Types.isString(id));
Assert.ok(Types.isObject(data));
Assert.ok(!this.data.has(id), 'There is already an extension with this id');
this.data.set(id, data);
}
public knows(id: string): boolean {
return this.data.has(id);
}
public as(id: string): any {
return this.data.get(id) || null;
}
}
export const Registry: IRegistry = new RegistryImpl();

View File

@@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as Platform from 'vs/platform/registry/common/platform';
import * as Types from 'vs/base/common/types';
suite('Platform / Registry', () => {
test('registry - api', function () {
assert.ok(Types.isFunction(Platform.Registry.add));
assert.ok(Types.isFunction(Platform.Registry.as));
assert.ok(Types.isFunction(Platform.Registry.knows));
});
test('registry - mixin', function () {
Platform.Registry.add('foo', { bar: true });
assert.ok(Platform.Registry.knows('foo'));
assert.ok(Platform.Registry.as<any>('foo').bar);
assert.equal(Platform.Registry.as<any>('foo').bar, true);
});
test('registry - knows, as', function () {
let ext = {};
Platform.Registry.add('knows,as', ext);
assert.ok(Platform.Registry.knows('knows,as'));
assert.ok(!Platform.Registry.knows('knows,as1234'));
assert.ok(Platform.Registry.as('knows,as') === ext);
assert.ok(Platform.Registry.as('knows,as1234') === null);
});
test('registry - mixin, fails on duplicate ids', function () {
Platform.Registry.add('foo-dup', { bar: true });
try {
Platform.Registry.add('foo-dup', { bar: false });
assert.ok(false);
} catch (e) {
assert.ok(true);
}
});
});