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
485 stars 18 forks source link

inlay hints - `only_current_line` not working #47

Closed litoj closed 1 year ago

litoj commented 1 year ago

I found nothing in official docs about how to set options through lsp, tried all other places I could find - still nothing.

Configuration shown here is not working for me (lazy.nvim):

local M = { 'p00f/clangd_extensions.nvim', event = 'VeryLazy', dependencies = 'nvim-lspconfig' }
function M.config()
    require('clangd_extensions').setup {
        inlay_hints = { only_current_line = true, show_parameter_hints = false },
    }
    require('lspconfig').clangd.setup {
        capabilities = { offsetEncoding = 'utf-16' },
        root_dir = function(fname)
            return vim.fs.dirname(vim.fs.find({
                'src',
                'Makefile',
                'CMakeLists.txt',
                '.git',
            }, { upward = true, path = fname })[1])
        end,
        on_attach = function(client, bufnr)
            require('clangd_extensions.inlay_hints').setup_autocmd()
            require('clangd_extensions.inlay_hints').set_inlay_hints()
        end,
    }
end
return M

None of the changed settings apply, also when I set builtin inlay hints on, I see them twice.

When including setup_autocmd, the inlay hints provided by this plugin are not displayed.

I am mainly looking for a way to configure clangd through LSP, since I haven't found online anything about it that would have worked.

p00f commented 1 year ago

None of the changed settings apply

are you sure you're calling M.config()? Sorry, I can't help you further - this plugin only provides extra commands and inlay hints.

Side note, you don't need "VeryLazy" or any kind of lazy loading, this plugin already lazy loads itself

also when I set builtin inlay hints on, I see them twice.

Of course, this is only for neovim 0.9 or lower which doesn't have inlay hints built in

When including setup_autocmd, the inlay hints provided by this plugin are not displayed.

just use builtin inlay hints if you use neovim 0.10

I am mainly looking for a way to configure clangd through LSP, since I haven't found online anything about it that would have worked.

https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#clangd should be all

Instead of messing around with lazy.nvim, I think you should just add this somewhere in your init file:

require('lspconfig').clangd.setup {
    capabilities = { offsetEncoding = 'utf-16' },
    root_dir = function(fname)
        return vim.fs.dirname(vim.fs.find({
            'src',
            'Makefile',
            'CMakeLists.txt',
            '.git',
        }, { upward = true, path = fname })[1])
    end,
    on_attach = function(_client, bufnr)
        vim.lsp.inlay_hint(bufnr, true)
    end,
}
litoj commented 1 year ago

are you sure you're calling M.config()?

Well, yes - clangd does get started so that most certainly does get called

this is only for neovim 0.9 or lower which doesn't have inlay hints built in

I see, but so far this was the only option to get inlay hints just for the current line. That was why I was sad that I couldn't get the config to affect anything.

lspconfig/clangd should be all

Well, from what I can tell, there is no mention of any sorts of configuration options specific to clangd, just the general lsp settings. On the Internet I only found some SublimeText example, which - even when translated to lua - did nothing even after trying a bunch of different variations.

I was hoping you ran into an issue of wanting to change some default settings, too, since you went through the effort to create this plugin.

p00f commented 1 year ago

ah those are through ~/.config/clangd/config.yaml

https://clangd.llvm.org/config#files

can't get only current line to work

I can reproduce this, I'll fix this soon

p00f commented 1 year ago

So only_current_line only worked when inline = false, I fixed it now