remarkjs / remark-language-server

A language server to lint and format markdown files with remark
MIT License
33 stars 1 forks source link

Fallback to global remark installation #6

Closed bennypowers closed 12 months ago

bennypowers commented 2 years ago

Initial checklist

Problem

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

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 https://github.com/unifiedjs/unified-language-server/issues/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

TerminalFi commented 2 years ago

https://github.com/unifiedjs/unified-language-server/issues/44

bencmbrook commented 1 year ago

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 commented 1 year ago

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

axgkl commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

https://github.com/unifiedjs/unified-language-server/pull/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 commented 12 months ago

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 https://github.com/remarkjs/vscode-remark/issues/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

github-actions[bot] commented 12 months ago

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