mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 01:25:37 -05:00
Feature/outer paths for project (#11445)
* allow relative paths in project file outside of project folder * Adding some tests * Adding error string to loc strings * Fixed test * fix error message * PR comments and some more fixes
This commit is contained in:
@@ -9,6 +9,7 @@ import { BaseProjectTreeItem } from './baseTreeItem';
|
||||
import { ProjectRootTreeItem } from './projectTreeItem';
|
||||
import { Project } from '../project';
|
||||
import { DatabaseProjectItemType } from '../../common/constants';
|
||||
import * as utils from '../../common/utils';
|
||||
|
||||
/**
|
||||
* Node representing a folder in a project
|
||||
@@ -44,7 +45,7 @@ export class FileNode extends BaseProjectTreeItem {
|
||||
public fileSystemUri: vscode.Uri;
|
||||
|
||||
constructor(filePath: vscode.Uri, parent: FolderNode | ProjectRootTreeItem) {
|
||||
super(fsPathToProjectUri(filePath, parent.root as ProjectRootTreeItem), parent);
|
||||
super(fsPathToProjectUri(filePath, parent.root as ProjectRootTreeItem, true), parent);
|
||||
this.fileSystemUri = filePath;
|
||||
}
|
||||
|
||||
@@ -87,15 +88,18 @@ export function sortFileFolderNodes(a: (FolderNode | FileNode), b: (FolderNode |
|
||||
/**
|
||||
* Converts a full filesystem URI to a project-relative URI that's compatible with the project tree
|
||||
*/
|
||||
function fsPathToProjectUri(fileSystemUri: vscode.Uri, projectNode: ProjectRootTreeItem): vscode.Uri {
|
||||
function fsPathToProjectUri(fileSystemUri: vscode.Uri, projectNode: ProjectRootTreeItem, isFile?: boolean): vscode.Uri {
|
||||
const projBaseDir = projectNode.project.projectFolderPath;
|
||||
let localUri = '';
|
||||
|
||||
if (fileSystemUri.fsPath.startsWith(projBaseDir)) {
|
||||
localUri = fileSystemUri.fsPath.substring(projBaseDir.length);
|
||||
}
|
||||
else {
|
||||
throw new Error(`Project (${projBaseDir}) pointing to file outside of directory (${fileSystemUri.fsPath})`);
|
||||
else if (isFile) {
|
||||
// if file is outside the folder add add at top level in tree
|
||||
// this is not true for folders otherwise the outside files will not be directly inside the top level
|
||||
let parts = utils.getPlatformSafeFileEntryPath(fileSystemUri.fsPath).split('/');
|
||||
localUri = parts[parts.length - 1];
|
||||
}
|
||||
|
||||
return vscode.Uri.file(path.join(projectNode.uri.path, localUri));
|
||||
|
||||
Reference in New Issue
Block a user