foambubble/foam-vscode

Reference list accumulates "s"s"s on Windows

jevakallio opened this issue ยท 7 comments

Via @taneliang

image

Bet this is because of Windows EOL characters messing up the replace measurement here:
https://github.com/foambubble/foam-vscode/blob/master/src/extension.ts#L164

Or, could be a different editor setting that doesn't insert newlines at the end of the file like mine does.

In either case, that login can be made more robust, the current implementation has too many failure modes

This only happens if there's a bullet point in the line directly above the [//begin] line. If there's a blank line or just random text this doesn't happen.

Also, once that bullet point is removed, no new s"s are generated but the existing ones still remain.

I'm using WSL and the line endings are set to LF, but I can also repro this with the line endings set to CRLF. My editor is also configured to insert newlines at the end of the files ๐Ÿ˜†

Could it be an interaction between Prettier and Foam? Update: It seems like that may be it, this no longer happens when I disable my Prettier extension. I'm using the esbenp.prettier-vscode VS Code extension with Prettier 2.0.5 on WSL2 running Ubuntu. I'm also using VS Code Insiders.

image

Wow, thanks for the detailed repro notes! I think there's a way to make this more resilient anyway, right now I'm measuring the exact line length and position, but there's really no need for me to do that.

At the time of writing this feature I wanted to support having link references inline, but now I'm thinking they should always be at the end of the file so I should be able to safely read until the next line!

@taneliang I wasn't able to reproduce this (prettier, markdown lists etc withstanding), but I think 43fd95c fixes this.

I've released this in v0.1.4. Could you give this a try to see if it's fixed?

The new version is tested:

  • with and without prettier
  • with and without trailing newline config (should always leave a trailing newline, prettier can fix it if it wants to, after)
  • with and without markdown lists preceding reference lists
  • only on MacOS

Thanks! Looks like that fixed this particular issue, but I think that may have introduced another bug that is deleting lines if the line directly above [[//begin]] contains a wikilink. Repro steps:

  1. Create new file and type a wikilink to an existing file
    image
  2. Press save. Link references are generated. Not sure why it says they are out of date
    image
  3. Press save again. The wikilink line is deleted
    image
  4. Repeated saving at this point does not change the file contents.

Similar to the s" bug above, this doesn't happen if the line above [[//begin]] is just a blank line or contains random text (or a bullet point with no wiki-links).

It may be related to this other bug that causes newlines to be generated when an file that only contains whitespace chars is saved. Repro steps:

  1. Create new file
    image
  2. Press save. A newline is created
    image
  3. Press save again. Another newline is created
    image
  4. Repeated saving will cause newlines to be added.

Adding whitespace chars to any line in the file does not change this newline-adding behavior, but adding a non-whitespace char seems to cause Prettier to format the file and collapse all the newlines.

I'm not sure if these bugs were also present in v0.1.3. I'm happy to copy this into a new issue if it's not related to this s" issue, but it sounds like they're all related to EOL handling ๐Ÿ˜†

Thanks @taneliang, no need to create a new issue, I can test that these are solved by #4 (also explains why the list shows as out of date) and as a part of fixing #5

@taneliang if you have time, could you please give v0.1.5 a spin from the marketplace and let me know if this has indeed been fixed, as AFAIK you're the only one with the original issue. Remember to reload VS Code after updating the extension.

Thanks for reporting!

Awesome, this fixed all the issues above. Thanks @jevakallio!