mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
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:
@@ -14,9 +14,8 @@ export abstract class BaseProjectTreeItem {
|
|||||||
* Constructor
|
* Constructor
|
||||||
* @param relativeProjectUri Project-relative URI that's compatible with the project tree
|
* @param relativeProjectUri Project-relative URI that's compatible with the project tree
|
||||||
* @param projectFileUri Full URI to the .sqlproj of this project
|
* @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[];
|
abstract get children(): BaseProjectTreeItem[];
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import * as path from 'path';
|
|||||||
import * as constants from '../../common/constants';
|
import * as constants from '../../common/constants';
|
||||||
|
|
||||||
import { BaseProjectTreeItem } from './baseTreeItem';
|
import { BaseProjectTreeItem } from './baseTreeItem';
|
||||||
import { ProjectRootTreeItem } from './projectTreeItem';
|
|
||||||
import { IconPathHelper } from '../../common/iconHelper';
|
import { IconPathHelper } from '../../common/iconHelper';
|
||||||
import { IDatabaseReferenceProjectEntry } from 'sqldbproj';
|
import { IDatabaseReferenceProjectEntry } from 'sqldbproj';
|
||||||
|
|
||||||
@@ -25,8 +24,8 @@ export class DatabaseReferencesTreeItem extends BaseProjectTreeItem {
|
|||||||
* @param databaseReferences Array of database references in the project
|
* @param databaseReferences Array of database references in the project
|
||||||
* @param project
|
* @param project
|
||||||
*/
|
*/
|
||||||
constructor(projectNodeName: string, sqlprojUri: vscode.Uri, databaseReferences: IDatabaseReferenceProjectEntry[], project: ProjectRootTreeItem) {
|
constructor(projectNodeName: string, sqlprojUri: vscode.Uri, databaseReferences: IDatabaseReferenceProjectEntry[]) {
|
||||||
super(vscode.Uri.file(path.join(projectNodeName, constants.databaseReferencesNodeName)), sqlprojUri, project);
|
super(vscode.Uri.file(path.join(projectNodeName, constants.databaseReferencesNodeName)), sqlprojUri);
|
||||||
|
|
||||||
this.construct(databaseReferences);
|
this.construct(databaseReferences);
|
||||||
}
|
}
|
||||||
@@ -37,7 +36,7 @@ export class DatabaseReferencesTreeItem extends BaseProjectTreeItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const reference of databaseReferences) {
|
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 {
|
export class DatabaseReferenceTreeItem extends BaseProjectTreeItem {
|
||||||
constructor(private reference: IDatabaseReferenceProjectEntry, referencesNodeRelativeProjectUri: vscode.Uri, sqlprojUri: vscode.Uri, referencesTreeItem: DatabaseReferencesTreeItem) {
|
constructor(private reference: IDatabaseReferenceProjectEntry, referencesNodeRelativeProjectUri: vscode.Uri, sqlprojUri: vscode.Uri) {
|
||||||
super(vscode.Uri.file(path.join(referencesNodeRelativeProjectUri.fsPath, reference.databaseName)), sqlprojUri, referencesTreeItem);
|
super(vscode.Uri.file(path.join(referencesNodeRelativeProjectUri.fsPath, reference.databaseName)), sqlprojUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get children(): BaseProjectTreeItem[] {
|
public get children(): BaseProjectTreeItem[] {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import * as vscode from 'vscode';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as utils from '../../common/utils';
|
import * as utils from '../../common/utils';
|
||||||
import { BaseProjectTreeItem } from './baseTreeItem';
|
import { BaseProjectTreeItem } from './baseTreeItem';
|
||||||
import { ProjectRootTreeItem } from './projectTreeItem';
|
|
||||||
import { DatabaseProjectItemType, sqlprojExtension } from '../../common/constants';
|
import { DatabaseProjectItemType, sqlprojExtension } from '../../common/constants';
|
||||||
import { IconPathHelper } from '../../common/iconHelper';
|
import { IconPathHelper } from '../../common/iconHelper';
|
||||||
|
|
||||||
@@ -18,8 +17,8 @@ export class FolderNode extends BaseProjectTreeItem {
|
|||||||
public fileChildren: { [childName: string]: (FolderNode | FileNode) } = {};
|
public fileChildren: { [childName: string]: (FolderNode | FileNode) } = {};
|
||||||
public fileSystemUri: vscode.Uri;
|
public fileSystemUri: vscode.Uri;
|
||||||
|
|
||||||
constructor(folderPath: vscode.Uri, sqlprojUri: vscode.Uri, parent: FolderNode | ProjectRootTreeItem) {
|
constructor(folderPath: vscode.Uri, sqlprojUri: vscode.Uri) {
|
||||||
super(fsPathToProjectUri(folderPath, sqlprojUri), sqlprojUri, parent);
|
super(fsPathToProjectUri(folderPath, sqlprojUri), sqlprojUri);
|
||||||
this.fileSystemUri = folderPath;
|
this.fileSystemUri = folderPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,8 +41,8 @@ export class FolderNode extends BaseProjectTreeItem {
|
|||||||
export class FileNode extends BaseProjectTreeItem {
|
export class FileNode extends BaseProjectTreeItem {
|
||||||
public fileSystemUri: vscode.Uri;
|
public fileSystemUri: vscode.Uri;
|
||||||
|
|
||||||
constructor(filePath: vscode.Uri, sqlprojUri: vscode.Uri, parent: FolderNode | ProjectRootTreeItem) {
|
constructor(filePath: vscode.Uri, sqlprojUri: vscode.Uri) {
|
||||||
super(fsPathToProjectUri(filePath, sqlprojUri, true), sqlprojUri, parent);
|
super(fsPathToProjectUri(filePath, sqlprojUri, true), sqlprojUri);
|
||||||
this.fileSystemUri = filePath;
|
this.fileSystemUri = filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ export class ProjectRootTreeItem extends BaseProjectTreeItem {
|
|||||||
projectNodeName: string;
|
projectNodeName: string;
|
||||||
|
|
||||||
constructor(project: Project) {
|
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.project = project;
|
||||||
this.fileSystemUri = vscode.Uri.file(project.projectFilePath);
|
this.fileSystemUri = vscode.Uri.file(project.projectFilePath);
|
||||||
this.projectNodeName = path.basename(project.projectFilePath, sqlprojExtension);
|
this.projectNodeName = path.basename(project.projectFilePath, sqlprojExtension);
|
||||||
|
|
||||||
this.databaseReferencesNode = new DatabaseReferencesTreeItem(this.projectNodeName, this.projectFileUri, project.databaseReferences, this);
|
this.databaseReferencesNode = new DatabaseReferencesTreeItem(this.projectNodeName, this.projectFileUri, project.databaseReferences);
|
||||||
this.sqlCmdVariablesNode = new SqlCmdVariablesTreeItem(this.projectNodeName, this.projectFileUri, project.sqlCmdVariables, this);
|
this.sqlCmdVariablesNode = new SqlCmdVariablesTreeItem(this.projectNodeName, this.projectFileUri, project.sqlCmdVariables);
|
||||||
this.construct();
|
this.construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,17 +83,17 @@ export class ProjectRootTreeItem extends BaseProjectTreeItem {
|
|||||||
switch (entry.type) {
|
switch (entry.type) {
|
||||||
case EntryType.File:
|
case EntryType.File:
|
||||||
if (entry.sqlObjectType === ExternalStreamingJob) {
|
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) {
|
} else if (entry.containsCreateTableStatement) {
|
||||||
newNode = new fileTree.TableFileNode(entry.fsUri, this.projectFileUri, parentNode);
|
newNode = new fileTree.TableFileNode(entry.fsUri, this.projectFileUri);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
newNode = new fileTree.FileNode(entry.fsUri, this.projectFileUri, parentNode);
|
newNode = new fileTree.FileNode(entry.fsUri, this.projectFileUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EntryType.Folder:
|
case EntryType.Folder:
|
||||||
newNode = new fileTree.FolderNode(entry.fsUri, this.projectFileUri, parentNode);
|
newNode = new fileTree.FolderNode(entry.fsUri, this.projectFileUri);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown EntryType: '${entry.type}'`);
|
throw new Error(`Unknown EntryType: '${entry.type}'`);
|
||||||
@@ -122,7 +122,7 @@ export class ProjectRootTreeItem extends BaseProjectTreeItem {
|
|||||||
for (const part of relativePathParts) {
|
for (const part of relativePathParts) {
|
||||||
if (current.fileChildren[part] === undefined) {
|
if (current.fileChildren[part] === undefined) {
|
||||||
const parentPath = current instanceof ProjectRootTreeItem ? path.dirname(current.fileSystemUri.fsPath) : current.fileSystemUri.fsPath;
|
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) {
|
if (current.fileChildren[part] instanceof fileTree.FileNode) {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import * as path from 'path';
|
|||||||
import * as constants from '../../common/constants';
|
import * as constants from '../../common/constants';
|
||||||
|
|
||||||
import { BaseProjectTreeItem } from './baseTreeItem';
|
import { BaseProjectTreeItem } from './baseTreeItem';
|
||||||
import { ProjectRootTreeItem } from './projectTreeItem';
|
|
||||||
import { IconPathHelper } from '../../common/iconHelper';
|
import { IconPathHelper } from '../../common/iconHelper';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,8 +23,8 @@ export class SqlCmdVariablesTreeItem extends BaseProjectTreeItem {
|
|||||||
* @param sqlCmdVariables Collection of SQLCMD variables in the project
|
* @param sqlCmdVariables Collection of SQLCMD variables in the project
|
||||||
* @param project
|
* @param project
|
||||||
*/
|
*/
|
||||||
constructor(projectNodeName: string, sqlprojUri: vscode.Uri, sqlCmdVariables: Record<string, string>, project: ProjectRootTreeItem) {
|
constructor(projectNodeName: string, sqlprojUri: vscode.Uri, sqlCmdVariables: Record<string, string>) {
|
||||||
super(vscode.Uri.file(path.join(projectNodeName, constants.sqlcmdVariablesNodeName)), sqlprojUri, project);
|
super(vscode.Uri.file(path.join(projectNodeName, constants.sqlcmdVariablesNodeName)), sqlprojUri);
|
||||||
|
|
||||||
this.construct(sqlCmdVariables);
|
this.construct(sqlCmdVariables);
|
||||||
}
|
}
|
||||||
@@ -37,7 +36,7 @@ export class SqlCmdVariablesTreeItem extends BaseProjectTreeItem {
|
|||||||
|
|
||||||
for (const sqlCmdVariable of Object.keys(sqlCmdVariables)) {
|
for (const sqlCmdVariable of Object.keys(sqlCmdVariables)) {
|
||||||
if (sqlCmdVariable) {
|
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
|
* Represents a SQLCMD variable in a .sqlproj
|
||||||
*/
|
*/
|
||||||
export class SqlCmdVariableTreeItem extends BaseProjectTreeItem {
|
export class SqlCmdVariableTreeItem extends BaseProjectTreeItem {
|
||||||
constructor(private sqlcmdVar: string, sqlprojUri: vscode.Uri, sqlCmdNodeRelativeProjectUri: vscode.Uri, sqlcmdVarsTreeItem: SqlCmdVariablesTreeItem) {
|
constructor(private sqlcmdVar: string, sqlprojUri: vscode.Uri, sqlCmdNodeRelativeProjectUri: vscode.Uri) {
|
||||||
super(vscode.Uri.file(path.join(sqlCmdNodeRelativeProjectUri.fsPath, sqlcmdVar)), sqlprojUri, sqlcmdVarsTreeItem);
|
super(vscode.Uri.file(path.join(sqlCmdNodeRelativeProjectUri.fsPath, sqlcmdVar)), sqlprojUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get children(): BaseProjectTreeItem[] {
|
public get children(): BaseProjectTreeItem[] {
|
||||||
|
|||||||
@@ -19,30 +19,29 @@ describe('Project Tree tests', function (): void {
|
|||||||
const root = os.platform() === 'win32' ? 'Z:\\' : '/';
|
const root = os.platform() === 'win32' ? 'Z:\\' : '/';
|
||||||
|
|
||||||
const sqlprojUri = vscode.Uri.file(`${root}Fake.sqlproj`);
|
const sqlprojUri = vscode.Uri.file(`${root}Fake.sqlproj`);
|
||||||
const parent = new ProjectRootTreeItem(new Project(sqlprojUri.fsPath));
|
|
||||||
|
|
||||||
let inputNodes: (FileNode | FolderNode)[] = [
|
let inputNodes: (FileNode | FolderNode)[] = [
|
||||||
new FileNode(vscode.Uri.file(`${root}C`), sqlprojUri, parent),
|
new FileNode(vscode.Uri.file(`${root}C`), sqlprojUri),
|
||||||
new FileNode(vscode.Uri.file(`${root}D`), sqlprojUri, parent),
|
new FileNode(vscode.Uri.file(`${root}D`), sqlprojUri),
|
||||||
new FolderNode(vscode.Uri.file(`${root}Z`), sqlprojUri, parent),
|
new FolderNode(vscode.Uri.file(`${root}Z`), sqlprojUri),
|
||||||
new FolderNode(vscode.Uri.file(`${root}X`), sqlprojUri, parent),
|
new FolderNode(vscode.Uri.file(`${root}X`), sqlprojUri),
|
||||||
new FileNode(vscode.Uri.file(`${root}B`), sqlprojUri, parent),
|
new FileNode(vscode.Uri.file(`${root}B`), sqlprojUri),
|
||||||
new FileNode(vscode.Uri.file(`${root}A`), sqlprojUri, parent),
|
new FileNode(vscode.Uri.file(`${root}A`), sqlprojUri),
|
||||||
new FolderNode(vscode.Uri.file(`${root}W`), sqlprojUri, parent),
|
new FolderNode(vscode.Uri.file(`${root}W`), sqlprojUri),
|
||||||
new FolderNode(vscode.Uri.file(`${root}Y`), sqlprojUri, parent)
|
new FolderNode(vscode.Uri.file(`${root}Y`), sqlprojUri)
|
||||||
];
|
];
|
||||||
|
|
||||||
inputNodes = inputNodes.sort(sortFileFolderNodes);
|
inputNodes = inputNodes.sort(sortFileFolderNodes);
|
||||||
|
|
||||||
const expectedNodes: (FileNode | FolderNode)[] = [
|
const expectedNodes: (FileNode | FolderNode)[] = [
|
||||||
new FolderNode(vscode.Uri.file(`${root}W`), sqlprojUri, parent),
|
new FolderNode(vscode.Uri.file(`${root}W`), sqlprojUri),
|
||||||
new FolderNode(vscode.Uri.file(`${root}X`), sqlprojUri, parent),
|
new FolderNode(vscode.Uri.file(`${root}X`), sqlprojUri),
|
||||||
new FolderNode(vscode.Uri.file(`${root}Y`), sqlprojUri, parent),
|
new FolderNode(vscode.Uri.file(`${root}Y`), sqlprojUri),
|
||||||
new FolderNode(vscode.Uri.file(`${root}Z`), sqlprojUri, parent),
|
new FolderNode(vscode.Uri.file(`${root}Z`), sqlprojUri),
|
||||||
new FileNode(vscode.Uri.file(`${root}A`), sqlprojUri, parent),
|
new FileNode(vscode.Uri.file(`${root}A`), sqlprojUri),
|
||||||
new FileNode(vscode.Uri.file(`${root}B`), sqlprojUri, parent),
|
new FileNode(vscode.Uri.file(`${root}B`), sqlprojUri),
|
||||||
new FileNode(vscode.Uri.file(`${root}C`), sqlprojUri, parent),
|
new FileNode(vscode.Uri.file(`${root}C`), sqlprojUri),
|
||||||
new FileNode(vscode.Uri.file(`${root}D`), sqlprojUri, parent)
|
new FileNode(vscode.Uri.file(`${root}D`), sqlprojUri)
|
||||||
];
|
];
|
||||||
|
|
||||||
should(inputNodes.map(n => n.relativeProjectUri.path)).deepEqual(expectedNodes.map(n => n.relativeProjectUri.path));
|
should(inputNodes.map(n => n.relativeProjectUri.path)).deepEqual(expectedNodes.map(n => n.relativeProjectUri.path));
|
||||||
|
|||||||
Reference in New Issue
Block a user