Fix for Sqlproj tree bug (#10605)

Fixes bug where files located in a subfolder defined before the folders themselves in .sqlproj would result in those files not appearing in the ADS treeview
This commit is contained in:
Benjin Dubishar
2020-06-01 22:41:00 -07:00
committed by GitHub
parent 8fc8a79e26
commit 0ac6a07c5f
4 changed files with 106 additions and 12 deletions

View File

@@ -22,7 +22,7 @@ export class FolderNode extends BaseProjectTreeItem {
}
public get children(): BaseProjectTreeItem[] {
return Object.values(this.fileChildren).sort();
return Object.values(this.fileChildren).sort(sortFileFolderNodes);
}
public get treeItem(): vscode.TreeItem {
@@ -64,6 +64,23 @@ export class FileNode extends BaseProjectTreeItem {
}
}
/**
* Compares two folder/file tree nodes so that folders come before files, then alphabetically
* @param a a folder or file tree node
* @param b another folder or file tree node
*/
export function sortFileFolderNodes(a: (FolderNode | FileNode), b: (FolderNode | FileNode)): number {
if (a instanceof FolderNode && !(b instanceof FolderNode)) {
return -1;
}
else if (!(a instanceof FolderNode) && b instanceof FolderNode) {
return 1;
}
else {
return a.uri.fsPath.localeCompare(b.uri.fsPath);
}
}
/**
* Converts a full filesystem URI to a project-relative URI that's compatible with the project tree
*/
@@ -75,8 +92,7 @@ function fsPathToProjectUri(fileSystemUri: vscode.Uri, projectNode: ProjectRootT
localUri = fileSystemUri.fsPath.substring(projBaseDir.length);
}
else {
vscode.window.showErrorMessage('Project pointing to file outside of directory');
throw new Error('Project pointing to file outside of directory');
throw new Error(`Project (${projBaseDir}) pointing to file outside of directory (${fileSystemUri.fsPath})`);
}
return vscode.Uri.file(path.join(projectNode.uri.path, localUri));

View File

@@ -32,14 +32,7 @@ export class ProjectRootTreeItem extends BaseProjectTreeItem {
const output: BaseProjectTreeItem[] = [];
output.push(this.dataSourceNode);
// sort children so that folders come first, then alphabetical
const sortedChildren = Object.values(this.fileChildren).sort((a: (fileTree.FolderNode | fileTree.FileNode), b: (fileTree.FolderNode | fileTree.FileNode)) => {
if (a instanceof fileTree.FolderNode && !(b instanceof fileTree.FolderNode)) { return -1; }
else if (!(a instanceof fileTree.FolderNode) && b instanceof fileTree.FolderNode) { return 1; }
else { return a.uri.fsPath.localeCompare(b.uri.fsPath); }
});
return output.concat(sortedChildren);
return output.concat(Object.values(this.fileChildren).sort(fileTree.sortFileFolderNodes));
}
public get treeItem(): vscode.TreeItem {
@@ -53,6 +46,10 @@ export class ProjectRootTreeItem extends BaseProjectTreeItem {
for (const entry of this.project.files) {
const parentNode = this.getEntryParentNode(entry);
if (Object.keys(parentNode.fileChildren).includes(path.basename(entry.fsUri.path))) {
continue; // ignore duplicate entries
}
let newNode: fileTree.FolderNode | fileTree.FileNode;
switch (entry.type) {