Skip to content

Diagnostics window always opens from behind #2000

@esn89

Description

@esn89

FAQ

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

Announcement

Minimal reproducible full config

local WIDE_HEIGHT = 40
local cmp_kinds = {
    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 = '',
}

return {
    'hrsh7th/nvim-cmp',
    config = function()
        local t = function(str)
            return vim.api.nvim_replace_termcodes(str, true, true, true)
        end
        local cmp = require('cmp')
        local types = require('cmp.types')
        require('cmp').setup({
            snippet = {
                expand = function(args)
                    require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
                end,
            },
            view = {
                entries = {
                    follow_cursor = true,
                },
            },
            sorting = {
                comparators = {
                    cmp.config.compare.offset,
                    cmp.config.compare.exact,
                    cmp.config.compare.score,
                    cmp.config.compare.recently_used,
                },
            },
            completion = {
                completeopt = 'Normal:Pmenu,FloatBorder:Pmenu,Search:None',
                col_offset = -3,
                side_padding = 0,
                autocomplete = { types.cmp.TriggerEvent.TextChanged },
            },
            formatting = {
                format = function(_, vim_item)
                    vim_item.kind = '' .. (cmp_kinds[vim_item.kind] or '') .. vim_item.kind
                    return vim_item
                end,
            },
            window = {
                completion = cmp.config.window.bordered(),
                -- documentation = cmp.config.window.bordered(),
                documentation = {
                    max_height = math.floor(WIDE_HEIGHT * (WIDE_HEIGHT / vim.o.lines)),
                    max_width = math.floor((WIDE_HEIGHT * 2) * (vim.o.columns / (WIDE_HEIGHT * 2 * 16 / 9))),
                    border = 'rounded',
                    winhighlight = 'FloatBorder:FloatBorder',
                    winblend = vim.o.pumblend,
                },

                scrollbar = true,
            },
            mapping = {
                ['<CR>'] = cmp.mapping({
                    i = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }),
                    c = function(fallback)
                        if cmp.visible() then
                            cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
                        else
                            fallback()
                        end
                    end,
                }),
                ['<C-d>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
                ['<C-u>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
                ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
                ['<C-e>'] = cmp.mapping({ i = cmp.mapping.close(), c = cmp.mapping.close() }),
                ['<C-n>'] = cmp.mapping({
                    c = function()
                        if cmp.visible() then
                            cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
                        else
                            vim.api.nvim_feedkeys(t('<Down>'), 'n', true)
                        end
                    end,
                    i = function(fallback)
                        if cmp.visible() then
                            cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
                        else
                            fallback()
                        end
                    end,
                }),
                ['<C-p>'] = cmp.mapping({
                    c = function()
                        if cmp.visible() then
                            cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
                        else
                            vim.api.nvim_feedkeys(t('<Up>'), 'n', true)
                        end
                    end,
                    i = function(fallback)
                        if cmp.visible() then
                            cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
                        else
                            fallback()
                        end
                    end,
                }),
            },
            experimental = {
                ghost_text = false,
            },
            sources = cmp.config.sources({
                { name = 'nvim_lsp' },
                { name = 'path' },
                { name = 'nvim_lua' },
                { name = 'buffer' },
                { name = 'luasnip' },
                { name = 'nvim_lsp_signature_help' },
            }),
            -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
            cmp.setup.cmdline({ '/', '?' }, {
                mapping = cmp.mapping.preset.cmdline(),
                sources = {
                    { name = 'buffer' },
                },
            }),
            cmp.setup.cmdline(':', {
                completion = {
                    completeopt = 'menu,menuone,noinsert',
                },
                -- mapping = cmp.mapping.preset.cmdline(),
                mapping = cmp.mapping.preset.cmdline({
                    ['<CR>'] = {
                        c = function()
                            if cmp.visible() then
                                cmp.confirm({ select = false })
                            end

                            local cr = vim.api.nvim_replace_termcodes('<CR>', true, true, true)
                            vim.api.nvim_feedkeys(cr, 'n', true)
                        end,
                    },
                }),
                sources = cmp.config.sources({
                    { name = 'path' },
                }, {
                    { name = 'cmdline' },
                }),
                -- matching = { disallow_symbol_nonprefix_matching = false },
            }),
        })
    end,
    dependencies = {
        'hrsh7th/cmp-nvim-lua',
        'hrsh7th/cmp-nvim-lsp',
        'hrsh7th/cmp-buffer',
        'hrsh7th/cmp-cmdline',
        'hrsh7th/cmp-path',
        'hrsh7th/cmp-nvim-lsp-signature-help',
        'L3MON4D3/LuaSnip',
    },
}

Description

When I am in the middle of autocomplete in any language (Golang/Python).

As autocomplete starts, I see another window in the background (which I am very sure are Diagnostics since I am in the middle of completing):

fmt.S][ <-- My cursor is here

Now there is a total of 3 pop ups:

  1. is the menu for me to select the completion item
  2. the documentation item
  3. the diagnostics/lint info hiding in the background

Example: https://imgur.com/a/0JdPN8O

Steps to reproduce

Take my nvim-cmp settings from above.
Try to autocomplete

Expected behavior

I should not be able to see the diagnostics hiding in the background poking out.

Actual behavior

I see the diagnostics window hiding in the background, poking out.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions