lukas-reineke / lsp-format.nvim

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

Setting up without messing up previous settings? #56

Closed Astrantia closed 1 year ago

Astrantia commented 1 year ago

I use rust-tools to dogfeed all the lsp related setup to lspconfig, and I don't need to manually add the following line lspconfig["rust_analyzer"].setup {} while setting up rust server. However, if I want to use lsp-format, then I have to have the following line in my config: lspconfig["rust_analyzer"].setup { on_attach = require "lsp-format".on_attach } While adding the above line makes formatting on save work, it messes up with the prior setup done by rust-tools. How can I use the functionality of both rust_tools and lsp-format simultaneously?

Astrantia commented 1 year ago

Quickly resolved it. For anyone's future reference:

local rt = require("rust-tools")

rt.setup({
  server = {
    on_attach = require "lsp-format".on_attach
      -- Hover actions
      vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr })
      -- Code action groups
      vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
    end,
  },
})

I should be passing on_attach to rust-tools' on_attach!