Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved URI handling for virtual FS #1409

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading