mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-20 17:22:51 -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:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user