handle unsupported connections in OE/Recent connections view (#20588)

* handle unknown provider in OE

* more update

* add comment

* test
This commit is contained in:
Alan Ren
2022-09-12 11:48:08 -07:00
committed by GitHub
parent b5408495b9
commit 6015c8e2f4
8 changed files with 67 additions and 46 deletions

View File

@@ -42,6 +42,7 @@ import { AsyncServerTree, ServerTreeElement } from 'sql/workbench/services/objec
import { coalesce } from 'vs/base/common/arrays';
import { CONNECTIONS_SORT_BY_CONFIG_KEY } from 'sql/platform/connection/common/connectionConfig';
import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { debounce } from 'vs/base/common/decorators';
export const CONTEXT_SERVER_TREE_VIEW = new RawContextKey<ServerTreeViewView>('serverTreeView.view', ServerTreeViewView.all);
export const CONTEXT_SERVER_TREE_HAS_CONNECTIONS = new RawContextKey<boolean>('serverTreeView.hasConnections', false);
@@ -67,7 +68,7 @@ export class ServerTreeView extends Disposable implements IServerTreeView {
@IThemeService private _themeService: IThemeService,
@IErrorMessageService private _errorMessageService: IErrorMessageService,
@IConfigurationService private _configurationService: IConfigurationService,
@ICapabilitiesService capabilitiesService: ICapabilitiesService,
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService,
@IContextMenuService private _contextMenuService: IContextMenuService,
@IKeybindingService private _keybindingService: IKeybindingService,
@IContextKeyService contextKeyService: IContextKeyService
@@ -78,23 +79,28 @@ export class ServerTreeView extends Disposable implements IServerTreeView {
this._treeSelectionHandler = this._instantiationService.createInstance(TreeSelectionHandler);
this._onSelectionOrFocusChange = new Emitter();
this._actionProvider = this._instantiationService.createInstance(ServerTreeActionProvider);
capabilitiesService.onCapabilitiesRegistered(async () => {
if (this._tree instanceof AsyncServerTree) {
// Refresh the tree input now that the capabilities are registered so that we can
// get the full ConnectionProfiles with the server info updated properly
const treeInput = TreeUpdateUtils.getTreeInput(this._connectionManagementService)!;
await this._tree.setInput(treeInput);
this._treeSelectionHandler.onTreeActionStateChange(false);
} else {
if (this._connectionManagementService.hasRegisteredServers()) {
await this.refreshTree();
this._treeSelectionHandler.onTreeActionStateChange(false);
}
}
this._capabilitiesService.onCapabilitiesRegistered(async () => {
await this.handleOnCapabilitiesRegistered();
});
this.registerCommands();
}
@debounce(50)
private async handleOnCapabilitiesRegistered(): Promise<void> {
if (this._tree instanceof AsyncServerTree) {
// Refresh the tree input now that the capabilities are registered so that we can
// get the full ConnectionProfiles with the server info updated properly
const treeInput = TreeUpdateUtils.getTreeInput(this._connectionManagementService)!;
await this._tree.setInput(treeInput);
this._treeSelectionHandler.onTreeActionStateChange(false);
} else {
if (this._connectionManagementService.hasRegisteredServers()) {
await this.refreshTree();
this._treeSelectionHandler.onTreeActionStateChange(false);
}
}
}
public get view(): ServerTreeViewView {
return this._viewKey.get();
}
@@ -532,7 +538,7 @@ export class ServerTreeView extends Disposable implements IServerTreeView {
}
private onSelected(event: any): void {
this._treeSelectionHandler.onTreeSelect(event, this._tree!, this._connectionManagementService, this._objectExplorerService, () => this._onSelectionOrFocusChange.fire());
this._treeSelectionHandler.onTreeSelect(event, this._tree!, this._connectionManagementService, this._objectExplorerService, this._capabilitiesService, () => this._onSelectionOrFocusChange.fire());
this._onSelectionOrFocusChange.fire();
}

View File

@@ -169,8 +169,12 @@ suite('ServerTreeView onAddConnectionProfile handler tests', () => {
mockTree.verify(x => x.select(TypeMoq.It.isAny()), TypeMoq.Times.never());
});
test('The tree refreshes when new capabilities are registered', () => {
test('The tree refreshes when new capabilities are registered', (done) => {
capabilitiesService.fireCapabilitiesRegistered(undefined, undefined);
mockRefreshTreeMethod.verify(x => x(), TypeMoq.Times.once());
// A debounce is added to the handler, we need to wait a bit before checking.
setTimeout(() => {
mockRefreshTreeMethod.verify(x => x(), TypeMoq.Times.once());
done();
}, 100);
});
});