Skip to content

Commit

Permalink
Improved URI handling for virtual FS (#1409)
Browse files Browse the repository at this point in the history
* Improved URI handling for virtual FS

* Ensure virtual filesystem is accepted as mdSelector

---------

Co-authored-by: Paul de Raaij <[email protected]>
  • Loading branch information
riccardoferretti and pderaaij authored Nov 12, 2024
1 parent aa311b2 commit e7ee143
Show file tree
Hide file tree
Showing 2 changed files with 19 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);
}
5 changes: 3 additions & 2 deletions packages/foam-vscode/src/services/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function formatMarkdownTooltip(content: string): MarkdownString {

export const mdDocSelector = [
{ language: 'markdown', scheme: 'file' },
{ language: 'markdown', scheme: 'vscode-vfs' },
{ language: 'markdown', scheme: 'untitled' },
];

Expand Down Expand Up @@ -219,9 +220,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 e7ee143

Please sign in to comment.