Show database references in project tree (#10837)

* add database references to same itemgroup

* show database references in tree

* update tests

* refresh project tree after a reference is added

* addressing comments

* add validation

* Add test

* sort imports
This commit is contained in:
Kim Santiago
2020-06-11 15:32:57 -07:00
committed by GitHub
parent a099b9e72a
commit 7b00e219ef
8 changed files with 88 additions and 2 deletions

View File

@@ -22,6 +22,7 @@ export class Project {
public files: ProjectEntry[] = [];
public dataSources: DataSource[] = [];
public importedTargets: string[] = [];
public databaseReferences: string[] = [];
public sqlCmdVariables: Record<string, string> = {};
public get projectFolderPath() {
@@ -60,6 +61,16 @@ export class Project {
const importTarget = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.Import)[i];
this.importedTargets.push(importTarget.getAttribute(constants.Project));
}
// find all database references to include
for (let r = 0; r < this.projFileXmlDoc.documentElement.getElementsByTagName(constants.ArtifactReference).length; r++) {
const filepath = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.ArtifactReference)[r].getAttribute(constants.Include);
if (!filepath) {
throw new Error(constants.invalidDatabaseReference);
}
this.databaseReferences.push(path.parse(filepath).name);
}
}
public async updateProjectForRoundTrip() {
@@ -259,7 +270,8 @@ export class Project {
referenceNode.appendChild(databaseVariableLiteralValue);
}
this.findOrCreateItemGroup().appendChild(referenceNode);
this.findOrCreateItemGroup(constants.ArtifactReference).appendChild(referenceNode);
this.databaseReferences.push(path.parse(entry.fsUri.fsPath.toString()).name);
}
private async updateImportedTargetsToProjFile(condition: string, projectAttributeVal: string, oldImportNode?: any): Promise<any> {

View File

@@ -0,0 +1,37 @@
/*---------------------------------------------------------------------------------------------
* 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, MessageTreeItem } from './baseTreeItem';
import { ProjectRootTreeItem } from './projectTreeItem';
/**
* Folder for containing references nodes in the tree
*/
export class DatabaseReferencesTreeItem extends BaseProjectTreeItem {
private references: MessageTreeItem[] = [];
constructor(project: ProjectRootTreeItem) {
super(vscode.Uri.file(path.join(project.uri.path, constants.databaseReferencesNodeName)), project);
this.construct();
}
private construct() {
for (const reference of (this.parent as ProjectRootTreeItem).project.databaseReferences) {
this.references.push(new MessageTreeItem(reference));
}
}
public get children(): BaseProjectTreeItem[] {
return this.references;
}
public get treeItem(): vscode.TreeItem {
return new vscode.TreeItem(this.uri, vscode.TreeItemCollapsibleState.Collapsed);
}
}

View File

@@ -10,12 +10,14 @@ import { BaseProjectTreeItem } from './baseTreeItem';
import * as fileTree from './fileFolderTreeItem';
import { Project, ProjectEntry, EntryType } from '../project';
import * as utils from '../../common/utils';
import { DatabaseReferencesTreeItem } from './databaseReferencesTreeItem';
/**
* TreeNode root that represents an entire project
*/
export class ProjectRootTreeItem extends BaseProjectTreeItem {
dataSourceNode: DataSourcesTreeItem;
databaseReferencesNode: DatabaseReferencesTreeItem;
fileChildren: { [childName: string]: (fileTree.FolderNode | fileTree.FileNode) } = {};
project: Project;
@@ -24,6 +26,7 @@ export class ProjectRootTreeItem extends BaseProjectTreeItem {
this.project = project;
this.dataSourceNode = new DataSourcesTreeItem(this);
this.databaseReferencesNode = new DatabaseReferencesTreeItem(this);
this.construct();
}
@@ -31,6 +34,7 @@ export class ProjectRootTreeItem extends BaseProjectTreeItem {
public get children(): BaseProjectTreeItem[] {
const output: BaseProjectTreeItem[] = [];
output.push(this.dataSourceNode);
output.push(this.databaseReferencesNode);
return output.concat(Object.values(this.fileChildren).sort(fileTree.sortFileFolderNodes));
}