Fix refresh action (#8519)

* Fix refresh action

* Refactor to async

* Fix missing bracket

* Remove unused error level

* Add back in error message

* Fix missing service
This commit is contained in:
Charles Gagnon
2019-12-03 17:40:02 -08:00
committed by GitHub
parent 255ea1945b
commit 7f16a4d857

View File

@@ -20,9 +20,12 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService'; import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService';
import { TreeSelectionHandler } from 'sql/workbench/contrib/objectExplorer/browser/treeSelectionHandler'; import { TreeSelectionHandler } from 'sql/workbench/contrib/objectExplorer/browser/treeSelectionHandler';
import { TreeUpdateUtils } from 'sql/workbench/contrib/objectExplorer/browser/treeUpdateUtils'; import { TreeUpdateUtils } from 'sql/workbench/contrib/objectExplorer/browser/treeUpdateUtils';
import Severity from 'vs/base/common/severity';
import { TreeNode } from 'sql/workbench/contrib/objectExplorer/common/treeNode'; import { TreeNode } from 'sql/workbench/contrib/objectExplorer/common/treeNode';
import { VIEWLET_ID } from 'sql/workbench/contrib/dataExplorer/browser/dataExplorerViewlet'; import { VIEWLET_ID } from 'sql/workbench/contrib/dataExplorer/browser/dataExplorerViewlet';
import { ILogService } from 'vs/platform/log/common/log';
import { getErrorMessage } from 'vs/base/common/errors';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { localize } from 'vs/nls';
//#region -- Data Explorer //#region -- Data Explorer
export const SCRIPT_AS_CREATE_COMMAND_ID = 'dataExplorer.scriptAsCreate'; export const SCRIPT_AS_CREATE_COMMAND_ID = 'dataExplorer.scriptAsCreate';
@@ -307,39 +310,36 @@ CommandsRegistry.registerCommand({
// Refresh Action for Scriptable objects // Refresh Action for Scriptable objects
CommandsRegistry.registerCommand({ CommandsRegistry.registerCommand({
id: OE_REFRESH_COMMAND_ID, id: OE_REFRESH_COMMAND_ID,
handler: async (accessor, args: ObjectExplorerActionsContext) => { handler: async (accessor, args: ObjectExplorerActionsContext): Promise<void> => {
const connectionManagementService = accessor.get(IConnectionManagementService); const connectionManagementService = accessor.get(IConnectionManagementService);
const capabilitiesService = accessor.get(ICapabilitiesService); const capabilitiesService = accessor.get(ICapabilitiesService);
const objectExplorerService = accessor.get(IObjectExplorerService); const objectExplorerService = accessor.get(IObjectExplorerService);
const errorMessageService = accessor.get(IErrorMessageService); const logService = accessor.get(ILogService);
const notificationService = accessor.get(INotificationService);
const connection = new ConnectionProfile(capabilitiesService, args.connectionProfile); const connection = new ConnectionProfile(capabilitiesService, args.connectionProfile);
let treeNode: TreeNode;
if (connectionManagementService.isConnected(undefined, connection)) { if (connectionManagementService.isConnected(undefined, connection)) {
treeNode = await getTreeNode(args, objectExplorerService); let treeNode = await getTreeNode(args, objectExplorerService);
if (treeNode === undefined) { if (!treeNode) {
objectExplorerService.updateObjectExplorerNodes(connection.toIConnectionProfile()).then(() => { await objectExplorerService.updateObjectExplorerNodes(connection.toIConnectionProfile());
treeNode = objectExplorerService.getObjectExplorerNode(connection); treeNode = objectExplorerService.getObjectExplorerNode(connection);
});
} }
}
const tree = objectExplorerService.getServerTreeView().tree;
if (treeNode) { if (treeNode) {
return tree.collapse(treeNode).then(() => { const tree = objectExplorerService.getServerTreeView().tree;
return objectExplorerService.refreshTreeNode(treeNode.getSession(), treeNode).then(() => { try {
return tree.refresh(treeNode).then(() => { await tree.collapse(treeNode);
return tree.expand(treeNode); await objectExplorerService.refreshTreeNode(treeNode.getSession(), treeNode);
}, refreshError => { await tree.refresh(treeNode);
return Promise.resolve(true); await tree.expand(treeNode);
}); } catch (err) {
}, error => { // Display message to the user but also log the entire error to the console for the stack trace
errorMessageService.showDialog(Severity.Error, '', error); notificationService.error(localize('refreshError', "An error occurred refreshing node '{0}': {1}", args.nodeInfo.label, getErrorMessage(err)));
return Promise.resolve(true); logService.error(err);
}); }
}, collapseError => {
return Promise.resolve(true); } else {
}); logService.error(`Could not find tree node for node ${args.nodeInfo.label}`);
}
} }
return Promise.resolve(true);
} }
}); });
//#endregion //#endregion