From c99ce4de07902673eb431502dd32f5976e93d281 Mon Sep 17 00:00:00 2001 From: Anthony Dresser Date: Tue, 30 Jul 2019 12:44:15 -0700 Subject: [PATCH] Move command line parsing to be a workbench contribution (#6524) * move command line parsing to be a workbench contribution * move to electron-browser * update variable names --- .../commandLine.contribution.ts | 11 ++++ .../electron-browser/commandLine.ts} | 5 +- .../test/common/commandLine.test.ts} | 50 +++++++++---------- .../commandLine/common/commandLine.ts | 18 ------- src/vs/workbench/browser/workbench.ts | 9 ---- src/vs/workbench/workbench.main.ts | 2 + 6 files changed, 40 insertions(+), 55 deletions(-) create mode 100644 src/sql/workbench/parts/commandLine/electron-browser/commandLine.contribution.ts rename src/sql/workbench/{services/commandLine/common/commandLineService.ts => parts/commandLine/electron-browser/commandLine.ts} (98%) rename src/sql/workbench/{services/commandLine/test/common/commandLineService.test.ts => parts/commandLine/test/common/commandLine.test.ts} (88%) delete mode 100644 src/sql/workbench/services/commandLine/common/commandLine.ts diff --git a/src/sql/workbench/parts/commandLine/electron-browser/commandLine.contribution.ts b/src/sql/workbench/parts/commandLine/electron-browser/commandLine.contribution.ts new file mode 100644 index 0000000000..4a7a89b603 --- /dev/null +++ b/src/sql/workbench/parts/commandLine/electron-browser/commandLine.contribution.ts @@ -0,0 +1,11 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { Registry } from 'vs/platform/registry/common/platform'; +import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions'; +import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; +import { CommandLineWorkbenchContribution } from 'sql/workbench/parts/commandLine/electron-browser/commandLine'; + +Registry.as(WorkbenchExtensions.Workbench).registerWorkbenchContribution(CommandLineWorkbenchContribution, LifecyclePhase.Restored); diff --git a/src/sql/workbench/services/commandLine/common/commandLineService.ts b/src/sql/workbench/parts/commandLine/electron-browser/commandLine.ts similarity index 98% rename from src/sql/workbench/services/commandLine/common/commandLineService.ts rename to src/sql/workbench/parts/commandLine/electron-browser/commandLine.ts index 080658ab4a..a8da6c44c2 100644 --- a/src/sql/workbench/services/commandLine/common/commandLineService.ts +++ b/src/sql/workbench/parts/commandLine/electron-browser/commandLine.ts @@ -7,7 +7,6 @@ import * as azdata from 'azdata'; import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile'; import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup'; import { equalsIgnoreCase } from 'vs/base/common/strings'; -import { ICommandLineProcessing } from 'sql/workbench/services/commandLine/common/commandLine'; import { IConnectionManagementService, IConnectionCompletionOptions, ConnectionType, RunQueryOnConnectionMode } from 'sql/platform/connection/common/connectionManagement'; import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService'; import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment'; @@ -27,9 +26,9 @@ import { QueryInput } from 'sql/workbench/parts/query/common/queryInput'; import { URI } from 'vs/base/common/uri'; import { ILogService } from 'vs/platform/log/common/log'; import { INotificationService } from 'vs/platform/notification/common/notification'; +import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; -export class CommandLineService implements ICommandLineProcessing { - public _serviceBrand: any; +export class CommandLineWorkbenchContribution implements IWorkbenchContribution { constructor( @ICapabilitiesService private _capabilitiesService: ICapabilitiesService, diff --git a/src/sql/workbench/services/commandLine/test/common/commandLineService.test.ts b/src/sql/workbench/parts/commandLine/test/common/commandLine.test.ts similarity index 88% rename from src/sql/workbench/services/commandLine/test/common/commandLineService.test.ts rename to src/sql/workbench/parts/commandLine/test/common/commandLine.test.ts index 9e0e92871d..f185ab26c0 100644 --- a/src/sql/workbench/services/commandLine/test/common/commandLineService.test.ts +++ b/src/sql/workbench/parts/commandLine/test/common/commandLine.test.ts @@ -8,7 +8,7 @@ import * as TypeMoq from 'typemoq'; import * as azdata from 'azdata'; import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile'; import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup'; -import { CommandLineService } from 'sql/workbench/services/commandLine/common/commandLineService'; +import { CommandLineWorkbenchContribution } from 'sql/workbench/parts/commandLine/electron-browser/commandLine'; import * as Constants from 'sql/platform/connection/common/constants'; import { ParsedArgs } from 'vs/platform/environment/common/environment'; import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService'; @@ -98,14 +98,15 @@ suite('commandLineService tests', () => { capabilitiesService = new TestCapabilitiesService(); }); - function getCommandLineService(connectionManagementService: IConnectionManagementService, + function getCommandLineContribution( + connectionManagementService: IConnectionManagementService, configurationService: IConfigurationService, capabilitiesService?: ICapabilitiesService, commandService?: ICommandService, editorService?: IEditorService, logService?: ILogService - ): CommandLineService { - let service = new CommandLineService( + ): CommandLineWorkbenchContribution { + return new CommandLineWorkbenchContribution( capabilitiesService, connectionManagementService, undefined, @@ -117,7 +118,6 @@ suite('commandLineService tests', () => { undefined, logService ); - return service; } function getConfigurationServiceMock(showConnectDialogOnStartup: boolean): TypeMoq.Mock { @@ -138,8 +138,8 @@ suite('commandLineService tests', () => { .returns(() => new Promise((resolve, reject) => { resolve('unused'); })) .verifiable(TypeMoq.Times.never()); const configurationService = getConfigurationServiceMock(true); - let service = getCommandLineService(connectionManagementService.object, configurationService.object); - service.processCommandLine(new TestParsedArgs()).then(() => { + let contribution = getCommandLineContribution(connectionManagementService.object, configurationService.object); + contribution.processCommandLine(new TestParsedArgs()).then(() => { connectionManagementService.verifyAll(); done(); }, error => { assert.fail(error, null, 'processCommandLine rejected ' + error); done(); }); @@ -154,9 +154,9 @@ suite('commandLineService tests', () => { connectionManagementService.setup(c => c.connectIfNotConnected(TypeMoq.It.isAny(), TypeMoq.It.isAny())) .verifiable(TypeMoq.Times.never()); const configurationService = getConfigurationServiceMock(false); - let service = getCommandLineService(connectionManagementService.object, configurationService.object); + let contribution = getCommandLineContribution(connectionManagementService.object, configurationService.object); - await service.processCommandLine(new TestParsedArgs()); + await contribution.processCommandLine(new TestParsedArgs()); connectionManagementService.verifyAll(); }); @@ -170,9 +170,9 @@ suite('commandLineService tests', () => { .returns(() => new Promise((resolve, reject) => { resolve('unused'); })) .verifiable(TypeMoq.Times.never()); const configurationService = getConfigurationServiceMock(true); - let service = getCommandLineService(connectionManagementService.object, configurationService.object); + let contribution = getCommandLineContribution(connectionManagementService.object, configurationService.object); try { - await service.processCommandLine(new TestParsedArgs()); + await contribution.processCommandLine(new TestParsedArgs()); connectionManagementService.verifyAll(); } catch (error) { assert.fail(error, null, 'processCommandLine rejected ' + error); @@ -200,8 +200,8 @@ suite('commandLineService tests', () => { connectionManagementService.setup(c => c.getConnectionProfileById(TypeMoq.It.isAnyString())).returns(() => originalProfile); const configurationService = getConfigurationServiceMock(true); const logService = new NullLogService(); - let service = getCommandLineService(connectionManagementService.object, configurationService.object, capabilitiesService, undefined, undefined, logService); - await service.processCommandLine(args); + let contribution = getCommandLineContribution(connectionManagementService.object, configurationService.object, capabilitiesService, undefined, undefined, logService); + await contribution.processCommandLine(args); connectionManagementService.verifyAll(); }); @@ -224,8 +224,8 @@ suite('commandLineService tests', () => { }) .verifiable(TypeMoq.Times.once()); const configurationService = getConfigurationServiceMock(true); - let service = getCommandLineService(connectionManagementService.object, configurationService.object, capabilitiesService, commandService.object); - await service.processCommandLine(args); + let contribution = getCommandLineContribution(connectionManagementService.object, configurationService.object, capabilitiesService, commandService.object); + await contribution.processCommandLine(args); connectionManagementService.verifyAll(); commandService.verifyAll(); should(capturedArgs).be.undefined(); @@ -260,8 +260,8 @@ suite('commandLineService tests', () => { }) .verifiable(TypeMoq.Times.once()); const configurationService = getConfigurationServiceMock(true); - let service = getCommandLineService(connectionManagementService.object, configurationService.object, capabilitiesService, commandService.object); - await service.processCommandLine(args); + let contribution = getCommandLineContribution(connectionManagementService.object, configurationService.object, capabilitiesService, commandService.object); + await contribution.processCommandLine(args); connectionManagementService.verifyAll(); commandService.verifyAll(); should(actualProfile).not.be.undefined(); @@ -281,8 +281,8 @@ suite('commandLineService tests', () => { .returns(() => Promise.reject(new Error('myerror'))) .verifiable(TypeMoq.Times.once()); const configurationService = getConfigurationServiceMock(true); - let service = getCommandLineService(connectionManagementService.object, configurationService.object, capabilitiesService, commandService.object); - assertThrowsAsync(async () => await service.processCommandLine(args)); + let contribution = getCommandLineContribution(connectionManagementService.object, configurationService.object, capabilitiesService, commandService.object); + assertThrowsAsync(async () => await contribution.processCommandLine(args)); }); test('processCommandLine uses Integrated auth if no user name or auth type is passed', async () => { @@ -305,8 +305,8 @@ suite('commandLineService tests', () => { connectionManagementService.setup(c => c.getConnectionGroups(TypeMoq.It.isAny())).returns(() => []); const configurationService = getConfigurationServiceMock(true); const logService = new NullLogService(); - let service = getCommandLineService(connectionManagementService.object, configurationService.object, capabilitiesService, undefined, undefined, logService); - await service.processCommandLine(args); + let contribution = getCommandLineContribution(connectionManagementService.object, configurationService.object, capabilitiesService, undefined, undefined, logService); + await contribution.processCommandLine(args); connectionManagementService.verifyAll(); }); @@ -348,8 +348,8 @@ suite('commandLineService tests', () => { connectionManagementService.setup(x => x.getConnectionGroups(TypeMoq.It.isAny())).returns(() => [conProfGroup]); const configurationService = getConfigurationServiceMock(true); const logService = new NullLogService(); - let service = getCommandLineService(connectionManagementService.object, configurationService.object, capabilitiesService, undefined, undefined, logService); - await service.processCommandLine(args); + let contribution = getCommandLineContribution(connectionManagementService.object, configurationService.object, capabilitiesService, undefined, undefined, logService); + await contribution.processCommandLine(args); connectionManagementService.verifyAll(); }); @@ -385,8 +385,8 @@ suite('commandLineService tests', () => { uri.toString(), TypeMoq.It.is(i => i.params.input === queryInput.object && i.params.connectionType === ConnectionType.editor)) ).verifiable(TypeMoq.Times.once()); - let service = getCommandLineService(connectionManagementService.object, configurationService.object, capabilitiesService, undefined, editorService.object); - await service.processCommandLine(args); + let contribution = getCommandLineContribution(connectionManagementService.object, configurationService.object, capabilitiesService, undefined, editorService.object); + await contribution.processCommandLine(args); queryInput.verifyAll(); connectionManagementService.verifyAll(); }); diff --git a/src/sql/workbench/services/commandLine/common/commandLine.ts b/src/sql/workbench/services/commandLine/common/commandLine.ts deleted file mode 100644 index c621a949ea..0000000000 --- a/src/sql/workbench/services/commandLine/common/commandLine.ts +++ /dev/null @@ -1,18 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the Source EULA. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; -import { ParsedArgs } from 'vs/platform/environment/common/environment'; - -export interface ICommandLineProcessing { - _serviceBrand: any; - /** - * Interprets the various Azure Data Studio-specific command line switches and - * performs the requisite tasks such as connecting to a server - */ - processCommandLine(args: ParsedArgs): Promise; -} - -export const ICommandLineProcessing = createDecorator('commandLineService'); \ No newline at end of file diff --git a/src/vs/workbench/browser/workbench.ts b/src/vs/workbench/browser/workbench.ts index 08f3f35a9f..499e18c8d4 100644 --- a/src/vs/workbench/browser/workbench.ts +++ b/src/vs/workbench/browser/workbench.ts @@ -44,10 +44,6 @@ import { WorkbenchContextKeysHandler } from 'vs/workbench/browser/contextkeys'; import { coalesce } from 'vs/base/common/arrays'; import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService'; import { Layout } from 'vs/workbench/browser/layout'; -import { ICommandLineProcessing } from 'sql/workbench/services/commandLine/common/commandLine'; -import { CommandLineService } from 'sql/workbench/services/commandLine/common/commandLineService'; -import { IAdsTelemetryService } from 'sql/platform/telemetry/telemetry'; -import { AdsTelemetryService } from 'sql/platform/telemetry/adsTelemetryService'; export class Workbench extends Layout { @@ -183,11 +179,6 @@ export class Workbench extends Layout { const instantiationService = new InstantiationService(serviceCollection, true); - // {{SQL CARBON EDIT }} - // TODO@Davidshi commandLineService currently has no referents, so force its creation - serviceCollection.set(ICommandLineProcessing, instantiationService.createInstance(CommandLineService)); - // {{SQL CARBON EDIT}} - End - // Wrap up instantiationService.invokeFunction(accessor => { const lifecycleService = accessor.get(ILifecycleService); diff --git a/src/vs/workbench/workbench.main.ts b/src/vs/workbench/workbench.main.ts index 933c4bd735..3c64eb80af 100644 --- a/src/vs/workbench/workbench.main.ts +++ b/src/vs/workbench/workbench.main.ts @@ -525,3 +525,5 @@ import 'sql/workbench/parts/dashboard/browser/containers/dashboardContainer.cont import 'sql/workbench/parts/dashboard/browser/containers/dashboardNavSection.contribution'; import 'sql/workbench/parts/dashboard/browser/containers/dashboardModelViewContainer.contribution'; import 'sql/workbench/parts/dashboard/browser/core/dashboardTab.contribution'; + +import 'sql/workbench/parts/commandLine/electron-browser/commandLine.contribution';