mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-01 09:35:41 -05:00
Initial support for SQLCMD variables in sql project tree (#21574)
* initial changes * sqlcmd node showing in tree * Add edit sqlcmdvar command * remove commands on sqlcmd vars for now * cleanup * fix tests * add icons * remove TestProject * add checks for undefined * add variable
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M2 2L1 3V12L2 13H14L15 12V3L14 2H2ZM2 12V3H14V12H2ZM5.3556 8.93017H6V7.22067C6 6.40689 5.68534 6 5.05603 6C4.92098 6 4.77083 6.02421 4.6056 6.07263C4.44181 6.12104 4.3125 6.17691 4.21767 6.24022V6.90503C4.45474 6.70205 4.70474 6.60056 4.96767 6.60056C5.22917 6.60056 5.35991 6.75698 5.35991 7.06983L4.76078 7.17318C4.25359 7.25885 4 7.57914 4 8.13408C4 8.39665 4.06106 8.60708 4.18319 8.76536C4.30675 8.92179 4.47557 9 4.68966 9C4.97989 9 5.19899 8.83985 5.34698 8.51955H5.3556V8.93017ZM5.35991 7.57542V7.76816C5.35991 7.9432 5.31968 8.08845 5.23922 8.20391C5.15876 8.3175 5.0546 8.3743 4.92672 8.3743C4.83477 8.3743 4.76149 8.34264 4.7069 8.27933C4.65374 8.21415 4.62716 8.13128 4.62716 8.03073C4.62716 7.80912 4.73779 7.6797 4.95905 7.64246L5.35991 7.57542ZM7.60094 8.62622H7.59343V8.93511H7V5H7.59343V6.67683H7.60094C7.74742 6.36708 7.95587 6.2122 8.22629 6.2122C8.47418 6.2122 8.6651 6.32987 8.79906 6.56522C8.93302 6.80056 9 7.12243 9 7.53082C9 7.97383 8.92175 8.32944 8.76526 8.59766C8.60876 8.86589 8.39969 9 8.13803 9C7.90141 9 7.72238 8.87541 7.60094 8.62622ZM7.58404 7.50487V7.77742C7.58404 7.94873 7.61972 8.09063 7.69108 8.20311C7.76244 8.3156 7.85383 8.37184 7.96526 8.37184C8.10047 8.37184 8.20501 8.30002 8.27887 8.15639C8.35399 8.01103 8.39155 7.80597 8.39155 7.54121C8.39155 7.32144 8.35712 7.15012 8.28826 7.02726C8.22066 6.90266 8.12363 6.84036 7.99718 6.84036C7.87825 6.84036 7.77934 6.9018 7.70047 7.02466C7.62285 7.14752 7.58404 7.30759 7.58404 7.50487ZM11.2616 9C11.5834 9 11.8295 8.94227 12 8.82682V8.11732C11.82 8.25512 11.636 8.32402 11.448 8.32402C11.2362 8.32402 11.0697 8.25233 10.9486 8.10894C10.8276 7.96369 10.767 7.76443 10.767 7.51117C10.767 7.25047 10.8299 7.04656 10.9558 6.89944C11.0832 6.75047 11.2553 6.67598 11.4719 6.67598C11.6663 6.67598 11.8423 6.74488 12 6.88268V6.13408C11.871 6.04469 11.6623 6 11.374 6C10.9566 6 10.6229 6.1406 10.3728 6.42179C10.1243 6.70112 10 7.0838 10 7.56983C10 7.99069 10.1163 8.33426 10.3489 8.60056C10.5814 8.86685 10.8857 9 11.2616 9Z" fill="#C5C5C5"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.1 KiB |
@@ -0,0 +1,3 @@
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M2 5H4V4H1.5L1 4.5V12.5L1.5 13H4V12H2V5ZM14.5 4H12V5H14V12H12V13H14.5L15 12.5V4.5L14.5 4ZM11.76 6.56995L12 7V9.51001L11.7 9.95996L7.19995 11.96H6.73999L4.23999 10.46L4 10.03V7.53003L4.30005 7.06995L8.80005 5.06995H9.26001L11.76 6.56995ZM5 9.70996L6.5 10.61V9.28003L5 8.38V9.70996ZM5.57996 7.56006L7.03003 8.43005L10.42 6.93005L8.96997 6.06006L5.57996 7.56006ZM7.53003 10.73L11.03 9.17004V7.77002L7.53003 9.31995V10.73Z" fill="#75BEFF"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 589 B |
@@ -0,0 +1,3 @@
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M2.00024 2L1.00024 3V12L2.00024 13H14.0002L15.0002 12V3L14.0002 2H2.00024ZM2.00024 12V3H14.0002V12H2.00024ZM5.35585 8.93017H6.00024V7.22067C6.00024 6.40689 5.68559 6 5.05628 6C4.92122 6 4.77108 6.02421 4.60585 6.07263C4.44205 6.12104 4.31274 6.17691 4.21792 6.24022V6.90503C4.45499 6.70205 4.70499 6.60056 4.96792 6.60056C5.22941 6.60056 5.36016 6.75698 5.36016 7.06983L4.76102 7.17318C4.25384 7.25885 4.00024 7.57914 4.00024 8.13408C4.00024 8.39665 4.06131 8.60708 4.18343 8.76536C4.307 8.92179 4.47582 9 4.6899 9C4.98013 9 5.19924 8.83985 5.34723 8.51955H5.35585V8.93017ZM5.36016 7.57542V7.76816C5.36016 7.9432 5.31993 8.08845 5.23947 8.20391C5.15901 8.3175 5.05484 8.3743 4.92697 8.3743C4.83501 8.3743 4.76174 8.34264 4.70714 8.27933C4.65398 8.21415 4.6274 8.13128 4.6274 8.03073C4.6274 7.80912 4.73803 7.6797 4.9593 7.64246L5.36016 7.57542ZM7.60118 8.62622H7.59367V8.93511H7.00024V5H7.59367V6.67683H7.60118C7.74766 6.36708 7.95611 6.2122 8.22653 6.2122C8.47442 6.2122 8.66535 6.32987 8.7993 6.56522C8.93326 6.80056 9.00024 7.12243 9.00024 7.53082C9.00024 7.97383 8.922 8.32944 8.7655 8.59766C8.60901 8.86589 8.39993 9 8.13827 9C7.90165 9 7.72262 8.87541 7.60118 8.62622ZM7.58428 7.50487V7.77742C7.58428 7.94873 7.61996 8.09063 7.69132 8.20311C7.76269 8.3156 7.85408 8.37184 7.9655 8.37184C8.10071 8.37184 8.20525 8.30002 8.27912 8.15639C8.35423 8.01103 8.39179 7.80597 8.39179 7.54121C8.39179 7.32144 8.35736 7.15012 8.28851 7.02726C8.2209 6.90266 8.12387 6.84036 7.99743 6.84036C7.87849 6.84036 7.77959 6.9018 7.70071 7.02466C7.62309 7.14752 7.58428 7.30759 7.58428 7.50487ZM11.2619 9C11.5837 9 11.8298 8.94227 12.0002 8.82682V8.11732C11.8202 8.25512 11.6362 8.32402 11.4483 8.32402C11.2364 8.32402 11.0699 8.25233 10.9489 8.10894C10.8278 7.96369 10.7673 7.76443 10.7673 7.51117C10.7673 7.25047 10.8302 7.04656 10.956 6.89944C11.0835 6.75047 11.2555 6.67598 11.4722 6.67598C11.6665 6.67598 11.8425 6.74488 12.0002 6.88268V6.13408C11.8712 6.04469 11.6625 6 11.3742 6C10.9568 6 10.6231 6.1406 10.373 6.42179C10.1245 6.70112 10.0002 7.0838 10.0002 7.56983C10.0002 7.99069 10.1165 8.33426 10.3491 8.60056C10.5817 8.86685 10.8859 9 11.2619 9Z" fill="#424242"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.3 KiB |
@@ -0,0 +1,3 @@
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M2.00024 5H4.00024V4H1.50024L1.00024 4.5V12.5L1.50024 13H4.00024V12H2.00024V5ZM14.5002 4H12.0002V5H14.0002V12H12.0002V13H14.5002L15.0002 12.5V4.5L14.5002 4ZM11.7603 6.56995L12.0002 7V9.51001L11.7002 9.95996L7.2002 11.96H6.74023L4.24023 10.46L4.00024 10.03V7.53003L4.30029 7.06995L8.80029 5.06995H9.26025L11.7603 6.56995ZM5.00024 9.70996L6.50024 10.61V9.28003L5.00024 8.38V9.70996ZM5.5802 7.56006L7.03027 8.43005L10.4203 6.93005L8.97021 6.06006L5.5802 7.56006ZM7.53027 10.73L11.0303 9.17004V7.77002L7.53027 9.31995V10.73Z" fill="#007ACC"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 691 B |
@@ -79,6 +79,7 @@ export const refreshDataWorkspaceCommand = 'dataworkspace.refresh';
|
||||
// UI Strings
|
||||
export const dataSourcesNodeName = localize('dataSourcesNodeName', "Data Sources");
|
||||
export const databaseReferencesNodeName = localize('databaseReferencesNodeName', "Database References");
|
||||
export const sqlcmdVariablesNodeName = localize('sqlcmdVariablesNodeName', "SQLCMD Variables");
|
||||
export const sqlConnectionStringFriendly = localize('sqlConnectionStringFriendly', "SQL connection string");
|
||||
export const yesString = localize('yesString', "Yes");
|
||||
export const openEulaString = localize('openEulaString', "Open License Agreement");
|
||||
@@ -553,6 +554,8 @@ export enum DatabaseProjectItemType {
|
||||
referencesRoot = 'databaseProject.itemType.referencesRoot',
|
||||
reference = 'databaseProject.itemType.reference',
|
||||
dataSourceRoot = 'databaseProject.itemType.dataSourceRoot',
|
||||
sqlcmdVariablesRoot = 'databaseProject.itemType.sqlcmdVariablesRoot',
|
||||
sqlcmdVariable = 'databaseProject.itemType.sqlcmdVariable'
|
||||
}
|
||||
|
||||
// AutoRest
|
||||
|
||||
@@ -24,6 +24,9 @@ export class IconPathHelper {
|
||||
public static referenceGroup: IconPath;
|
||||
public static referenceDatabase: IconPath;
|
||||
|
||||
public static sqlCmdVariablesGroup: IconPath;
|
||||
public static sqlCmdVariable: IconPath;
|
||||
|
||||
public static refresh: IconPath;
|
||||
public static folder_blue: IconPath;
|
||||
public static selectConnection: IconPath;
|
||||
@@ -57,6 +60,9 @@ export class IconPathHelper {
|
||||
IconPathHelper.referenceGroup = IconPathHelper.makeIcon('referenceGroup');
|
||||
IconPathHelper.referenceDatabase = IconPathHelper.makeIcon('reference-database');
|
||||
|
||||
IconPathHelper.sqlCmdVariablesGroup = IconPathHelper.makeIcon('symbol-string');
|
||||
IconPathHelper.sqlCmdVariable = IconPathHelper.makeIcon('symbol-variable');
|
||||
|
||||
IconPathHelper.refresh = IconPathHelper.makeIcon('refresh', true);
|
||||
IconPathHelper.folder_blue = IconPathHelper.makeIcon('folder_blue', true);
|
||||
IconPathHelper.selectConnection = IconPathHelper.makeIcon('selectConnection', true);
|
||||
|
||||
@@ -16,6 +16,7 @@ import { IconPathHelper } from '../../common/iconHelper';
|
||||
import { FileProjectEntry } from '../projectEntry';
|
||||
import { EntryType } from 'sqldbproj';
|
||||
import { DBProjectConfigurationKey } from '../../tools/netcoreTool';
|
||||
import { SqlCmdVariablesTreeItem } from './sqlcmdVariableTreeItem';
|
||||
|
||||
/**
|
||||
* TreeNode root that represents an entire project
|
||||
@@ -23,6 +24,7 @@ import { DBProjectConfigurationKey } from '../../tools/netcoreTool';
|
||||
export class ProjectRootTreeItem extends BaseProjectTreeItem {
|
||||
dataSourceNode: DataSourcesTreeItem;
|
||||
databaseReferencesNode: DatabaseReferencesTreeItem;
|
||||
sqlCmdVariablesNode: SqlCmdVariablesTreeItem;
|
||||
fileChildren: { [childName: string]: (fileTree.FolderNode | fileTree.FileNode) } = {};
|
||||
project: Project;
|
||||
fileSystemUri: vscode.Uri;
|
||||
@@ -34,7 +36,7 @@ export class ProjectRootTreeItem extends BaseProjectTreeItem {
|
||||
this.fileSystemUri = vscode.Uri.file(project.projectFilePath);
|
||||
this.dataSourceNode = new DataSourcesTreeItem(this);
|
||||
this.databaseReferencesNode = new DatabaseReferencesTreeItem(this);
|
||||
|
||||
this.sqlCmdVariablesNode = new SqlCmdVariablesTreeItem(this);
|
||||
this.construct();
|
||||
}
|
||||
|
||||
@@ -43,6 +45,7 @@ export class ProjectRootTreeItem extends BaseProjectTreeItem {
|
||||
// [8/31/2020] Hiding Data source for Preview since we do not have a way to add or update those.
|
||||
// output.push(this.dataSourceNode);
|
||||
output.push(this.databaseReferencesNode);
|
||||
output.push(this.sqlCmdVariablesNode);
|
||||
|
||||
return output.concat(Object.values(this.fileChildren).sort(fileTree.sortFileFolderNodes));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import * as constants from '../../common/constants';
|
||||
|
||||
import { BaseProjectTreeItem } from './baseTreeItem';
|
||||
import { ProjectRootTreeItem } from './projectTreeItem';
|
||||
import { IconPathHelper } from '../../common/iconHelper';
|
||||
|
||||
/**
|
||||
* Folder for containing SQLCMD variable nodes in the tree
|
||||
*/
|
||||
export class SqlCmdVariablesTreeItem extends BaseProjectTreeItem {
|
||||
private sqlcmdVariables: SqlCmdVariableTreeItem[] = [];
|
||||
|
||||
constructor(project: ProjectRootTreeItem) {
|
||||
super(vscode.Uri.file(path.join(project.projectUri.fsPath, constants.sqlcmdVariablesNodeName)), project);
|
||||
|
||||
this.construct();
|
||||
}
|
||||
|
||||
private construct() {
|
||||
const sqlCmdVariables = (this.parent as ProjectRootTreeItem).project.sqlCmdVariables;
|
||||
|
||||
if (!sqlCmdVariables) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const sqlCmdVariable of Object.keys(sqlCmdVariables)) {
|
||||
if (sqlCmdVariable) {
|
||||
this.sqlcmdVariables.push(new SqlCmdVariableTreeItem(sqlCmdVariable, this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public get children(): SqlCmdVariableTreeItem[] {
|
||||
return this.sqlcmdVariables;
|
||||
}
|
||||
|
||||
public get treeItem(): vscode.TreeItem {
|
||||
const sqlCmdVariableFolderItem = new vscode.TreeItem(this.projectUri, vscode.TreeItemCollapsibleState.Collapsed);
|
||||
sqlCmdVariableFolderItem.contextValue = constants.DatabaseProjectItemType.sqlcmdVariablesRoot;
|
||||
sqlCmdVariableFolderItem.iconPath = IconPathHelper.sqlCmdVariablesGroup;
|
||||
|
||||
return sqlCmdVariableFolderItem;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a SQLCMD variable in a .sqlproj
|
||||
*/
|
||||
export class SqlCmdVariableTreeItem extends BaseProjectTreeItem {
|
||||
constructor(private sqlcmdVar: string, sqlcmdVarsTreeItem: SqlCmdVariablesTreeItem) {
|
||||
super(vscode.Uri.file(path.join(sqlcmdVarsTreeItem.projectUri.fsPath, sqlcmdVar)), sqlcmdVarsTreeItem);
|
||||
}
|
||||
|
||||
public get children(): BaseProjectTreeItem[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
public get treeItem(): vscode.TreeItem {
|
||||
const sqlcmdVariableItem = new vscode.TreeItem(this.projectUri, vscode.TreeItemCollapsibleState.None);
|
||||
sqlcmdVariableItem.label = this.sqlcmdVar;
|
||||
sqlcmdVariableItem.contextValue = constants.DatabaseProjectItemType.sqlcmdVariable;
|
||||
sqlcmdVariableItem.iconPath = IconPathHelper.sqlCmdVariable;
|
||||
|
||||
return sqlcmdVariableItem;
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,7 @@ describe('Project Tree tests', function (): void {
|
||||
const tree = new ProjectRootTreeItem(proj);
|
||||
should(tree.children.map(x => x.projectUri.path)).deepEqual([
|
||||
'/TestProj/Database References',
|
||||
'/TestProj/SQLCMD Variables',
|
||||
'/TestProj/duplicateFolder',
|
||||
'/TestProj/someFolder',
|
||||
'/TestProj/duplicate.sql']);
|
||||
@@ -82,6 +83,7 @@ describe('Project Tree tests', function (): void {
|
||||
|
||||
should(tree.children.map(x => x.treeItem.contextValue)).deepEqual([
|
||||
DatabaseProjectItemType.referencesRoot,
|
||||
DatabaseProjectItemType.sqlcmdVariablesRoot,
|
||||
DatabaseProjectItemType.folder,
|
||||
DatabaseProjectItemType.folder,
|
||||
DatabaseProjectItemType.file]);
|
||||
@@ -106,12 +108,13 @@ describe('Project Tree tests', function (): void {
|
||||
const tree = new ProjectRootTreeItem(proj);
|
||||
should(tree.children.map(x => x.projectUri.path)).deepEqual([
|
||||
'/TestProj/Database References',
|
||||
'/TestProj/SQLCMD Variables',
|
||||
'/TestProj/someFolder1']);
|
||||
|
||||
should(tree.children.find(x => x.projectUri.path === '/TestProj/someFolder1')?.children.map(y => y.projectUri.path)).deepEqual([
|
||||
'/TestProj/someFolder1/MyNestedFolder1',
|
||||
'/TestProj/someFolder1/MyNestedFolder2',
|
||||
'/TestProj/someFolder1/MyFile2.sql']);
|
||||
'/TestProj/someFolder1/MyNestedFolder1',
|
||||
'/TestProj/someFolder1/MyNestedFolder2',
|
||||
'/TestProj/someFolder1/MyFile2.sql']);
|
||||
});
|
||||
|
||||
it('Should be able to parse and include relative paths outside project folder', function (): void {
|
||||
@@ -127,6 +130,7 @@ describe('Project Tree tests', function (): void {
|
||||
const tree = new ProjectRootTreeItem(proj);
|
||||
should(tree.children.map(x => x.projectUri.path)).deepEqual([
|
||||
'/TestProj/Database References',
|
||||
'/TestProj/SQLCMD Variables',
|
||||
'/TestProj/MyFile1.sql',
|
||||
'/TestProj/MyFile2.sql']);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user