Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

item.abbr too wide completion window does not aligned correctly #2051

Closed
2 tasks done
Song-Tianxiang opened this issue Sep 28, 2024 · 3 comments
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@Song-Tianxiang
Copy link

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

local cmp = require('cmp')

local kind_icons = {
    Text = '󰦨',
    Method = '󰆧',
    Function = '󰊕',
    Constructor = '',
    Field = '󰇽',
    Variable = '󰂡',
    Class = '󰠱',
    Interface = '',
    Module = '',
    Property = '󰜢',
    Unit = '',
    Value = '󰎠',
    Enum = '',
    Keyword = '󰌋',
    Snippet = '',
    Color = '󰏘',
    File = '󰈙',
    Reference = '',
    Folder = '󰉋',
    EnumMember = '',
    Constant = '󰏿',
    Struct = '',
    Event = '',
    Operator = '󰆕',
    TypeParameter = '󰅲',
}

local formatFn = function(_, item)
    local icon = kind_icons[item.kind] or ''
    icon = ' ' .. icon .. ' '

    item.menu = ('   (' .. item.kind .. ')') or ''
    item.kind = icon

    return item
end

require('cmp').setup({
    experimental = {
        ghost_text = true,
    },
    matching = {
        disallow_fuzzy_matching = false,
    },
    completion = {
        keyword_length = 1,
        completeopt = 'menuone,noselect,noinsert,popup,fuzzy',
    },
    snippet = {
        expand = function(args)
            require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
        end,
    },
    mapping = {
        ['<C-p>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
        ['<C-n>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
        ['<C-e>'] = cmp.mapping.abort(),
        ['<C-y>'] = cmp.mapping.confirm({ select = true }),
        ['<C-d>'] = cmp.mapping.scroll_docs(3),
        ['<C-u>'] = cmp.mapping.scroll_docs(-3),

        ['<CR>'] = cmp.mapping({
            i = function(fallback)
                if cmp.visible() and cmp.get_active_entry() then
                    cmp.confirm({ select = false })
                else
                    fallback()
                end
            end,
            s = cmp.mapping.confirm({ select = true }),
        }),
    },
    formatting = {
        expandable_indicator = true,
        fields = { 'kind', 'abbr', 'menu' },
        format = formatFn,
    },
    window = {
        completion = {
            col_offset = -3,
            side_padding = 0,
            winhighlight = "Normal:CmpPmenu,CursorLine:CmpSel,Search:None",
            scrollbar = true,
            -- border = { '', '─','', '─',},
            -- border = { "", "", "", "│", "", "", "", "│" },
        },
        documentation = {
            border = {
                { "", "CmpDocBorder" },
                { "", "CmpDocBorder" },
                { "", "CmpDocBorder" },
                { "", "CmpDocBorder" },
                { "", "CmpDocBorder" },
                { "", "CmpDocBorder" },
                { "", "CmpDocBorder" },
                { "", "CmpDocBorder" },
            },
            winhighlight = "Normal:CmpDoc",
        },
    },
    sources = cmp.config.sources({
        { name = 'luasnip' },
        { name = 'nvim_lsp', },
        { name = 'buffer' },
        { name = 'path' },
        { name = 'nvim_lsp_signature_help' },
    }, {
    })
})

Description

item.abbr too wide completion window does not aligned correctly

Screenshot 2024-09-28 at 10 33 05 AM

Steps to reproduce

config as above and edit a cpp file with configed clangd lsp.

Expected behavior

we can set the width of abbr field and completion window like view.document.max_width.
completion window is correctly aligned

Actual behavior

item.abbr too wide completion window does not aligned correctly

Additional context

No response

@Song-Tianxiang Song-Tianxiang added the bug Something isn't working label Sep 28, 2024
@Song-Tianxiang
Copy link
Author

The completion windows are not aligned correctly, is this expected behavior? Or is it just something wrong with my configuration?
Screen Recording 2024-09-28 at 11 20 38 AM

@Shougo
Copy link

Shougo commented Sep 28, 2024

Hm...

The completion window seems to be starting at an incorrect position because it is too large, trying to display all the completion candidates. To prevent this, I think you need to set a maximum width for the completion window.

#980

@Song-Tianxiang
Copy link
Author

Thank you. It works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants