lukas-reineke / lsp-format.nvim

A wrapper around Neovims native LSP formatting.
564 stars 27 forks source link

Custom format commands no longer working. #25

Closed AlexisFinn closed 2 years ago

AlexisFinn commented 2 years ago

Hello.

Ok, so what I used to do was disable formatting in nvim-lsp and use this plugin to take care of that. So instead now I use the on_attach config in the lsp as indicated in the doc, but this no longer seems to work (notably php-cs-fixer is not running, didn't really check on the rest but I suspect the above config no longer does anything). So my question is how do I get this working again.

This is my configuration:
```lua
require("lsp-format").setup {
  javascript = {
    {cmd = {"prettier -w", "./node_modules/.bin/eslint --fix"}}
  },
  typescript = {
    {cmd = {"prettier --parser typescript -w"}}
  },
  vue = {
    {cmd = {"prettier --parser vue -w"}}
  },
  scss = {
    {cmd = {"prettier --parser scss -w"}}
  },
  css = {
    {cmd = {"prettier --parser css -w"}}
  },
  yaml = {
    {cmd = {"prettier --parser yaml -w"}}
  },
  html = {
    {cmd = {"prettier --parser html -w"}}
  },
  haskell = {
    {cmd = {"hindent"}}
  },
  python = {
    {cmd = {"autopep8 --ignore E501"}}
  },
  php = {
    {cmd = {"php-cs-fixer fix"}}
  },
  go = {
    {cmd = {"goimports -w"}}
  },
  rust = {
    {cmd = {"rustfmt"}}
  }
}

local onAttach = (function(client)
  -- add custom formatting
  require('lsp-format').on_attach(client)

  -- add nvim-cmp (autocomplete) to lsp capabilities
  client.capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
  -- show doc with 'K'
  vim.api.nvim_set_keymap('n', 'K', ':lua vim.lsp.buf.hover()<CR>', {noremap = true, silent = true})
  -- jump to definition
  vim.api.nvim_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', {noremap = true, silent = true})
  vim.api.nvim_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", {noremap = true, silent = true})
  vim.api.nvim_set_keymap("n", "tt", "<cmd>lua vim.diagnostic.open_float()<CR>", {noremap = true, silent = true})
end)
etc...

PS: Sorry if there's just something I missed in the docs but it seems unclear to me.

lukas-reineke commented 2 years ago

Yes sorry, you are using the old version. I did not maintain that anymore for some time now. I decided to repurpose this repository for a modern way to format with LSP instead.

If you don't want to use LSP to format, you can either use https://github.com/mhartington/formatter.nvim, or pin the version of this repo to tag v1. That is the old version. It should still continue to work, but I won't be fixing any bugs.

AlexisFinn commented 2 years ago

ok, kinda what I figured. Thank you.