edave

u/edave@programming.dev
1 posts · 1 comments

Recent posts

Recent comments

This is the post I tried to share this morning as a reference for the type of information I want to be sure is available in the future:


✅ How to Enable Parameter Hinting in Neovim with lsp_signature.nvim and lazy.nvim

To display function signatures and parameter hints inline while coding in Neovim, follow these steps:

1. Add lsp_signature.nvim to Your Plugin List

If you're using lazy.nvim as your plugin manager, include the following in your plugin setup:

{
  "ray-x/lsp_signature.nvim",
  event = "InsertEnter",
  config = function()
    require("lsp_signature").setup({
      bind = true,
      hint_enable = true,
      handler_opts = {
        border = "rounded"
      },
      floating_window = true,
      fix_pos = true,
      hi_parameter = "Search",
    })
  end,
},

This configuration ensures that lsp_signature.nvim loads when you enter insert mode and provides a floating window with function signature hints.

2. Update Your LSP on_attach Function

Ensure that lsp_signature is attached when your LSP client attaches to a buffer:

local on_attach = function(_, bufnr)
  local bufmap = function(mode, lhs, rhs)
    vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, { noremap=true, silent=true })
  end
  bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>')
  bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>')
  bufmap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>')
  bufmap('n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>')

  -- Attach lsp_signature
  require("lsp_signature").on_attach({
    bind = true,
    hint_enable = true,
    handler_opts = {
      border = "rounded"
    },
    floating_window = true,
    fix_pos = true,
    hi_parameter = "Search",
  }, bufnr)
end

Then, pass this on_attach function to your LSP server setup:

require('lspconfig').pyright.setup({
  on_attach = on_attach,
  -- other configurations
})

3. Restart Neovim

After saving your configuration changes, restart Neovim to load the new plugin and settings.

4. Test the Setup

Open a Python file and start typing a function call, such as ChatMessage(. You should see a floating window displaying the function's parameters.


This setup provides real-time function signature hints, enhancing your coding experience in Neovim. If you need further assistance or customization, feel free to ask!