yaegassy / coc-volar

Volar (Fast Vue Language Support) extension for coc.nvim
https://www.npmjs.com/package/@yaegassy/coc-volar
MIT License
269 stars 6 forks source link

How to Enable Local Formatting Configuration? #97

Closed phobetron closed 2 years ago

phobetron commented 2 years ago

In my CoC config file, the coc.preferences.formatOnSaveFiletypes list contains vue.

I recall that coc-vetur had the vetur.useWorkspaceDependencies flag that respected local configurations. Is there something similar for coc-volar? Is there another CoC configuration option that should be used instead?

I've noticed Volar has instructions for VS Code in this instance, but I don't know of an analog for Neovim.

yaegassy commented 2 years ago

If you want to use "prettier", please install coc-prettier.

As a side note, coc-prettier is set to disable vue files by default, so you need to adjust your settings to enable them.

e.g. coc-settings.json:

{
  // (1) Disable volar formatting.
  "volar.formatting.enable": false,
  // (2) Use a formatter when saving files.
  "coc.preferences.formatOnSaveFiletypes": [
    // ...snip
    "vue"
  ],
  // (3) Enable coc-prettier to use vue files as well
  "prettier.disableLanguages": []
}
phobetron commented 2 years ago

Thanks for the information, @yaegassy! I was unaware that Prettier would ignore Vue files. I suppose Vetur was superseding coc-prettier when configured to use workspace dependencies, and ran it in its own process... I don't yet understand the differences in design choices between the two LSPs.

Do you know whether it's possible to alter Volar's built-in formatting configuration as well? Does Volar handle formatting manually, or does it depend on other tools?

yaegassy commented 2 years ago

I think Volar uses prettyhtml, prettier (probably in the css part), pug-beautify, sass-formatter, etc. internally.

I don't think Volar's formatter allows you to change the detailed settings. With VSCode, it may be possible to adjust the ts/js part slightly, but not with coc-volar.

Volar formatter is designed to be used out of the box, for more custom rules I recommend switching to Prettier (coc-prettier).

phobetron commented 2 years ago

Yes, that does seem the best way to go. I've just been spoiled by Vetur's useWorkspaceDependencies feature 😅

I'll go ahead and close this issue. Thanks for your input!