simrat39/rust-tools.nvim

Cannot enable inlay hints

Opened this issue · 3 comments

It is impossible to enable inlay hints, since neither the lua function nor the command are defined.

require('rust-tools').inlay_hints.set

returns nil

RustEnableInlayHints
E492: Not an editor command: RustEnableInlayHints

Quick little update, the entire table only consists of inlay_hints which is an empty table and setup which is the setup function.

I looked into your nvim config in your repo, and I saw that you are using mason_lspconfig.setup_handlers to install the capabilities. This function will setup all of your LSPs detected by Mason.

This plugin automatically sets up nvim-lspconfig for rust_analyzer for you, so don't do that manually, as it causes conflicts.

This means, that Mason sets up rust_analyzer for you, not your configuration. Try to change your config to be something like this:

local handlers = {
  function(server_name)
    require('lspconfig')[server_name].setup {
      capabilities = capabilities,
      on_attach = on_attach,
      settings = servers[server_name],
      filetypes = (servers[server_name] or {}).filetypes,
    }
  end,
  ["rust_analyzer"] = function()              -- This will "skip" setting up rust_analyzer
  end
}

mason_lspconfig.setup_handlers(handlers)

To setup the rust_analyzer, you want to call the modified version of on_attach function, since you want to add another keymappings. Maybe something like this:

local rt = require("rust-tools")

rt.setup({
  server = {
    on_attach = function(_, bufnr)
      on_attach(_, bufnr)   -- This calls your default on_attach function, so every keymap will be loaded correctly
      vim.keymap.set("n", "<leader>ca", require("rust-tools.code_action_group").code_action_group, { buffer = bufnr})
      vim.keymap.set("n", "<leader>ha", require("rust-tools.hover_actions").hover_actions, { buffer = bufnr})
    end,
  },
})