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
This commit is contained in:
Anthony Dresser
2019-07-30 12:44:15 -07:00
committed by GitHub
parent 2c12b95e17
commit c99ce4de07
6 changed files with 40 additions and 55 deletions

View File

@@ -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<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(CommandLineWorkbenchContribution, LifecyclePhase.Restored);

View File

@@ -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,

View File

@@ -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<IConfigurationService> {
@@ -138,8 +138,8 @@ suite('commandLineService tests', () => {
.returns(() => new Promise<string>((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<string>((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<IConnectionCompletionOptions>(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();
});

View File

@@ -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<void>;
}
export const ICommandLineProcessing = createDecorator<ICommandLineProcessing>('commandLineService');