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

Change reading file from native fs to vscode alternative #1295

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/foam-vscode/src/features/preview/wikilink-embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ function fullExtractor(
parser: ResourceParser,
workspace: FoamWorkspace
): string {
let noteText = readFileSync(note.uri.toFsPath()).toString();
let noteText;

vsWorkspace.fs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this will work?
I am not sure this would work, as this call returns a promise, and whether noteText is actually set when needed (e.g. line 192) becomes a matter of timing.
This is the reason why originally we didn't migrate this part of the code from readFileSync.

Am I missing something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not working. Need to refine it, but needed a test run on thr CI as I had some issues locally. Forgot to add wip to the PR ;)

.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');
Expand All @@ -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,
Expand Down