mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 01:25:37 -05:00
More layering and strictness (#9004)
* move handling generated files to the serilization classes * remove unneeded methods * add more folders to strictire compile, add more strict compile options * update ci * wip * add more layering and fix issues * add more strictness * remove unnecessary assertion * add missing checks * fix indentation * wip * remove jsdoc * fix layering * fix compile * fix compile errors * wip * wip * finish layering * fix css * more layering * remove no longer good parts * fix issues with startup * another try * fix startup
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { TreeViewItemHandleArg } from 'sql/workbench/common/views';
|
||||
import * as azdata from 'azdata';
|
||||
import { IOEShimService } from 'sql/workbench/contrib/objectExplorer/browser/objectExplorerViewTreeShim';
|
||||
import { IOEShimService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerViewTreeShim';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
|
||||
import { DATA_TIER_WIZARD_COMMAND_ID, PROFILER_COMMAND_ID, IMPORT_COMMAND_ID, SCHEMA_COMPARE_COMMAND_ID, GENERATE_SCRIPTS_COMMAND_ID, PROPERTIES_COMMAND_ID } from 'sql/workbench/contrib/dataExplorer/browser/extensionActions';
|
||||
import { ContextKeyExpr, ContextKeyRegexExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { MssqlNodeContext } from 'sql/workbench/contrib/dataExplorer/browser/mssqlNodeContext';
|
||||
import { MssqlNodeContext } from 'sql/workbench/services/objectExplorer/browser/mssqlNodeContext';
|
||||
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||
import { NodeType } from 'sql/workbench/contrib/objectExplorer/common/nodeType';
|
||||
import { NodeType } from 'sql/workbench/services/objectExplorer/common/nodeType';
|
||||
import { localize } from 'vs/nls';
|
||||
import { DatabaseEngineEdition } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
|
||||
|
||||
@@ -1,183 +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 * as azdata from 'azdata';
|
||||
import { INodeContextValue } from 'sql/workbench/contrib/dataExplorer/browser/nodeContext';
|
||||
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||
import { NodeType } from 'sql/workbench/contrib/objectExplorer/common/nodeType';
|
||||
import { ExtensionNodeType, DatabaseEngineEdition } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
|
||||
export class MssqlNodeContext extends Disposable {
|
||||
|
||||
static readonly canSelect = new Set([NodeType.Table, NodeType.View]);
|
||||
static readonly canEditData = new Set([NodeType.Table]);
|
||||
static readonly canCreateOrDelete = new Set([NodeType.AggregateFunction, NodeType.PartitionFunction, NodeType.ScalarValuedFunction,
|
||||
NodeType.Schema, NodeType.StoredProcedure, NodeType.Table, NodeType.TableValuedFunction,
|
||||
NodeType.User, NodeType.UserDefinedTableType, NodeType.View]);
|
||||
static readonly canExecute = new Set([NodeType.StoredProcedure]);
|
||||
static readonly canAlter = new Set([NodeType.AggregateFunction, NodeType.PartitionFunction, NodeType.ScalarValuedFunction,
|
||||
NodeType.StoredProcedure, NodeType.TableValuedFunction, NodeType.View]);
|
||||
|
||||
// General node context keys
|
||||
static NodeProvider = new RawContextKey<string>('nodeProvider', undefined);
|
||||
static IsDatabaseOrServer = new RawContextKey<boolean>('isDatabaseOrServer', false);
|
||||
static IsWindows = new RawContextKey<boolean>('isWindows', isWindows);
|
||||
static IsCloud = new RawContextKey<boolean>('isCloud', false);
|
||||
static NodeType = new RawContextKey<string>('nodeType', undefined);
|
||||
static NodeLabel = new RawContextKey<string>('nodeLabel', undefined);
|
||||
static EngineEdition = new RawContextKey<number>('engineEdition', DatabaseEngineEdition.Unknown);
|
||||
|
||||
// Scripting context keys
|
||||
static CanScriptAsSelect = new RawContextKey<boolean>('canScriptAsSelect', false);
|
||||
static CanEditData = new RawContextKey<boolean>('canEditData', false);
|
||||
static CanScriptAsCreateOrDelete = new RawContextKey<boolean>('canScriptAsCreateOeDelete', false);
|
||||
static CanScriptAsExecute = new RawContextKey<boolean>('canScriptAsExecute', false);
|
||||
static CanScriptAsAlter = new RawContextKey<boolean>('canScriptAsAlter', false);
|
||||
|
||||
private nodeProviderKey: IContextKey<string>;
|
||||
private isCloudKey: IContextKey<boolean>;
|
||||
private nodeTypeKey: IContextKey<string>;
|
||||
private nodeLabelKey: IContextKey<string>;
|
||||
private isDatabaseOrServerKey: IContextKey<boolean>;
|
||||
private engineEditionKey: IContextKey<number>;
|
||||
|
||||
private canScriptAsSelectKey: IContextKey<boolean>;
|
||||
private canEditDataKey: IContextKey<boolean>;
|
||||
private canScriptAsCreateOrDeleteKey: IContextKey<boolean>;
|
||||
private canScriptAsExecuteKey: IContextKey<boolean>;
|
||||
private canScriptAsAlterKey: IContextKey<boolean>;
|
||||
|
||||
constructor(
|
||||
private nodeContextValue: INodeContextValue,
|
||||
@IContextKeyService private contextKeyService: IContextKeyService,
|
||||
@IConnectionManagementService private connectionManagementService: IConnectionManagementService,
|
||||
@ICapabilitiesService private capabilitiesService: ICapabilitiesService
|
||||
) {
|
||||
super();
|
||||
this.bindContextKeys();
|
||||
|
||||
// Set additional node context keys
|
||||
if (this.nodeContextValue.node) {
|
||||
const node = this.nodeContextValue.node;
|
||||
if (node.payload) {
|
||||
this.setNodeProvider();
|
||||
this.setIsCloud();
|
||||
this.setEngineEdition();
|
||||
if (node.type) {
|
||||
this.setIsDatabaseOrServer();
|
||||
this.nodeTypeKey.set(node.type);
|
||||
} else if (node.contextValue && node.providerHandle === mssqlProviderName) {
|
||||
this.setIsDatabaseOrServer();
|
||||
this.setScriptingContextKeys();
|
||||
this.nodeTypeKey.set(node.contextValue);
|
||||
}
|
||||
}
|
||||
if (node.label) {
|
||||
this.nodeLabelKey.set(node.label.label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bindContextKeys(): void {
|
||||
this.isCloudKey = MssqlNodeContext.IsCloud.bindTo(this.contextKeyService);
|
||||
this.engineEditionKey = MssqlNodeContext.EngineEdition.bindTo(this.contextKeyService);
|
||||
this.nodeTypeKey = MssqlNodeContext.NodeType.bindTo(this.contextKeyService);
|
||||
this.nodeLabelKey = MssqlNodeContext.NodeLabel.bindTo(this.contextKeyService);
|
||||
this.isDatabaseOrServerKey = MssqlNodeContext.IsDatabaseOrServer.bindTo(this.contextKeyService);
|
||||
this.canScriptAsSelectKey = MssqlNodeContext.CanScriptAsSelect.bindTo(this.contextKeyService);
|
||||
this.canEditDataKey = MssqlNodeContext.CanEditData.bindTo(this.contextKeyService);
|
||||
this.canScriptAsCreateOrDeleteKey = MssqlNodeContext.CanScriptAsCreateOrDelete.bindTo(this.contextKeyService);
|
||||
this.canScriptAsExecuteKey = MssqlNodeContext.CanScriptAsExecute.bindTo(this.contextKeyService);
|
||||
this.canScriptAsAlterKey = MssqlNodeContext.CanScriptAsAlter.bindTo(this.contextKeyService);
|
||||
this.nodeProviderKey = MssqlNodeContext.NodeProvider.bindTo(this.contextKeyService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to get the node provider
|
||||
*/
|
||||
private setNodeProvider(): void {
|
||||
if (this.nodeContextValue.node.payload.providerName) {
|
||||
this.nodeProviderKey.set(this.nodeContextValue.node.payload.providerName);
|
||||
} else if (this.nodeContextValue.node.childProvider) {
|
||||
this.nodeProviderKey.set(this.nodeContextValue.node.childProvider);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to tell whether a connected node is cloud or not
|
||||
*/
|
||||
private setIsCloud(): void {
|
||||
let serverInfo: azdata.ServerInfo = this.getServerInfo();
|
||||
if (serverInfo && serverInfo.isCloud) {
|
||||
this.isCloudKey.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to set engine edition
|
||||
*/
|
||||
private setEngineEdition(): void {
|
||||
|
||||
let serverInfo: azdata.ServerInfo = this.getServerInfo();
|
||||
if (serverInfo && serverInfo.engineEditionId) {
|
||||
this.engineEditionKey.set(serverInfo.engineEditionId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function fetching the server info
|
||||
*/
|
||||
private getServerInfo(): azdata.ServerInfo | undefined {
|
||||
const profile = new ConnectionProfile(this.capabilitiesService,
|
||||
this.nodeContextValue.node.payload);
|
||||
const connection = this.connectionManagementService.findExistingConnection(profile);
|
||||
if (connection) {
|
||||
return this.connectionManagementService.getServerInfo(connection.id);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to tell whether a connected node is a database or a
|
||||
* server or not. Added this key because this is easier to write than
|
||||
* writing an OR statement in ContextKeyExpr
|
||||
*/
|
||||
private setIsDatabaseOrServer(): void {
|
||||
const isDatabaseOrServer = (this.nodeContextValue.node.contextValue === NodeType.Server ||
|
||||
this.nodeContextValue.node.contextValue === NodeType.Database ||
|
||||
this.nodeContextValue.node.type === ExtensionNodeType.Server ||
|
||||
this.nodeContextValue.node.type === ExtensionNodeType.Database);
|
||||
this.isDatabaseOrServerKey.set(isDatabaseOrServer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to get the correct context from node for showing
|
||||
* scripting context menu actions
|
||||
*/
|
||||
private setScriptingContextKeys(): void {
|
||||
const nodeType = this.nodeContextValue.node.contextValue;
|
||||
if (MssqlNodeContext.canCreateOrDelete.has(nodeType)) {
|
||||
this.canScriptAsCreateOrDeleteKey.set(true);
|
||||
}
|
||||
if (MssqlNodeContext.canEditData.has(nodeType)) {
|
||||
this.canEditDataKey.set(true);
|
||||
}
|
||||
if (MssqlNodeContext.canAlter.has(nodeType)) {
|
||||
this.canScriptAsAlterKey.set(true);
|
||||
}
|
||||
if (MssqlNodeContext.canExecute.has(nodeType)) {
|
||||
this.canScriptAsExecuteKey.set(true);
|
||||
}
|
||||
if (MssqlNodeContext.canSelect.has(nodeType)) {
|
||||
this.canScriptAsSelectKey.set(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,9 @@ import {
|
||||
DISCONNECT_COMMAND_ID, REFRESH_COMMAND_ID
|
||||
} from './nodeCommands.common';
|
||||
import { ContextKeyExpr, ContextKeyNotEqualsExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { NodeContextKey } from 'sql/workbench/contrib/dataExplorer/browser/nodeContext';
|
||||
import { MssqlNodeContext } from 'sql/workbench/contrib/dataExplorer/browser/mssqlNodeContext';
|
||||
import { NodeType } from 'sql/workbench/contrib/objectExplorer/common/nodeType';
|
||||
import { NodeContextKey } from 'sql/workbench/browser/parts/views/nodeContext';
|
||||
import { MssqlNodeContext } from 'sql/workbench/services/objectExplorer/browser/mssqlNodeContext';
|
||||
import { NodeType } from 'sql/workbench/services/objectExplorer/common/nodeType';
|
||||
|
||||
|
||||
// Disconnect
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IOEShimService } from 'sql/workbench/contrib/objectExplorer/browser/objectExplorerViewTreeShim';
|
||||
import { IOEShimService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerViewTreeShim';
|
||||
import { ICustomViewDescriptor, TreeViewItemHandleArg } from 'sql/workbench/common/views';
|
||||
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { IViewsRegistry, Extensions } from 'vs/workbench/common/views';
|
||||
|
||||
@@ -1,89 +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 { ConnectionContextKey } from 'sql/workbench/contrib/connection/common/connectionContextKey';
|
||||
import { IOEShimService } from 'sql/workbench/contrib/objectExplorer/browser/objectExplorerViewTreeShim';
|
||||
import { ITreeItem } from 'sql/workbench/common/views';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IQueryManagementService } from 'sql/workbench/services/query/common/queryManagement';
|
||||
import { MssqlNodeContext } from 'sql/workbench/contrib/dataExplorer/browser/mssqlNodeContext';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
|
||||
export interface INodeContextValue {
|
||||
node: ITreeItem;
|
||||
viewId: string;
|
||||
}
|
||||
|
||||
export class NodeContextKey extends Disposable implements IContextKey<INodeContextValue> {
|
||||
|
||||
static IsConnectable = new RawContextKey<boolean>('isConnectable', false);
|
||||
static IsConnected = new RawContextKey<boolean>('isConnected', false);
|
||||
static ViewId = new RawContextKey<string>('view', undefined);
|
||||
static ViewItem = new RawContextKey<string>('viewItem', undefined);
|
||||
static Node = new RawContextKey<INodeContextValue>('node', undefined);
|
||||
|
||||
private readonly _connectionContextKey: ConnectionContextKey;
|
||||
private readonly _connectableKey: IContextKey<boolean>;
|
||||
private readonly _connectedKey: IContextKey<boolean>;
|
||||
private readonly _viewIdKey: IContextKey<string>;
|
||||
private readonly _viewItemKey: IContextKey<string>;
|
||||
private readonly _nodeContextKey: IContextKey<INodeContextValue>;
|
||||
|
||||
private _nodeContextUtils: MssqlNodeContext;
|
||||
|
||||
constructor(
|
||||
@IContextKeyService private contextKeyService: IContextKeyService,
|
||||
@IOEShimService private oeService: IOEShimService,
|
||||
@IQueryManagementService queryManagementService: IQueryManagementService,
|
||||
@IConnectionManagementService private connectionManagementService: IConnectionManagementService,
|
||||
@ICapabilitiesService private capabilitiesService: ICapabilitiesService
|
||||
) {
|
||||
super();
|
||||
|
||||
this._connectableKey = NodeContextKey.IsConnectable.bindTo(contextKeyService);
|
||||
this._connectedKey = NodeContextKey.IsConnected.bindTo(contextKeyService);
|
||||
this._viewIdKey = NodeContextKey.ViewId.bindTo(contextKeyService);
|
||||
this._viewItemKey = NodeContextKey.ViewItem.bindTo(contextKeyService);
|
||||
this._nodeContextKey = NodeContextKey.Node.bindTo(contextKeyService);
|
||||
this._connectionContextKey = new ConnectionContextKey(contextKeyService, queryManagementService);
|
||||
}
|
||||
|
||||
set(value: INodeContextValue) {
|
||||
if (value.node && value.node.payload) {
|
||||
this._connectableKey.set(true);
|
||||
this._connectedKey.set(this.oeService.isNodeConnected(value.viewId, value.node));
|
||||
this._connectionContextKey.set(value.node.payload);
|
||||
} else {
|
||||
this._connectableKey.set(false);
|
||||
this._connectedKey.set(false);
|
||||
this._connectionContextKey.reset();
|
||||
}
|
||||
if (value.node) {
|
||||
this._viewItemKey.set(value.node.contextValue);
|
||||
} else {
|
||||
this._viewItemKey.reset();
|
||||
}
|
||||
this._nodeContextKey.set(value);
|
||||
this._viewIdKey.set(value.viewId);
|
||||
this._nodeContextUtils = new MssqlNodeContext(this._nodeContextKey.get(), this.contextKeyService,
|
||||
this.connectionManagementService, this.capabilitiesService);
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
this._viewIdKey.reset();
|
||||
this._viewItemKey.reset();
|
||||
this._connectableKey.reset();
|
||||
this._connectedKey.reset();
|
||||
this._connectionContextKey.reset();
|
||||
this._nodeContextKey.reset();
|
||||
this._nodeContextUtils.dispose();
|
||||
}
|
||||
|
||||
get(): INodeContextValue | undefined {
|
||||
return this._nodeContextKey.get();
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,14 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { INodeContextValue } from 'sql/workbench/contrib/dataExplorer/browser/nodeContext';
|
||||
import { INodeContextValue } from 'sql/workbench/browser/parts/views/nodeContext';
|
||||
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||
import { NodeType } from 'sql/workbench/contrib/objectExplorer/common/nodeType';
|
||||
import { ExtensionNodeType } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { NodeType } from 'sql/workbench/services/objectExplorer/common/nodeType';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
|
||||
export class NodeContextUtils extends Disposable {
|
||||
@@ -129,8 +128,8 @@ export class NodeContextUtils extends Disposable {
|
||||
private setIsDatabaseOrServer(): void {
|
||||
const isDatabaseOrServer = (this.nodeContextValue.node.contextValue === NodeType.Server ||
|
||||
this.nodeContextValue.node.contextValue === NodeType.Database ||
|
||||
this.nodeContextValue.node.type === ExtensionNodeType.Server ||
|
||||
this.nodeContextValue.node.type === ExtensionNodeType.Database);
|
||||
this.nodeContextValue.node.type === NodeType.Server ||
|
||||
this.nodeContextValue.node.type === NodeType.Database);
|
||||
this.isDatabaseOrServerKey.set(isDatabaseOrServer);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user