diff --git a/src/sql/parts/objectExplorer/viewlet/serverTreeView.ts b/src/sql/parts/objectExplorer/viewlet/serverTreeView.ts index 8947bf13cd..453e54f2f2 100644 --- a/src/sql/parts/objectExplorer/viewlet/serverTreeView.ts +++ b/src/sql/parts/objectExplorer/viewlet/serverTreeView.ts @@ -32,6 +32,7 @@ import { TreeNode, TreeItemCollapsibleState } from 'sql/parts/objectExplorer/com import { SERVER_GROUP_CONFIG, SERVER_GROUP_AUTOEXPAND_CONFIG } from 'sql/parts/objectExplorer/serverGroupDialog/serverGroup.contribution'; import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMessageService'; import { ServerTreeActionProvider } from 'sql/parts/objectExplorer/viewlet/serverTreeActionProvider'; +import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService'; const $ = builder.$; @@ -54,7 +55,8 @@ export class ServerTreeView { @IObjectExplorerService private _objectExplorerService: IObjectExplorerService, @IThemeService private _themeService: IThemeService, @IErrorMessageService private _errorMessageService: IErrorMessageService, - @IConfigurationService private _configurationService: IConfigurationService + @IConfigurationService private _configurationService: IConfigurationService, + @ICapabilitiesService capabilitiesService: ICapabilitiesService ) { this._activeConnectionsFilterAction = this._instantiationService.createInstance( ActiveConnectionsFilterAction, @@ -64,6 +66,12 @@ export class ServerTreeView { this._treeSelectionHandler = this._instantiationService.createInstance(TreeSelectionHandler); this._onSelectionOrFocusChange = new Emitter(); this._actionProvider = this._instantiationService.createInstance(ServerTreeActionProvider); + capabilitiesService.onCapabilitiesRegistered(() => { + if (this._connectionManagementService.hasRegisteredServers()) { + this.refreshTree(); + this._treeSelectionHandler.onTreeActionStateChange(false); + } + }); } /** diff --git a/src/sqltest/parts/connection/connectionTreeActions.test.ts b/src/sqltest/parts/connection/connectionTreeActions.test.ts index e512234405..949b68243a 100644 --- a/src/sqltest/parts/connection/connectionTreeActions.test.ts +++ b/src/sqltest/parts/connection/connectionTreeActions.test.ts @@ -205,7 +205,7 @@ suite('SQL Connection Tree Action tests', () => { return new TPromise((resolve) => resolve({})); }); - let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined); + let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined, undefined, capabilitiesService); serverTreeView.setup(x => x.showFilteredTree(TypeMoq.It.isAnyString())); serverTreeView.setup(x => x.refreshTree()); let connectionTreeAction: ActiveConnectionsFilterAction = new ActiveConnectionsFilterAction(ActiveConnectionsFilterAction.ID, ActiveConnectionsFilterAction.LABEL, serverTreeView.object, connectionManagementService.object); @@ -222,7 +222,7 @@ suite('SQL Connection Tree Action tests', () => { return new TPromise((resolve) => resolve({})); }); - let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined); + let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined, undefined, capabilitiesService); serverTreeView.setup(x => x.showFilteredTree(TypeMoq.It.isAnyString())); serverTreeView.setup(x => x.refreshTree()); let connectionTreeAction: ActiveConnectionsFilterAction = new ActiveConnectionsFilterAction(ActiveConnectionsFilterAction.ID, ActiveConnectionsFilterAction.LABEL, serverTreeView.object, connectionManagementService.object); @@ -240,7 +240,7 @@ suite('SQL Connection Tree Action tests', () => { return new TPromise((resolve) => resolve({})); }); - let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined); + let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined, undefined, capabilitiesService); serverTreeView.setup(x => x.showFilteredTree(TypeMoq.It.isAnyString())); serverTreeView.setup(x => x.refreshTree()); let connectionTreeAction: RecentConnectionsFilterAction = new RecentConnectionsFilterAction(RecentConnectionsFilterAction.ID, RecentConnectionsFilterAction.LABEL, serverTreeView.object, connectionManagementService.object); @@ -257,7 +257,7 @@ suite('SQL Connection Tree Action tests', () => { return new TPromise((resolve) => resolve({})); }); - let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined); + let serverTreeView = TypeMoq.Mock.ofType(ServerTreeView, TypeMoq.MockBehavior.Strict, undefined, instantiationService.object, undefined, undefined, undefined, undefined, capabilitiesService); serverTreeView.setup(x => x.showFilteredTree(TypeMoq.It.isAnyString())); serverTreeView.setup(x => x.refreshTree()); let connectionTreeAction: RecentConnectionsFilterAction = new RecentConnectionsFilterAction(RecentConnectionsFilterAction.ID, RecentConnectionsFilterAction.LABEL, serverTreeView.object, connectionManagementService.object); diff --git a/src/sqltest/parts/registeredServer/viewlet/serverTreeView.test.ts b/src/sqltest/parts/registeredServer/viewlet/serverTreeView.test.ts index b24c927e3d..1cd2e8c273 100644 --- a/src/sqltest/parts/registeredServer/viewlet/serverTreeView.test.ts +++ b/src/sqltest/parts/registeredServer/viewlet/serverTreeView.test.ts @@ -14,18 +14,21 @@ import { TestInstantiationService } from 'vs/platform/instantiation/test/common/ import { TestStorageService } from 'vs/workbench/test/workbenchTestServices'; import * as TypeMoq from 'typemoq'; +import { CapabilitiesTestService } from 'sqltest/stubs/capabilitiesTestService'; suite('ServerTreeView onAddConnectionProfile handler tests', () => { let serverTreeView: ServerTreeView; let mockTree: TypeMoq.Mock; let mockRefreshTreeMethod: TypeMoq.Mock; + let capabilitiesService = new CapabilitiesTestService(); setup(() => { let instantiationService = new TestInstantiationService(); let mockConnectionManagementService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Strict, {}, {}, new TestStorageService()); mockConnectionManagementService.setup(x => x.getConnectionGroups()).returns(x => []); - serverTreeView = new ServerTreeView(mockConnectionManagementService.object, instantiationService, undefined, undefined, undefined, undefined); + mockConnectionManagementService.setup(x => x.hasRegisteredServers()).returns(() => true); + serverTreeView = new ServerTreeView(mockConnectionManagementService.object, instantiationService, undefined, undefined, undefined, undefined, capabilitiesService); let tree = { clearSelection() { }, getSelection() { }, @@ -91,4 +94,9 @@ suite('ServerTreeView onAddConnectionProfile handler tests', () => { mockTree.verify(x => x.clearSelection(), TypeMoq.Times.never()); mockTree.verify(x => x.select(TypeMoq.It.isAny()), TypeMoq.Times.never()); }); + + test('The tree refreshes when new capabilities are registered', () => { + capabilitiesService.fireCapabilitiesRegistered(undefined); + mockRefreshTreeMethod.verify(x => x(), TypeMoq.Times.once()); + }); }); diff --git a/src/sqltest/stubs/capabilitiesTestService.ts b/src/sqltest/stubs/capabilitiesTestService.ts index d0ca7ae377..4c7eb386a0 100644 --- a/src/sqltest/stubs/capabilitiesTestService.ts +++ b/src/sqltest/stubs/capabilitiesTestService.ts @@ -138,6 +138,10 @@ export class CapabilitiesTestService implements ICapabilitiesService { return Promise.resolve(null); } + public fireCapabilitiesRegistered(providerFeatures: ProviderFeatures): void { + this._onCapabilitiesRegistered.fire(providerFeatures); + } + private _onCapabilitiesRegistered = new Emitter(); public readonly onCapabilitiesRegistered = this._onCapabilitiesRegistered.event; }