Merge from master

This commit is contained in:
Raj Musuku
2019-02-21 17:56:04 -08:00
parent 5a146e34fa
commit 666ae11639
11482 changed files with 119352 additions and 255574 deletions

View File

@@ -2,13 +2,11 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { TypeConstraint, validateConstraints } from 'vs/base/common/types';
import { ServicesAccessor, createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { Event } from 'vs/base/common/event';
import { Event, Emitter } from 'vs/base/common/event';
import { LinkedList } from 'vs/base/common/linkedList';
export const ICommandService = createDecorator<ICommandService>('commandService');
@@ -20,7 +18,7 @@ export interface ICommandEvent {
export interface ICommandService {
_serviceBrand: any;
onWillExecuteCommand: Event<ICommandEvent>;
executeCommand<T = any>(commandId: string, ...args: any[]): TPromise<T>;
executeCommand<T = any>(commandId: string, ...args: any[]): Promise<T | undefined>;
}
export interface ICommandsMap {
@@ -34,7 +32,7 @@ export interface ICommandHandler {
export interface ICommand {
id: string;
handler: ICommandHandler;
description?: ICommandHandlerDescription;
description?: ICommandHandlerDescription | null;
}
export interface ICommandHandlerDescription {
@@ -44,16 +42,20 @@ export interface ICommandHandlerDescription {
}
export interface ICommandRegistry {
onDidRegisterCommand: Event<string>;
registerCommand(id: string, command: ICommandHandler): IDisposable;
registerCommand(command: ICommand): IDisposable;
registerCommandAlias(oldId: string, newId: string): IDisposable;
getCommand(id: string): ICommand;
getCommand(id: string): ICommand | undefined;
getCommands(): ICommandsMap;
}
export const CommandsRegistry: ICommandRegistry = new class implements ICommandRegistry {
private _commands = new Map<string, LinkedList<ICommand>>();
private readonly _commands = new Map<string, LinkedList<ICommand>>();
private readonly _onDidRegisterCommand = new Emitter<string>();
readonly onDidRegisterCommand: Event<string> = this._onDidRegisterCommand.event;
registerCommand(idOrCommand: string | ICommand, handler?: ICommandHandler): IDisposable {
@@ -70,7 +72,7 @@ export const CommandsRegistry: ICommandRegistry = new class implements ICommandR
// add argument validation if rich command metadata is provided
if (idOrCommand.description) {
const constraints: TypeConstraint[] = [];
const constraints: (TypeConstraint | undefined)[] = [];
for (let arg of idOrCommand.description.args) {
constraints.push(arg.constraint);
}
@@ -92,12 +94,17 @@ export const CommandsRegistry: ICommandRegistry = new class implements ICommandR
let removeFn = commands.unshift(idOrCommand);
return toDisposable(() => {
let ret = toDisposable(() => {
removeFn();
if (this._commands.get(id).isEmpty()) {
this._commands.delete(id);
}
});
// tell the world about this command
this._onDidRegisterCommand.fire(id);
return ret;
}
registerCommandAlias(oldId: string, newId: string): IDisposable {
@@ -106,7 +113,7 @@ export const CommandsRegistry: ICommandRegistry = new class implements ICommandR
});
}
getCommand(id: string): ICommand {
getCommand(id: string): ICommand | undefined {
const list = this._commands.get(id);
if (!list || list.isEmpty()) {
return undefined;
@@ -117,7 +124,7 @@ export const CommandsRegistry: ICommandRegistry = new class implements ICommandR
getCommands(): ICommandsMap {
const result: ICommandsMap = Object.create(null);
this._commands.forEach((value, key) => {
result[key] = this.getCommand(key);
result[key] = this.getCommand(key)!;
});
return result;
}
@@ -126,7 +133,7 @@ export const CommandsRegistry: ICommandRegistry = new class implements ICommandR
export const NullCommandService: ICommandService = {
_serviceBrand: undefined,
onWillExecuteCommand: () => ({ dispose: () => { } }),
executeCommand() {
return TPromise.as(undefined);
executeCommand<T = any>() {
return Promise.resolve<T>(undefined);
}
};

View File

@@ -2,8 +2,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
@@ -13,7 +11,7 @@ suite('Command Tests', function () {
assert.throws(() => CommandsRegistry.registerCommand('foo', null));
});
test('register/dispose', function () {
test('register/dispose', () => {
const command = function () { };
const reg = CommandsRegistry.registerCommand('foo', command);
assert.ok(CommandsRegistry.getCommand('foo').handler === command);
@@ -21,7 +19,7 @@ suite('Command Tests', function () {
assert.ok(CommandsRegistry.getCommand('foo') === undefined);
});
test('register/register/dispose', function () {
test('register/register/dispose', () => {
const command1 = function () { };
const command2 = function () { };