micangl / cmp-vimtex

Vimtex source for nvim-cmp.
MIT License
78 stars 5 forks source link

Custom formatting work-around #5

Closed Chiarandini closed 8 months ago

Chiarandini commented 9 months ago

I've just moved over to using cmp-vimtex from cmp-omni. I'm liking it better, and there are a few hick-up's I'm trying to fix. I'd like to see the citation information the plugin provides, but I have a custom formatting for my cmp sources:

cmp.setup({ 
...
    formatting = {
    fields = { "kind", "abbr", "menu" },
    format = function(entry, vim_item)
        vim_item.kind = string.format('%s %s', icons.kind_icons[vim_item.kind], vim_item.kind) -- This concatenates the icons with the name of the item kind
        vim_item.menu = ({
            nvim_lsp = "[Lsp]",
            luasnip = "[Snip]",
            path = "[Path]",
            nerdfont = '[Nerd]',
            buffer = "[Buf]",
            spell = "[Spell]",
            calc = "[Calc]",
            vimtex = "[Vimtex]",
            git = "[Git]",
            Variable = "[Var]",
            Todos = "[Comment]",
        })[entry.source.name]
        return vim_item
    end,
    }
...
})

I have done require('cmp-vimtex').setup(...) as well, but this seems to override it. I think I need to put something here to say that for cmp-vimtex, use its custom formatting. Any ideas on how to do that?

micangl commented 9 months ago

Unfortunately, setting the menu field seems to prevent the display of the additional bibliographic information. A quick solution is to just check if the entry source if cmp-vimtex; if so, we skip setting the menu tag. Notice the if statement I've added.

cmp.setup({ 
...
    formatting = {
    fields = { "kind", "abbr", "menu" },
    format = function(entry, vim_item)
        vim_item.kind = string.format('%s %s', icons.kind_icons[vim_item.kind], vim_item.kind) -- This concatenates the icons with the name of the item kind

                if entry.source.name == "vimtex" then
                    return vim_item
                end
        vim_item.menu = ({
            nvim_lsp = "[Lsp]",
            luasnip = "[Snip]",
            path = "[Path]",
            nerdfont = '[Nerd]',
            buffer = "[Buf]",
            spell = "[Spell]",
            calc = "[Calc]",
            vimtex = "[Vimtex]",
            git = "[Git]",
            Variable = "[Var]",
            Todos = "[Comment]",
        })[entry.source.name]
        return vim_item
    end,
    }
...
})
micangl commented 9 months ago

@Chiarandini Did you try it out? If it worked for you, I'll add a warning to the documentation.

micangl commented 8 months ago

Closing for inactivity.