Skip to content

Commit

Permalink
Improved URI handling for virtual FS
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardoferretti committed Nov 8, 2024
1 parent 764750f commit cfceb56
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions packages/foam-vscode/src/core/model/uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,20 @@ function encodeURIComponentMinimal(path: string): string {
* TODO this probably needs to be moved to the workspace service
*/
export function asAbsoluteUri(uri: URI, baseFolders: URI[]): URI {
return URI.file(
pathUtils.asAbsolutePaths(
uri.path,
baseFolders.map(f => f.path)
)[0]
);
const path = uri.path;
if (pathUtils.isAbsolute(path)) {
return uri;
}
let tokens = path.split('/');
const firstDir = tokens[0];
if (baseFolders.length > 1) {
for (const folder of baseFolders) {
const lastDir = folder.path.split('/').pop();
if (lastDir === firstDir) {
tokens = tokens.slice(1);
return folder.joinPath(...tokens);
}
}
}
return baseFolders[0].joinPath(...tokens);
}
4 changes: 2 additions & 2 deletions packages/foam-vscode/src/services/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ export async function createMatcherAndDataStore(excludes: string[]): Promise<{
let files: Uri[] = [];
for (const folder of workspace.workspaceFolders) {
const uris = await workspace.findFiles(
new RelativePattern(folder.uri.path, '**/*'),
new RelativePattern(folder.uri, '**/*'),
new RelativePattern(
folder.uri.path,
folder.uri,
`{${excludePatterns.get(folder.name).join(',')}}`
)
);
Expand Down

0 comments on commit cfceb56

Please sign in to comment.