From 66b38df5afe53b352509755f18925d491493f83e Mon Sep 17 00:00:00 2001 From: Paul de Raaij Date: Wed, 11 Oct 2023 10:21:40 +0200 Subject: [PATCH] Change reading file from native fs to vscode alternative --- .../src/features/preview/wikilink-embed.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/foam-vscode/src/features/preview/wikilink-embed.ts b/packages/foam-vscode/src/features/preview/wikilink-embed.ts index 441c7713b..4b3dd6650 100644 --- a/packages/foam-vscode/src/features/preview/wikilink-embed.ts +++ b/packages/foam-vscode/src/features/preview/wikilink-embed.ts @@ -177,7 +177,11 @@ function fullExtractor( parser: ResourceParser, workspace: FoamWorkspace ): string { - let noteText = readFileSync(note.uri.toFsPath()).toString(); + let noteText; + + vsWorkspace.fs + .readFile(toVsCodeUri(note.uri)) + .then(f => (noteText = f.toString())); const section = Resource.findSection(note, note.uri.fragment); if (isSome(section)) { const rows = noteText.split('\n'); @@ -194,7 +198,12 @@ function contentExtractor( parser: ResourceParser, workspace: FoamWorkspace ): string { - let noteText = readFileSync(note.uri.toFsPath()).toString(); + let noteText; + + vsWorkspace.fs + .readFile(toVsCodeUri(note.uri)) + .then(f => (noteText = f.toString())); + let section = Resource.findSection(note, note.uri.fragment); if (!note.uri.fragment) { // if there's no fragment(section), the wikilink is linking to the entire note,