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));