Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Cannot enable inlay hints #430

Open
LuckyMika opened this issue Nov 10, 2023 · 3 comments
Open

Cannot enable inlay hints #430

LuckyMika opened this issue Nov 10, 2023 · 3 comments

Comments

@LuckyMika
Copy link

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
@LuckyMika
Copy link
Author

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

@embe221ed
Copy link

neovim/neovim@448907f

@s1syph0s
Copy link

s1syph0s commented Dec 6, 2023

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,
  },
})

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants