p00f / clangd_extensions.nvim

Clangd's off-spec features for neovim's LSP client. Use https://sr.ht/~p00f/clangd_extensions.nvim instead
MIT License
448 stars 16 forks source link

Add `CursorHold` to the trigger for the inlay hints #40

Closed judaew closed 11 months ago

judaew commented 11 months ago

I suggest adding a CursorHold to the triggers to update the inlay hints immediately. This way, inlay hints will be updated in real time instead of only when BufWritePost.

function M.setup_autocmd()
-    local events = "BufEnter,BufWinEnter,TabEnter,BufWritePost"
+    local events = "BufEnter,BufWinEnter,TabEnter,BufWritePost,CursorHold"
    if config.options.extensions.inlay_hints.only_current_line then

See lua/clangd_extensions/inlay_hints.lua#L30.

p00f commented 11 months ago

I think this is too frequent to do without a debounce, and I don't want to implement debounce (because neovim nightly already has this)

You can either

judaew commented 11 months ago

Thanks @p00f!

I'll leave here a guide for other users. This is the minimum config to enable inlay hints for Neovim 0.10.0 (not released yet):

local on_attach = function(client, bufnr)
    -- here is your attach conf

    -- enable inlay hint
    if client.server_capabilities.inlayHintProvider then
        vim.lsp.inlay_hint(bufnr, true)
    end
end

local capabilities = vim.lsp.protocol.make_client_capabilities()

local servers = {
    clangd = {
        cmd = { vim.fn.exepath("clangd"),
            -- here is your clangd command line args
    }
}

for i in pairs(servers) do
    require("lspconfig")[i].setup({
        capabilities = capabilities,
        on_attach = on_attach,
        settings = servers[i]
    })
end

If you are using the clangd_extensions.nvim plugin, then use the following condition:

for i in pairs(servers) do
    if i == "clangd" then
        require("clangd_extensions").setup({
            server = {
                capabilities = capabilities,
                on_attach = on_attach,
                settings = servers[i]
            },
            extensions = {
                autoSetHints = false,
            }
        })
    else
        require("lspconfig")[i].setup({
            capabilities = capabilities,
            on_attach = on_attach,
            settings = servers[i]
        })
    end
end
p00f commented 11 months ago

That seems correct