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

Fallback to global remark installation #6

Closed
4 tasks done
bennypowers opened this issue May 23, 2022 · 15 comments · Fixed by #14
Closed
4 tasks done

Fallback to global remark installation #6

bennypowers opened this issue May 23, 2022 · 15 comments · Fixed by #14
Labels
🤞 phase/open Post is being triaged manually

Comments

@bennypowers
Copy link

Initial checklist

Problem

Here's one scenario, which I imagine is probably very common:

  • The repo contains markdown files
  • The repo does not use remark in any of it's app code or dependencies
  • The user wants to format markdown files in the repo, for example the README.md file
  • The user does not want to install any extra dependencies

In that case, if the user chooses nvim as their editor, and sets up their lsp config like this:

lspconfig.remark_ls.setup {
  defaultProcessor: 'remark'
}

Then, the user will receive the following error message on every character they type into any markdown file:

Cannot turn on language server without remark locally. Run npm install remark to enable it

See also unifiedjs/unified-language-server#31

Solution

remark-language-server should either bundle its own fallback copy of remark, or default to the global installation (i.e. npm i -g remark) and some ~/.config/remarkrc.yml configuration, if it does not find a configuration or package.json file.

Alternatives

  • Don't use remark_ls
  • Don't use nvim
  • Manually format your own markdown files char by char
@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels May 23, 2022
@TerminalFi
Copy link

@bencmbrook
Copy link

bencmbrook commented Nov 22, 2022

This would be great!

This would also work around a bug which I think is related to my setup with Yarn PnP, where remark is not being found despite being locally installed. I'm getting this same error ("Cannot turn on language server without remark locally. Run npm install remark to enable it"). The underlying PnP issue may be coming from load-plugin

@oliverlambson
Copy link

Bump on this. Having exactly the same issue—want to format my README.md and can't use globally installed remark

@axgkl
Copy link

axgkl commented Aug 29, 2023

my workaround - ugly but works:

remark will search upwards your path to find its "local installation", ignoring all node_modules dirs w/o remark. So go to your home and install it there:

cd
npm install remark

@9mm
Copy link

9mm commented Sep 17, 2023

this seems very weird... why should my project require a local node_modules folder for things not even remotely related to JS, just to have a random MD file parse properly. this should be using the global remark from command line. at the very least we should be able to configure the lsp with some kind of bin path or something...

@wooorm
Copy link
Member

wooorm commented Sep 20, 2023

npm isn’t just for js. this isn’t a “random md file parser”. this is called remark-language-server not markdown-language-server

@9mm
Copy link

9mm commented Sep 20, 2023

Ok, well remark can be used from the CLI.. ie not project specific. So shouldnt a remark LSP handle MD thats not project specific, similar to as if I used the remark-cli?

@wooorm
Copy link
Member

wooorm commented Sep 20, 2023

remark can be used from the CLI.

That’s a different aspect than being global or not.
Similarly, this project is already an LSP, regardless of how it is installed.

Something being usable from a shell has to do with where it is located on the file system.

If you put a remark somewhere on the file system too (specifically in node_modules/ higher than your project, so say in `/Users/tilde/node_modules/), this works.

@Murderlon
Copy link
Member

this should be using the global remark from command line

For some extra context, here is my previous answer on why a global remark wouldn't be as convenient as one might think: https://github.com/orgs/remarkjs/discussions/960#discussioncomment-2270454

@9mm
Copy link

9mm commented Sep 20, 2023

Ok, that makes sense @Murderlon .. I suppose a greater reason of what Im actually looking for is I have 100+ repos of various types and sizes, all of them having README, documentation, etc. Some are big, some are small, some are quick, some are multiple year long projects. I basically just want to validate and edit whatever markdown file I open without thinking about it, and certainly without configuring every repo specifically.

Having a node_modules in my home folder is horrid, and I suppose Ill just use a different one, but I do appreciate thats a solution

@Murderlon
Copy link
Member

I understand and I think that could be a valid use case for remark-language-server, but there is no way around installing plugins somewhere and having a config file somewhere.

default to the global installation (i.e. npm i -g remark) and some ~/.config/remarkrc.yml configuration

@wooorm @remcohaszing I'm not fully up-to-date on these LSP discussions, there have been multiple, but I have seen enough of them that the idea of configuring remark globally is clearly a need for quite a few people. As far as I know, adding support for $HOME/.config/ and using a global installation as a fallback wouldn't conceptually go against remark's usage. Local usage remains the same. What do you think?

@9mm
Copy link

9mm commented Sep 20, 2023

i 100% think -g is an extremely perfect solution, ultimately thats why it exists I believe, and thats how every other library ive ever used solves it, that has some global library from NPM

My hangup was having the node modules in my home folder when I feel like that is defeating the purpose of global node modules

And yes, i also 100% agree on some kind of remarkrc.yml config, that would be in line with my expectations on how most libraries which work the same way would be configured.

The only change is i believe it should be .remarkrc.yml so its hidden like all other yaml configs

@remcohaszing
Copy link
Member

unifiedjs/unified-language-server#43 adds the setting remark.requireConfig. When this is true, the language server will only perform actions of a .remarkrc file is found. I think this is what most people actually want.

unified-language-server has support for the defaultProcessor option. Setting this means the language server would fall back to the bundled remark if remark can’t be found in node_modules. I think it’s good to set this too. For example pnpm users may have remark-cli installed directly, but not remark.

I don’t have remark installed globally, and I don’t expect any other users to have to either. In VSCode I disable the extension for projects that don’t use remark. Having to do this is annoying, and possibly even more so for other clients.

The OP shows they use defaultProcessor as a configuration setting. However, this configuration setting does not exist. It appears to be confused with the defaultProcessor option for creating a unified language server. I hope the updated documentation and introduction of a configuration setting will clear up this confusion.

@wooorm is busy creating major releases all over the unified ecosystem. remark-cli was updated 2 days ago. unified-language-server and remark-language-server could be next.

@wooorm
Copy link
Member

wooorm commented Sep 24, 2023

but I have seen enough of them that the idea of configuring remark globally is clearly a need for quite a few people.

My general feeling is that folks are looking for a batteries included markdown linter/formatter. I think that’s a different project. Things like remarkjs/vscode-remark#86 and for example https://github.com/syntax-tree/mdast-util-mdx-jsx/blob/15da3704395cd3c541dfcfe9fb28029674331f1c/lib/index.js#L680-L682 will help. Or maybe the CST in micromark.


Generally, the thing is: folks install something and see an error, leading them to think a global remark will solve that error and everything else. But the error isn’t about that. Having remark global solves nothing. remark doesn’t do anything. Folks want to do things

remcohaszing added a commit that referenced this issue Sep 25, 2023
This is used as a fallback if remark can’t be resolved.

Closes #6
remcohaszing added a commit that referenced this issue Sep 25, 2023
This is used as a fallback if remark can’t be resolved.

Closes #6
@github-actions
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤞 phase/open Post is being triaged manually
Development

Successfully merging a pull request may close this issue.

9 participants