mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-20 17:22:51 -05:00
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:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user