mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05: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:
@@ -1,70 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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/platform/extensions/common/extensions';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
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 _instantiationService: IInstantiationService,
|
||||
@IExtensionService private _extensionService: IExtensionService,
|
||||
@IContextKeyService private _contextKeyService: IContextKeyService,
|
||||
@ILogService private _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}`);
|
||||
|
||||
if (!this._extensionHostIsReady && CommandsRegistry.getCommand(id)) {
|
||||
return this._tryExecuteCommand(id, args);
|
||||
} else {
|
||||
return activation.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`));
|
||||
}
|
||||
|
||||
if (command.precondition && !this._contextKeyService.contextMatchesRules(command.precondition)) {
|
||||
// not enabled
|
||||
return TPromise.wrapError(new Error('NOT_ENABLED'));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import { IDisposable } 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 { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { LinkedList } from 'vs/base/common/linkedList';
|
||||
|
||||
export const ICommandService = createDecorator<ICommandService>('commandService');
|
||||
@@ -35,7 +34,6 @@ export interface ICommandHandler {
|
||||
export interface ICommand {
|
||||
id: string;
|
||||
handler: ICommandHandler;
|
||||
precondition?: ContextKeyExpr;
|
||||
description?: ICommandHandlerDescription;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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/platform/commands/common/commandService';
|
||||
import { IExtensionService, ExtensionPointContribution, IExtensionDescription, IExtensionHostInformation, ProfileSession } from 'vs/platform/extensions/common/extensions';
|
||||
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
||||
import { IExtensionPoint } from 'vs/platform/extensions/common/extensionsRegistry';
|
||||
import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService';
|
||||
import { SimpleConfigurationService } from 'vs/editor/standalone/browser/simpleServices';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { NoopLogService } from 'vs/platform/log/common/log';
|
||||
|
||||
class SimpleExtensionService implements IExtensionService {
|
||||
_serviceBrand: any;
|
||||
private _onDidRegisterExtensions = new Emitter<IExtensionDescription[]>();
|
||||
get onDidRegisterExtensions(): Event<IExtensionDescription[]> {
|
||||
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;
|
||||
}
|
||||
getExtensionHostInformation(): IExtensionHostInformation {
|
||||
return undefined;
|
||||
}
|
||||
getExtensions(): TPromise<IExtensionDescription[]> {
|
||||
return TPromise.wrap([]);
|
||||
}
|
||||
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 ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
|
||||
|
||||
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 ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
|
||||
|
||||
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 ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
|
||||
|
||||
service.executeCommand('bar');
|
||||
assert.equal(callCounter, 1);
|
||||
reg.dispose();
|
||||
});
|
||||
|
||||
test('issue #34913: !onReady, unknown command', function () {
|
||||
|
||||
let callCounter = 0;
|
||||
let resolveFunc: Function;
|
||||
// let reg = CommandsRegistry.registerCommand('bar', () => callCounter += 1);
|
||||
|
||||
let service = new CommandService(new InstantiationService(), new class extends SimpleExtensionService {
|
||||
whenInstalledExtensionsRegistered() {
|
||||
return new TPromise<boolean>(_resolve => { resolveFunc = _resolve; });
|
||||
}
|
||||
}, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
test('honor command-precondition', function () {
|
||||
let contextKeyService = new ContextKeyService(new SimpleConfigurationService());
|
||||
let commandService = new CommandService(
|
||||
new InstantiationService(),
|
||||
new SimpleExtensionService(),
|
||||
contextKeyService,
|
||||
new NoopLogService()
|
||||
);
|
||||
|
||||
let counter = 0;
|
||||
let reg = CommandsRegistry.registerCommand({
|
||||
id: 'bar',
|
||||
handler: () => { counter += 1; },
|
||||
precondition: ContextKeyExpr.has('foocontext')
|
||||
});
|
||||
|
||||
return commandService.executeCommand('bar').then(() => {
|
||||
assert.throws(() => { });
|
||||
}, () => {
|
||||
contextKeyService.setContext('foocontext', true);
|
||||
return commandService.executeCommand('bar');
|
||||
}).then(() => {
|
||||
assert.equal(counter, 1);
|
||||
reg.dispose();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
|
||||
suite('Command Tests', function () {
|
||||
|
||||
@@ -77,21 +76,4 @@ suite('Command Tests', function () {
|
||||
assert.equal(CommandsRegistry.getCommands()['test3'].handler.apply(undefined, [undefined, 1]), true);
|
||||
|
||||
});
|
||||
|
||||
test('CommandsRegistry with precondition', function () {
|
||||
let r1 = CommandsRegistry.registerCommand('foo', () => { });
|
||||
|
||||
const precondition = new RawContextKey<boolean>('ddd', false);
|
||||
let r2 = CommandsRegistry.registerCommand({
|
||||
id: 'bar',
|
||||
handler: () => { },
|
||||
precondition
|
||||
});
|
||||
|
||||
assert.ok(CommandsRegistry.getCommand('bar').precondition === precondition);
|
||||
assert.equal(CommandsRegistry.getCommand('foo').precondition, undefined);
|
||||
|
||||
r1.dispose();
|
||||
r2.dispose();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user