mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-17 11:03:14 -04:00
Merge VS Code 1.21 source code (#1067)
* Initial VS Code 1.21 file copy with patches * A few more merges * Post npm install * Fix batch of build breaks * Fix more build breaks * Fix more build errors * Fix more build breaks * Runtime fixes 1 * Get connection dialog working with some todos * Fix a few packaging issues * Copy several node_modules to package build to fix loader issues * Fix breaks from master * A few more fixes * Make tests pass * First pass of license header updates * Second pass of license header updates * Fix restore dialog issues * Remove add additional themes menu items * fix select box issues where the list doesn't show up * formatting * Fix editor dispose issue * Copy over node modules to correct location on all platforms
This commit is contained in:
67
src/vs/workbench/services/commands/common/commandService.ts
Normal file
67
src/vs/workbench/services/commands/common/commandService.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ICommandService, ICommandEvent, CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
|
||||
export class CommandService extends Disposable implements ICommandService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
private _extensionHostIsReady: boolean = false;
|
||||
|
||||
private _onWillExecuteCommand: Emitter<ICommandEvent> = this._register(new Emitter<ICommandEvent>());
|
||||
public readonly onWillExecuteCommand: Event<ICommandEvent> = this._onWillExecuteCommand.event;
|
||||
|
||||
constructor(
|
||||
@IInstantiationService private readonly _instantiationService: IInstantiationService,
|
||||
@IExtensionService private readonly _extensionService: IExtensionService,
|
||||
@ILogService private readonly _logService: ILogService
|
||||
) {
|
||||
super();
|
||||
this._extensionService.whenInstalledExtensionsRegistered().then(value => this._extensionHostIsReady = value);
|
||||
}
|
||||
|
||||
executeCommand<T>(id: string, ...args: any[]): TPromise<T> {
|
||||
this._logService.trace('CommandService#executeCommand', id);
|
||||
|
||||
// we always send an activation event, but
|
||||
// we don't wait for it when the extension
|
||||
// host didn't yet start and the command is already registered
|
||||
|
||||
const activation = this._extensionService.activateByEvent(`onCommand:${id}`);
|
||||
const commandIsRegistered = !!CommandsRegistry.getCommand(id);
|
||||
|
||||
if (!this._extensionHostIsReady && commandIsRegistered) {
|
||||
return this._tryExecuteCommand(id, args);
|
||||
} else {
|
||||
let waitFor: TPromise<any> = activation;
|
||||
if (!commandIsRegistered) {
|
||||
waitFor = TPromise.join([activation, this._extensionService.activateByEvent(`*`)]);
|
||||
}
|
||||
return waitFor.then(_ => this._tryExecuteCommand(id, args));
|
||||
}
|
||||
}
|
||||
|
||||
private _tryExecuteCommand(id: string, args: any[]): TPromise<any> {
|
||||
const command = CommandsRegistry.getCommand(id);
|
||||
if (!command) {
|
||||
return TPromise.wrapError(new Error(`command '${id}' not found`));
|
||||
}
|
||||
try {
|
||||
this._onWillExecuteCommand.fire({ commandId: id });
|
||||
const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler].concat(args));
|
||||
return TPromise.as(result);
|
||||
} catch (err) {
|
||||
return TPromise.wrapError(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { CommandService } from 'vs/workbench/services/commands/common/commandService';
|
||||
import { IExtensionService, ExtensionPointContribution, IExtensionDescription, ProfileSession } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
||||
import { IExtensionPoint } from 'vs/workbench/services/extensions/common/extensionsRegistry';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
|
||||
class SimpleExtensionService implements IExtensionService {
|
||||
_serviceBrand: any;
|
||||
private _onDidRegisterExtensions = new Emitter<void>();
|
||||
get onDidRegisterExtensions(): Event<void> {
|
||||
return this._onDidRegisterExtensions.event;
|
||||
}
|
||||
onDidChangeExtensionsStatus = null;
|
||||
activateByEvent(activationEvent: string): TPromise<void> {
|
||||
return this.whenInstalledExtensionsRegistered().then(() => { });
|
||||
}
|
||||
whenInstalledExtensionsRegistered(): TPromise<boolean> {
|
||||
return TPromise.as(true);
|
||||
}
|
||||
readExtensionPointContributions<T>(extPoint: IExtensionPoint<T>): TPromise<ExtensionPointContribution<T>[]> {
|
||||
return TPromise.as([]);
|
||||
}
|
||||
getExtensionsStatus() {
|
||||
return undefined;
|
||||
}
|
||||
getExtensions(): TPromise<IExtensionDescription[]> {
|
||||
return TPromise.wrap([]);
|
||||
}
|
||||
canProfileExtensionHost() {
|
||||
return false;
|
||||
}
|
||||
startExtensionHostProfile(): TPromise<ProfileSession> {
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
restartExtensionHost(): void {
|
||||
}
|
||||
startExtensionHost(): void {
|
||||
}
|
||||
stopExtensionHost(): void {
|
||||
}
|
||||
}
|
||||
|
||||
suite('CommandService', function () {
|
||||
|
||||
let commandRegistration: IDisposable;
|
||||
|
||||
setup(function () {
|
||||
commandRegistration = CommandsRegistry.registerCommand('foo', function () { });
|
||||
});
|
||||
|
||||
teardown(function () {
|
||||
commandRegistration.dispose();
|
||||
});
|
||||
|
||||
test('activateOnCommand', function () {
|
||||
|
||||
let lastEvent: string;
|
||||
|
||||
let service = new CommandService(new InstantiationService(), new class extends SimpleExtensionService {
|
||||
activateByEvent(activationEvent: string): TPromise<void> {
|
||||
lastEvent = activationEvent;
|
||||
return super.activateByEvent(activationEvent);
|
||||
}
|
||||
}, new NullLogService());
|
||||
|
||||
return service.executeCommand('foo').then(() => {
|
||||
assert.ok(lastEvent, 'onCommand:foo');
|
||||
return service.executeCommand('unknownCommandId');
|
||||
}).then(() => {
|
||||
assert.ok(false);
|
||||
}, () => {
|
||||
assert.ok(lastEvent, 'onCommand:unknownCommandId');
|
||||
});
|
||||
});
|
||||
|
||||
test('fwd activation error', function () {
|
||||
|
||||
let service = new CommandService(new InstantiationService(), new class extends SimpleExtensionService {
|
||||
activateByEvent(activationEvent: string): TPromise<void> {
|
||||
return TPromise.wrapError<void>(new Error('bad_activate'));
|
||||
}
|
||||
}, new NullLogService());
|
||||
|
||||
return service.executeCommand('foo').then(() => assert.ok(false), err => {
|
||||
assert.equal(err.message, 'bad_activate');
|
||||
});
|
||||
});
|
||||
|
||||
test('!onReady, but executeCommand', function () {
|
||||
|
||||
let callCounter = 0;
|
||||
let reg = CommandsRegistry.registerCommand('bar', () => callCounter += 1);
|
||||
|
||||
let service = new CommandService(new InstantiationService(), new class extends SimpleExtensionService {
|
||||
whenInstalledExtensionsRegistered() {
|
||||
return new TPromise<boolean>(_resolve => { /*ignore*/ });
|
||||
}
|
||||
}, new NullLogService());
|
||||
|
||||
service.executeCommand('bar');
|
||||
assert.equal(callCounter, 1);
|
||||
reg.dispose();
|
||||
});
|
||||
|
||||
test('issue #34913: !onReady, unknown command', function () {
|
||||
|
||||
let callCounter = 0;
|
||||
let resolveFunc: Function;
|
||||
const whenInstalledExtensionsRegistered = new TPromise<boolean>(_resolve => { resolveFunc = _resolve; });
|
||||
|
||||
let service = new CommandService(new InstantiationService(), new class extends SimpleExtensionService {
|
||||
whenInstalledExtensionsRegistered() {
|
||||
return whenInstalledExtensionsRegistered;
|
||||
}
|
||||
}, new NullLogService());
|
||||
|
||||
let r = service.executeCommand('bar');
|
||||
assert.equal(callCounter, 0);
|
||||
|
||||
let reg = CommandsRegistry.registerCommand('bar', () => callCounter += 1);
|
||||
resolveFunc(true);
|
||||
|
||||
return r.then(() => {
|
||||
reg.dispose();
|
||||
assert.equal(callCounter, 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user