hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
8.09k stars 400 forks source link

[bug after the floating window update] completion menu is not triggered automaticall anymore #297

Closed alexzanderr closed 3 years ago

alexzanderr commented 3 years ago

completion menu its not triggered by default anymore. only if i press control + space (or trigger key), meaning that only manually will be triggered.

my cmp config:

local cmp = require("cmp")
cmp.setup({
    snippet = {
        expand = function(args) require"luasnip".lsp_expand(args.body) end

    }, -- in this order they will appear in the box
    sources = {
        { name = "nvim_lsp" },
        { name = "luasnip" },
        -- cmp buffer is causing UI bad performance
        -- so its disabled
        -- { name = "buffer" },

        { name = "path" },
        { name = "nvim_lua" } -- {
        --  name = 'tmux',
        --    opts = {
        --      all_panes = false,
        --      label = '[tmux]',
        --      trigger_characters = { '.' },
    }, --       trigger_characters_ft = {} -- { filetype = { '.' } }
    --    }
    -- }
    completion = {
        -- with this false completion is triggered only manually
        autocomplete = true
    },
    mapping = {
        -- ['<C-d>'] = cmp.mapping.scroll_docs(-4),
        -- ['<C-f>'] = cmp.mapping.scroll_docs(4),
        ["<C-p>"] = cmp.mapping.select_prev_item(),
        ["<C-n>"] = cmp.mapping.select_next_item(),
        ["<C-space>"] = cmp.mapping.complete(),
        -- ["<C-e>"] = cmp.mapping.close(),
        ["<esc>"] = cmp.mapping.close(),
        -- ['<CR>'] = cmp.mapping.confirm({
        --   select = true,
        --   behavior = cmp.ConfirmBehavior.Replace,
        -- }),
        ["<CR>"] = cmp.mapping.abort(),
        ["<tab>"] = cmp.mapping.confirm({
            select = true -- behavior = cmp.ConfirmBehavior.Replace,
        })
        -- ["<tab>"] = cmp.mapping.select_next_item(),
    },
    formatting = {
        format = function(entry, vim_item)
            -- fancy icons and a name of kind
            vim_item.kind = require("lspkind").presets.default[vim_item.kind] ..
                                " " .. vim_item.kind

            -- set a name for each source
            vim_item.menu = ({
                nvim_lsp = "[LSP]",
                buffer = "[Buffer]",
                luasnip = "[LuaSnip]",
                nvim_lua = "[Lua]",
                latex_symbols = "[Latex]",
                -- https://github.com/andersevenrud/compe-tmux/issues/6
                tmux = "[tmux]"
            })[entry.source.name]
            return vim_item
        end

    }
})

-- up and down over long lines
-- used for long line traversing
-- normal mode
nnoremap { "<Up>", "gk" }
nnoremap { "<Down>", "gj" }

-- insert mode
inoremap { "<Down>", "pumvisible() ? \"<Down>\" : \"<C-O>gj\"", expr = true }
inoremap { "<Up>", "pumvisible() ? \"<Up>\" : \"<C-O>gk\"", expr = true }
-- inoremap_expr("<CR>",  "pumvisible() ? \"<c-e><cr>\" : \"<CR>\"")
-- inoremap_expr("<tab>",  "pumvisible() ? \"<Return>\" : \"<tab>\"")

vim.cmd(
    "autocmd FileType TelescopePrompt lua require('cmp').setup.buffer { enabled = false }")

-- color the thumb of the scrollbar of the completion menu
-- vim.cmd('highlight PmenuThumb guibg=#f73e3e gui=bold')
-- vim.cmd("highlight PmenuThumb guibg=#F55138 gui=bold")
vim.cmd[[
    " scrollbar
    highlight PmenuThumb guibg=#e86671 gui=bold

    " menu selection when you use arrows
    hi PmenuSel guibg=#e86671

    " fuzzy match for what you typed
    hi CmpItemAbbrMatchFuzzy guifg=#4695DFa

    " matched item (what you typed until present)
    hi CmpItemAbbrMatch guifg=#e86671

    " [LSP] section
    hi CmpItemMenu guifg=#61afef

    " uncompleted item that may be good for completion
    " hi CmpItemAbbr guifg=#808080
    hi CmpItemAbbr guifg=#9C9C9C
]]

its not much. just some settings for

dont get me wrong. the plugins is working. just not triggered automatically when i type in insert mode.

extra: i dont think there is a plugin that is interfering with cmp, i dont think its possible for this to happen.

alexzanderr commented 3 years ago

a little demo to see better whats happening

https://user-images.githubusercontent.com/54772464/136614900-f28b32c0-95c5-444d-9dbc-e046580d6ebc.mp4

goolord commented 3 years ago

the completion menu appears automatically for me, so this may be a configuration problem or plugin interaction. maybe try to get a minimal reproducible example vimrc

alexzanderr commented 3 years ago

yea... i have 100 plugins. do you have any idea what could cause it? just for reference to look into.

gegoune commented 3 years ago

Use binary system to figure it out. Disable 50% of your plugins and see if issue persists. Then keep narrowing it down the same way until you find the culprit.

I don't think anyone else reported that issue yet so it might be some more 'exotic' plugin interacting here. Or your configuration.

alexzanderr commented 3 years ago

sure. im gonna check

rafamadriz commented 3 years ago

Hey @alexzanderr I was having the same issue and just found out the problem, it's because of this option on the setup:

        completion = {
            autocomplete = true,
        }

Now it doesn't work if you just pass true, comment that out the leave the default value and you're gonna see that the autocomplete works (at least it did for me).

alexzanderr commented 3 years ago

omg @rafamadriz, you are my hero.

alexzanderr commented 3 years ago

@hrsh7th, please fix this option with autocomplete = true, commenting it will fix the issue.

wookayin commented 3 years ago

@alexzanderr The default option for completion.autocomplete is TextChanged and it is not expected to take Boolean value, so you can safely remove that option.

See this line: https://github.com/hrsh7th/nvim-cmp/blob/main/lua/cmp/core.lua#L171

The documentation sounds a little bit misleading actually; though I think having a sanity check might be good to have to make it even more fool-proof :)

alexzanderr commented 3 years ago

so you can safely remove that option.

i saw that after removing it.

okey. thanks for info.