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

Inlay hints autocmd check #17

Closed ranebrown closed 2 years ago

ranebrown commented 2 years ago

Would it be possible to add a check that the running server supports inlay hints prior to running the set_inlay_hints autocmd? I normally run with clangd and null-ls. Sometimes when I do a clean it wipes out my compile_commands.json and the clangd server dies. Then I get spammed with messages about the server not supporting inlay hints when the autocmd runs.

p00f commented 2 years ago

clangd's server_capabilities doesn't have anything for inlay hints (even though https://clangd.llvm.org/extensions#inlay-hints says it should have clangdInlayHintsProvider) so I don't think this can be checked

ranebrown commented 2 years ago

Seemed like this might work with some quick testing? if client.supports_method("clangd/inlayHints") then.

Seemed like the same response for if client.supports_method("textDocument/inlayHints") then which might be better.

p00f commented 2 years ago

ah ok i'll do that

ranebrown commented 2 years ago

Might not be the best solution but this works.

        vim.api.nvim_create_autocmd(
            { "BufEnter", "BufWinEnter", "TabEnter", "BufWritePost" },
            {
                group = clangd_augroup,
                buffer = bufnr,
                callback = function()
                    local buf = vim.api.nvim_get_current_buf()
                    local clients = vim.lsp.buf_get_clients(buf)
                    for _, c in pairs(clients) do
                        if c.name == "clangd" then
                            require("clangd_extensions.inlay_hints").set_inlay_hints()
                            break
                        end
                    end
                end,
                desc = "Clangd set inlay hints",
            }
        )
p00f commented 2 years ago

looks ok, can you open a pr?