diff --git a/packages/foam-vscode/src/core/model/uri.ts b/packages/foam-vscode/src/core/model/uri.ts index 16010d1c0..1c8d95b31 100644 --- a/packages/foam-vscode/src/core/model/uri.ts +++ b/packages/foam-vscode/src/core/model/uri.ts @@ -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); } diff --git a/packages/foam-vscode/src/services/editor.ts b/packages/foam-vscode/src/services/editor.ts index 5ff0ed19d..af0255095 100644 --- a/packages/foam-vscode/src/services/editor.ts +++ b/packages/foam-vscode/src/services/editor.ts @@ -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(',')}}` ) );