only show new query when query is supported (#17346)

* only show new query when query is supported

* test case fix and pr comments

* rename context key
This commit is contained in:
Alan Ren
2021-10-13 13:01:31 -07:00
committed by GitHub
parent 547ceba501
commit 156f8f1d5f
13 changed files with 66 additions and 20 deletions

View File

@@ -48,6 +48,7 @@ export class MssqlNodeContext extends Disposable {
static CanScriptAsCreateOrDelete = new RawContextKey<boolean>('canScriptAsCreateOeDelete', false);
static CanScriptAsExecute = new RawContextKey<boolean>('canScriptAsExecute', false);
static CanScriptAsAlter = new RawContextKey<boolean>('canScriptAsAlter', false);
static IsQueryProvider = new RawContextKey<boolean>('isQueryProvider', false);
private nodeProviderKey!: IContextKey<string>;
private isCloudKey!: IContextKey<boolean>;
@@ -62,6 +63,8 @@ export class MssqlNodeContext extends Disposable {
private canScriptAsCreateOrDeleteKey!: IContextKey<boolean>;
private canScriptAsExecuteKey!: IContextKey<boolean>;
private canScriptAsAlterKey!: IContextKey<boolean>;
private isQueryProviderKey!: IContextKey<boolean>;
constructor(
private nodeContextValue: INodeContextValue,
@@ -88,6 +91,7 @@ export class MssqlNodeContext extends Disposable {
this.setScriptingContextKeys();
this.nodeTypeKey.set(node.contextValue);
}
this.setQueryEnabledKey();
}
if (node.label) {
this.nodeLabelKey.set(node.label.label);
@@ -108,6 +112,7 @@ export class MssqlNodeContext extends Disposable {
this.canScriptAsAlterKey = MssqlNodeContext.CanScriptAsAlter.bindTo(this.contextKeyService);
this.nodeProviderKey = MssqlNodeContext.NodeProvider.bindTo(this.contextKeyService);
this.canOpenInAzurePortal = MssqlNodeContext.CanOpenInAzurePortal.bindTo(this.contextKeyService);
this.isQueryProviderKey = MssqlNodeContext.IsQueryProvider.bindTo(this.contextKeyService);
}
/**
@@ -203,4 +208,13 @@ export class MssqlNodeContext extends Disposable {
this.canScriptAsSelectKey.set(true);
}
}
/**
* Set whether the current node's provider is also a query provider.
*/
private setQueryEnabledKey(): void {
const provider = this.nodeContextValue?.node?.payload?.providerName || this.nodeContextValue.node.childProvider;
const capabilities = provider ? this.capabilitiesService.getCapabilities(provider) : undefined;
this.isQueryProviderKey.set(capabilities?.connection.isQueryProvider);
}
}

View File

@@ -25,6 +25,7 @@ import { IQueryManagementService } from 'sql/workbench/services/query/common/que
import { ServerInfoContextKey } from 'sql/workbench/services/connection/common/serverInfoContextKey';
import { fillInActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { AsyncServerTree, ServerTreeElement } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
/**
* Provides actions for the server tree elements
@@ -36,7 +37,8 @@ export class ServerTreeActionProvider {
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@IQueryManagementService private _queryManagementService: IQueryManagementService,
@IMenuService private menuService: IMenuService,
@IContextKeyService private _contextKeyService: IContextKeyService
@IContextKeyService private _contextKeyService: IContextKeyService,
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService
) {
}
@@ -68,6 +70,7 @@ export class ServerTreeActionProvider {
*/
private getConnectionActions(tree: AsyncServerTree | ITree, profile: ConnectionProfile): IAction[] {
let node = new TreeNode(NodeType.Server, '', false, '', '', '', undefined, undefined, undefined, undefined);
node.connection = profile;
return this.getAllActions({
tree: tree,
profile: profile,
@@ -146,7 +149,7 @@ export class ServerTreeActionProvider {
serverInfoContextKey.set(serverInfo);
}
}
let treeNodeContextKey = new TreeNodeContextKey(scopedContextService);
let treeNodeContextKey = new TreeNodeContextKey(scopedContextService, this._capabilitiesService);
if (context.treeNode) {
treeNodeContextKey.set(context.treeNode);
}

View File

@@ -5,6 +5,7 @@
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { TreeNode } from 'sql/workbench/services/objectExplorer/common/treeNode';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
export class TreeNodeContextKey implements IContextKey<TreeNode> {
@@ -14,6 +15,7 @@ export class TreeNodeContextKey implements IContextKey<TreeNode> {
static TreeNode = new RawContextKey<TreeNode>('treeNode', undefined);
static NodeLabel = new RawContextKey<string>('nodeLabel', undefined);
static NodePath = new RawContextKey<string>('nodePath', undefined);
static IsQueryProvider = new RawContextKey<boolean>('isQueryProvider', false);
private _nodeTypeKey: IContextKey<string>;
private _subTypeKey: IContextKey<string>;
@@ -21,9 +23,11 @@ export class TreeNodeContextKey implements IContextKey<TreeNode> {
private _treeNodeKey: IContextKey<TreeNode>;
private _nodeLabelKey: IContextKey<string>;
private _nodePathKey: IContextKey<string>;
private _isQueryProvider: IContextKey<boolean>;
constructor(
@IContextKeyService contextKeyService: IContextKeyService
@IContextKeyService contextKeyService: IContextKeyService,
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService
) {
this._nodeTypeKey = TreeNodeContextKey.NodeType.bindTo(contextKeyService);
this._subTypeKey = TreeNodeContextKey.SubType.bindTo(contextKeyService);
@@ -31,6 +35,7 @@ export class TreeNodeContextKey implements IContextKey<TreeNode> {
this._treeNodeKey = TreeNodeContextKey.TreeNode.bindTo(contextKeyService);
this._nodeLabelKey = TreeNodeContextKey.NodeLabel.bindTo(contextKeyService);
this._nodePathKey = TreeNodeContextKey.NodePath.bindTo(contextKeyService);
this._isQueryProvider = TreeNodeContextKey.IsQueryProvider.bindTo(contextKeyService);
}
set(value: TreeNode) {
@@ -42,6 +47,9 @@ export class TreeNodeContextKey implements IContextKey<TreeNode> {
}
this._nodeLabelKey.set(value && value.label);
this._nodePathKey.set(value && value.nodePath);
const connectionProfile = value.getConnectionProfile();
const capabilities = connectionProfile ? this._capabilitiesService.getCapabilities(connectionProfile.providerName) : undefined;
this._isQueryProvider.set(capabilities?.connection.isQueryProvider);
}
reset(): void {
@@ -51,6 +59,7 @@ export class TreeNodeContextKey implements IContextKey<TreeNode> {
this._treeNodeKey.reset();
this._nodeLabelKey.reset();
this._nodePathKey.reset();
this._isQueryProvider.reset();
}
public get(): TreeNode | undefined {