Remove parent from sql project tree items (#21912)

* update getFileProjectEntry and getRelativePath

* remove root and fix tests

* remove parent from sql project tree items
This commit is contained in:
Kim Santiago
2023-02-14 14:53:39 -08:00
committed by GitHub
parent fe25674401
commit 4f6fe5955d
6 changed files with 39 additions and 44 deletions

View File

@@ -14,9 +14,8 @@ export abstract class BaseProjectTreeItem {
* Constructor
* @param relativeProjectUri Project-relative URI that's compatible with the project tree
* @param projectFileUri Full URI to the .sqlproj of this project
* @param parent parent tree item
*/
constructor(public relativeProjectUri: vscode.Uri, public projectFileUri: vscode.Uri, public parent?: BaseProjectTreeItem) { }
constructor(public relativeProjectUri: vscode.Uri, public projectFileUri: vscode.Uri) { }
abstract get children(): BaseProjectTreeItem[];

View File

@@ -8,7 +8,6 @@ import * as path from 'path';
import * as constants from '../../common/constants';
import { BaseProjectTreeItem } from './baseTreeItem';
import { ProjectRootTreeItem } from './projectTreeItem';
import { IconPathHelper } from '../../common/iconHelper';
import { IDatabaseReferenceProjectEntry } from 'sqldbproj';
@@ -25,8 +24,8 @@ export class DatabaseReferencesTreeItem extends BaseProjectTreeItem {
* @param databaseReferences Array of database references in the project
* @param project
*/
constructor(projectNodeName: string, sqlprojUri: vscode.Uri, databaseReferences: IDatabaseReferenceProjectEntry[], project: ProjectRootTreeItem) {
super(vscode.Uri.file(path.join(projectNodeName, constants.databaseReferencesNodeName)), sqlprojUri, project);
constructor(projectNodeName: string, sqlprojUri: vscode.Uri, databaseReferences: IDatabaseReferenceProjectEntry[]) {
super(vscode.Uri.file(path.join(projectNodeName, constants.databaseReferencesNodeName)), sqlprojUri);
this.construct(databaseReferences);
}
@@ -37,7 +36,7 @@ export class DatabaseReferencesTreeItem extends BaseProjectTreeItem {
}
for (const reference of databaseReferences) {
this.references.push(new DatabaseReferenceTreeItem(reference, this.relativeProjectUri, this.projectFileUri, this));
this.references.push(new DatabaseReferenceTreeItem(reference, this.relativeProjectUri, this.projectFileUri));
}
}
@@ -55,8 +54,8 @@ export class DatabaseReferencesTreeItem extends BaseProjectTreeItem {
}
export class DatabaseReferenceTreeItem extends BaseProjectTreeItem {
constructor(private reference: IDatabaseReferenceProjectEntry, referencesNodeRelativeProjectUri: vscode.Uri, sqlprojUri: vscode.Uri, referencesTreeItem: DatabaseReferencesTreeItem) {
super(vscode.Uri.file(path.join(referencesNodeRelativeProjectUri.fsPath, reference.databaseName)), sqlprojUri, referencesTreeItem);
constructor(private reference: IDatabaseReferenceProjectEntry, referencesNodeRelativeProjectUri: vscode.Uri, sqlprojUri: vscode.Uri) {
super(vscode.Uri.file(path.join(referencesNodeRelativeProjectUri.fsPath, reference.databaseName)), sqlprojUri);
}
public get children(): BaseProjectTreeItem[] {

View File

@@ -7,7 +7,6 @@ import * as vscode from 'vscode';
import * as path from 'path';
import * as utils from '../../common/utils';
import { BaseProjectTreeItem } from './baseTreeItem';
import { ProjectRootTreeItem } from './projectTreeItem';
import { DatabaseProjectItemType, sqlprojExtension } from '../../common/constants';
import { IconPathHelper } from '../../common/iconHelper';
@@ -18,8 +17,8 @@ export class FolderNode extends BaseProjectTreeItem {
public fileChildren: { [childName: string]: (FolderNode | FileNode) } = {};
public fileSystemUri: vscode.Uri;
constructor(folderPath: vscode.Uri, sqlprojUri: vscode.Uri, parent: FolderNode | ProjectRootTreeItem) {
super(fsPathToProjectUri(folderPath, sqlprojUri), sqlprojUri, parent);
constructor(folderPath: vscode.Uri, sqlprojUri: vscode.Uri) {
super(fsPathToProjectUri(folderPath, sqlprojUri), sqlprojUri);
this.fileSystemUri = folderPath;
}
@@ -42,8 +41,8 @@ export class FolderNode extends BaseProjectTreeItem {
export class FileNode extends BaseProjectTreeItem {
public fileSystemUri: vscode.Uri;
constructor(filePath: vscode.Uri, sqlprojUri: vscode.Uri, parent: FolderNode | ProjectRootTreeItem) {
super(fsPathToProjectUri(filePath, sqlprojUri, true), sqlprojUri, parent);
constructor(filePath: vscode.Uri, sqlprojUri: vscode.Uri) {
super(fsPathToProjectUri(filePath, sqlprojUri, true), sqlprojUri);
this.fileSystemUri = filePath;
}

View File

@@ -29,14 +29,14 @@ export class ProjectRootTreeItem extends BaseProjectTreeItem {
projectNodeName: string;
constructor(project: Project) {
super(vscode.Uri.parse(path.basename(project.projectFilePath, sqlprojExtension)), vscode.Uri.file(project.projectFilePath), undefined);
super(vscode.Uri.parse(path.basename(project.projectFilePath, sqlprojExtension)), vscode.Uri.file(project.projectFilePath));
this.project = project;
this.fileSystemUri = vscode.Uri.file(project.projectFilePath);
this.projectNodeName = path.basename(project.projectFilePath, sqlprojExtension);
this.databaseReferencesNode = new DatabaseReferencesTreeItem(this.projectNodeName, this.projectFileUri, project.databaseReferences, this);
this.sqlCmdVariablesNode = new SqlCmdVariablesTreeItem(this.projectNodeName, this.projectFileUri, project.sqlCmdVariables, this);
this.databaseReferencesNode = new DatabaseReferencesTreeItem(this.projectNodeName, this.projectFileUri, project.databaseReferences);
this.sqlCmdVariablesNode = new SqlCmdVariablesTreeItem(this.projectNodeName, this.projectFileUri, project.sqlCmdVariables);
this.construct();
}
@@ -83,17 +83,17 @@ export class ProjectRootTreeItem extends BaseProjectTreeItem {
switch (entry.type) {
case EntryType.File:
if (entry.sqlObjectType === ExternalStreamingJob) {
newNode = new fileTree.ExternalStreamingJobFileNode(entry.fsUri, this.projectFileUri, parentNode);
newNode = new fileTree.ExternalStreamingJobFileNode(entry.fsUri, this.projectFileUri);
} else if (entry.containsCreateTableStatement) {
newNode = new fileTree.TableFileNode(entry.fsUri, this.projectFileUri, parentNode);
newNode = new fileTree.TableFileNode(entry.fsUri, this.projectFileUri);
}
else {
newNode = new fileTree.FileNode(entry.fsUri, this.projectFileUri, parentNode);
newNode = new fileTree.FileNode(entry.fsUri, this.projectFileUri);
}
break;
case EntryType.Folder:
newNode = new fileTree.FolderNode(entry.fsUri, this.projectFileUri, parentNode);
newNode = new fileTree.FolderNode(entry.fsUri, this.projectFileUri);
break;
default:
throw new Error(`Unknown EntryType: '${entry.type}'`);
@@ -122,7 +122,7 @@ export class ProjectRootTreeItem extends BaseProjectTreeItem {
for (const part of relativePathParts) {
if (current.fileChildren[part] === undefined) {
const parentPath = current instanceof ProjectRootTreeItem ? path.dirname(current.fileSystemUri.fsPath) : current.fileSystemUri.fsPath;
current.fileChildren[part] = new fileTree.FolderNode(vscode.Uri.file(path.join(parentPath, part)), this.projectFileUri, current);
current.fileChildren[part] = new fileTree.FolderNode(vscode.Uri.file(path.join(parentPath, part)), this.projectFileUri);
}
if (current.fileChildren[part] instanceof fileTree.FileNode) {

View File

@@ -8,7 +8,6 @@ import * as path from 'path';
import * as constants from '../../common/constants';
import { BaseProjectTreeItem } from './baseTreeItem';
import { ProjectRootTreeItem } from './projectTreeItem';
import { IconPathHelper } from '../../common/iconHelper';
/**
@@ -24,8 +23,8 @@ export class SqlCmdVariablesTreeItem extends BaseProjectTreeItem {
* @param sqlCmdVariables Collection of SQLCMD variables in the project
* @param project
*/
constructor(projectNodeName: string, sqlprojUri: vscode.Uri, sqlCmdVariables: Record<string, string>, project: ProjectRootTreeItem) {
super(vscode.Uri.file(path.join(projectNodeName, constants.sqlcmdVariablesNodeName)), sqlprojUri, project);
constructor(projectNodeName: string, sqlprojUri: vscode.Uri, sqlCmdVariables: Record<string, string>) {
super(vscode.Uri.file(path.join(projectNodeName, constants.sqlcmdVariablesNodeName)), sqlprojUri);
this.construct(sqlCmdVariables);
}
@@ -37,7 +36,7 @@ export class SqlCmdVariablesTreeItem extends BaseProjectTreeItem {
for (const sqlCmdVariable of Object.keys(sqlCmdVariables)) {
if (sqlCmdVariable) {
this.sqlcmdVariableTreeItems.push(new SqlCmdVariableTreeItem(sqlCmdVariable, this.relativeProjectUri, this.projectFileUri, this));
this.sqlcmdVariableTreeItems.push(new SqlCmdVariableTreeItem(sqlCmdVariable, this.relativeProjectUri, this.projectFileUri));
}
}
}
@@ -59,8 +58,8 @@ export class SqlCmdVariablesTreeItem extends BaseProjectTreeItem {
* Represents a SQLCMD variable in a .sqlproj
*/
export class SqlCmdVariableTreeItem extends BaseProjectTreeItem {
constructor(private sqlcmdVar: string, sqlprojUri: vscode.Uri, sqlCmdNodeRelativeProjectUri: vscode.Uri, sqlcmdVarsTreeItem: SqlCmdVariablesTreeItem) {
super(vscode.Uri.file(path.join(sqlCmdNodeRelativeProjectUri.fsPath, sqlcmdVar)), sqlprojUri, sqlcmdVarsTreeItem);
constructor(private sqlcmdVar: string, sqlprojUri: vscode.Uri, sqlCmdNodeRelativeProjectUri: vscode.Uri) {
super(vscode.Uri.file(path.join(sqlCmdNodeRelativeProjectUri.fsPath, sqlcmdVar)), sqlprojUri);
}
public get children(): BaseProjectTreeItem[] {

View File

@@ -19,30 +19,29 @@ describe('Project Tree tests', function (): void {
const root = os.platform() === 'win32' ? 'Z:\\' : '/';
const sqlprojUri = vscode.Uri.file(`${root}Fake.sqlproj`);
const parent = new ProjectRootTreeItem(new Project(sqlprojUri.fsPath));
let inputNodes: (FileNode | FolderNode)[] = [
new FileNode(vscode.Uri.file(`${root}C`), sqlprojUri, parent),
new FileNode(vscode.Uri.file(`${root}D`), sqlprojUri, parent),
new FolderNode(vscode.Uri.file(`${root}Z`), sqlprojUri, parent),
new FolderNode(vscode.Uri.file(`${root}X`), sqlprojUri, parent),
new FileNode(vscode.Uri.file(`${root}B`), sqlprojUri, parent),
new FileNode(vscode.Uri.file(`${root}A`), sqlprojUri, parent),
new FolderNode(vscode.Uri.file(`${root}W`), sqlprojUri, parent),
new FolderNode(vscode.Uri.file(`${root}Y`), sqlprojUri, parent)
new FileNode(vscode.Uri.file(`${root}C`), sqlprojUri),
new FileNode(vscode.Uri.file(`${root}D`), sqlprojUri),
new FolderNode(vscode.Uri.file(`${root}Z`), sqlprojUri),
new FolderNode(vscode.Uri.file(`${root}X`), sqlprojUri),
new FileNode(vscode.Uri.file(`${root}B`), sqlprojUri),
new FileNode(vscode.Uri.file(`${root}A`), sqlprojUri),
new FolderNode(vscode.Uri.file(`${root}W`), sqlprojUri),
new FolderNode(vscode.Uri.file(`${root}Y`), sqlprojUri)
];
inputNodes = inputNodes.sort(sortFileFolderNodes);
const expectedNodes: (FileNode | FolderNode)[] = [
new FolderNode(vscode.Uri.file(`${root}W`), sqlprojUri, parent),
new FolderNode(vscode.Uri.file(`${root}X`), sqlprojUri, parent),
new FolderNode(vscode.Uri.file(`${root}Y`), sqlprojUri, parent),
new FolderNode(vscode.Uri.file(`${root}Z`), sqlprojUri, parent),
new FileNode(vscode.Uri.file(`${root}A`), sqlprojUri, parent),
new FileNode(vscode.Uri.file(`${root}B`), sqlprojUri, parent),
new FileNode(vscode.Uri.file(`${root}C`), sqlprojUri, parent),
new FileNode(vscode.Uri.file(`${root}D`), sqlprojUri, parent)
new FolderNode(vscode.Uri.file(`${root}W`), sqlprojUri),
new FolderNode(vscode.Uri.file(`${root}X`), sqlprojUri),
new FolderNode(vscode.Uri.file(`${root}Y`), sqlprojUri),
new FolderNode(vscode.Uri.file(`${root}Z`), sqlprojUri),
new FileNode(vscode.Uri.file(`${root}A`), sqlprojUri),
new FileNode(vscode.Uri.file(`${root}B`), sqlprojUri),
new FileNode(vscode.Uri.file(`${root}C`), sqlprojUri),
new FileNode(vscode.Uri.file(`${root}D`), sqlprojUri)
];
should(inputNodes.map(n => n.relativeProjectUri.path)).deepEqual(expectedNodes.map(n => n.relativeProjectUri.path));