remarkjs / vscode-remark

Lint and format markdown code with remark
https://marketplace.visualstudio.com/items?itemName=unifiedjs.vscode-remark
MIT License
54 stars 11 forks source link

Remark will replace the contents of a markdown file with undefined if remark is not installed #113

Closed trickypr closed 2 years ago

trickypr commented 2 years ago

Initial checklist

Affected packages and versions

v2.0.0

Link to runnable example

No response

Steps to reproduce

  1. Install the remark vscode extension
  2. Open a folder that does not contain a remark installation
  3. Format a markdown file
  4. Experience the file being replaced with undefined

Runtime information:

Expected behavior

There should be an error telling you to install remark, but the file should be left unchanged.

Actual behavior

There is an error telling you to install remark, but it also replaces the content of your file with undefined

Runtime

Other (please specify in steps to reproduce)

Package manager

Other (please specify in steps to reproduce)

OS

macOS

Build and bundle tools

Other (please specify in steps to reproduce)

trickypr commented 2 years ago

As a side note, remark will continue to fail if you have remark installed globally. It appears that you must install it locally for it to work, which seems annoying, especially for those who use format-on-save.

wooorm commented 2 years ago
  1. but it also replaces the content of your file with undefined

That is a bug indeed. However:

  1. Uninstall any copies of the remark package

You shouldn’t do that though.

My guess is that the processor is cached (the module was loaded in the past so it’s still in the module cache). I can’t imagine why it would start returning empty files though? Perhaps an error is thrown here which is swallowed.

It appears that you must install it locally for it to work, which seems annoying, especially for those who use format-on-save.

This is intentional for this project (see readme). It is intended that you use this in combination with a) configuration specific to the project, b) versioned dependencies, optionally/typically c) with remark-cli so that you can ensure in a CI/makefile/npm scripts/etc that people who don’t have VS Code, also format the same way you do with VS Code.

trickypr commented 2 years ago

You shouldn’t do that though.

My guess is that the processor is cached (the module was loaded in the past so it’s still in the module cache).

I should be more clear that this happens before first install. In my case, Codacy was complaining that my markdown formatting was wrong and I got the vscode extension as a quick fix, without installing the lsp. I don't think that I have installed remark or the extension before, so I don't think it would be caching.

I have updated the reproduction steps to be more clear.

I can’t imagine why it would start returning empty files though?

By undefined, I don't mean empty files. I mean replacing the contents of the file with undefined.

Kapture 2022-07-26 at 21 55 46

This is intentional for this project (see readme).

Sorry, I skimmed the project name and ignored the readme. That is entirely my fault.

wooorm commented 2 years ago

I have updated the reproduction steps to be more clear.

Ahhh okay, that makes more sense, thanks.


This is likely a bug in unified-language-server.

/cc @remcohaszing

remcohaszing commented 2 years ago

I noticed a situation where the file contents are replaced with undefined myself. This should never happen, it’s worse than errors. I will investigate.

remcohaszing commented 2 years ago

Theis was fixed in https://github.com/unifiedjs/unified-language-server/pull/51 and released in version 2.1.0.

github-actions[bot] commented 2 years ago

Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.