mason.nvim icon indicating copy to clipboard operation
mason.nvim copied to clipboard

prettier/prettier_d plugins

Open axieax opened this issue 2 years ago • 4 comments

Package name

Not sure

Package homepage

https://prettier.io/docs/en/plugins.html

Languages

many additional ones (as specified on the website)

How is this package distributed?

  • npm install a plugin
  • plugin can be detected as a language to be used from prettier / prettier_d

axieax avatar Jul 26 '22 14:07 axieax

Hello! Cool! Pull requests are always very welcomed to add new packages. If the distribution of the package is simple, the installation will most likely be so as well (existing package installers may be used for reference!). Otherwise, @williamboman will get around to looking into this ASAP!

williambotman avatar Jul 26 '22 14:07 williambotman

Not sure what would be the best way for configuring such plugins tbh

e.g.

  • passing a table of plugins under prettier
  • each plugin as a separate entry in the registry

axieax avatar Jul 26 '22 14:07 axieax

These exist already!

williamboman avatar Jul 26 '22 18:07 williamboman

Ah, it's regarding prettier plugins

williamboman avatar Jul 26 '22 18:07 williamboman

I would like to use the prettierd plugin prettier-plugin-svelte and don't know how to do this with Mason.

As a workaround, would it be possible to manually install this plugin into the Mason npm manager directory (~/.local/share/nvim/mason/packages)? If so, how would I do this -- run npm i with a prefix ?

Additional context:

I have a project with a .prettierrc file with "plugins": ["prettier-plugin-svelte"]

When trying to format a file using the function vim.lsp.buf.format(), I get the following debug output involving the mason npm manager directory (.local/share/nvim/mason/packages/prettierd) in the log file of null-ls:

[DEBUG Wed 28 Sep 2022 04:48:35 PM CEST] ...t/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:321: spawning command "prettierd" at /home/user/myproject with args { "/home/user/myproject/test.svelte" }
[TRACE Wed 28 Sep 2022 04:48:35 PM CEST] ...t/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:209: error output: Error: Cannot find module 'prettier-plugin-svelte'
Require stack:
- /home/user/myproject/node_modules/prettier/index.js
- /home/user/.local/share/nvim/mason/packages/prettierd/node_modules/@fsouza/prettierd/dist/service.js
- /home/user/.local/share/nvim/mason/packages/prettierd/node_modules/@fsouza/prettierd/node_modules/core_d/lib/server.js
- /home/user/.local/share/nvim/mason/packages/prettierd/node_modules/@fsouza/prettierd/node_modules/core_d/lib/daemon.js

Of course I have installed prettier-plugin-svelte in my project. mason, null-ls and nvim are all the most recent version.

Thanks, and thanks for Mason.

michaelfranzl avatar Sep 28 '22 15:09 michaelfranzl

I'm not entirely familiar how prettier resolves plugins, but I assume they need to be installed within the same Node module resolution path as prettier itself, in which case plugins needs to be installed adjacent to Mason's installation of prettier. Try:

$ cd ~/.local/share/nvim/mason/packages/prettierd
$ npm install prettier-plugin-svelte

Note that any modifications you make in this directory will be wiped when updating prettierd via Mason.

See #392 for the generalized issue for this. I've got something locally but it's turned out to be more complex and involved than I intended so I'm sort of backtracking it atm. (I'll close this issue for that one instead, but feel free to continue here for anything prettier specific)

williamboman avatar Sep 29 '22 00:09 williamboman

Thanks @williamboman for the suggestion. I tried it and it didn't work. However, additional investigation showed that I got fooled: prettierd spawns and detaches a long-running daemon which keeps a snapshot of the environment (.prettierrc, .prettierignore, the location of prettier, the entire stack of node including node_modules, etc.) This is why it did not pick up any newly installed plugins.

The solution was to stop prettierd to force it to freshly initialize.

It turns out that prettierd supports local prettier installs and local prettier plugins since about one year, since version 0.18.0. See https://github.com/fsouza/prettierd/blob/main/CHANGELOG.md#v0180

In conclusion, prettierd + prettier plugins work 'out of the box' with Mason.

michaelfranzl avatar Sep 29 '22 06:09 michaelfranzl