Skip to content

Commit e7ee143

Browse files
Improved URI handling for virtual FS (#1409)
* Improved URI handling for virtual FS * Ensure virtual filesystem is accepted as mdSelector --------- Co-authored-by: Paul de Raaij <[email protected]>
1 parent aa311b2 commit e7ee143

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

packages/foam-vscode/src/core/model/uri.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,20 @@ function encodeURIComponentMinimal(path: string): string {
381381
* TODO this probably needs to be moved to the workspace service
382382
*/
383383
export function asAbsoluteUri(uri: URI, baseFolders: URI[]): URI {
384-
return URI.file(
385-
pathUtils.asAbsolutePaths(
386-
uri.path,
387-
baseFolders.map(f => f.path)
388-
)[0]
389-
);
384+
const path = uri.path;
385+
if (pathUtils.isAbsolute(path)) {
386+
return uri;
387+
}
388+
let tokens = path.split('/');
389+
const firstDir = tokens[0];
390+
if (baseFolders.length > 1) {
391+
for (const folder of baseFolders) {
392+
const lastDir = folder.path.split('/').pop();
393+
if (lastDir === firstDir) {
394+
tokens = tokens.slice(1);
395+
return folder.joinPath(...tokens);
396+
}
397+
}
398+
}
399+
return baseFolders[0].joinPath(...tokens);
390400
}

packages/foam-vscode/src/services/editor.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export function formatMarkdownTooltip(content: string): MarkdownString {
5454

5555
export const mdDocSelector = [
5656
{ language: 'markdown', scheme: 'file' },
57+
{ language: 'markdown', scheme: 'vscode-vfs' },
5758
{ language: 'markdown', scheme: 'untitled' },
5859
];
5960

@@ -219,9 +220,9 @@ export async function createMatcherAndDataStore(excludes: string[]): Promise<{
219220
let files: Uri[] = [];
220221
for (const folder of workspace.workspaceFolders) {
221222
const uris = await workspace.findFiles(
222-
new RelativePattern(folder.uri.path, '**/*'),
223+
new RelativePattern(folder.uri, '**/*'),
223224
new RelativePattern(
224-
folder.uri.path,
225+
folder.uri,
225226
`{${excludePatterns.get(folder.name).join(',')}}`
226227
)
227228
);

0 commit comments

Comments
 (0)