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

Adding cmp-path breaks completion #38

Open
nimeco opened this issue Mar 16, 2022 · 0 comments
Open

Adding cmp-path breaks completion #38

nimeco opened this issue Mar 16, 2022 · 0 comments

Comments

@nimeco
Copy link

nimeco commented Mar 16, 2022

Greetings,
I noticed that pressing <Tab> on the Cmdline mode stopped working, even though wildmenu was set to on.
I thought the mappings were the culprit and using :verbose map <Tab> only showed:

s  <Tab>       * <Cmd>call v:lua.cmp.utils.keymap.set_map(11)<CR>
        Last set from Lua

Tried locating where v:lua.cmp.utils.keymap.set_map was being set and it turns out to be in nvim-cmp\lua\cmp\utils\keymap.lua, line 228 here.
Added a print to see what was being set (is there a better way to debug those?) and the outcome was:

mode:i lhs:<Up> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(1)<CR>
mode:c lhs:<Up> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(2)<CR>
mode:i lhs:<C-E> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(3)<CR>
mode:c lhs:<C-E> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(4)<CR>
mode:c lhs:<S-Tab> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(5)<CR>
mode:i lhs:<C-P> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(6)<CR>
mode:c lhs:<C-P> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(7)<CR>
mode:i lhs:<C-N> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(8)<CR>
mode:c lhs:<C-N> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(9)<CR>
mode:i lhs:<CR> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(10)<CR>
mode:s lhs:<Tab> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(11)<CR>
mode:i lhs:<Tab> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(12)<CR>
mode:c lhs:<Tab> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(13)<CR>
mode:i lhs:<C-Space> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(14)<CR>
mode:c lhs:<C-Space> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(15)<CR>
mode:i lhs:<C-F> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(16)<CR>
mode:c lhs:<C-F> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(17)<CR>
mode:i lhs:<Down> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(18)<CR>
mode:c lhs:<Down> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(19)<CR>
mode:i lhs:<C-D> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(20)<CR>
mode:c lhs:<C-D> rhs:<Cmd>call v:lua.cmp.utils.keymap.set_map(21)<CR>

So, <Tab> is being set to something in Cmdline mode, even though :verbose map <Tab> didn't show it. (Why's that?)
I don't really know if the above has any relation with the issue.

So I went for the minimum config and found out that, when adding nvim-cmp with cmp-path, the issue would happen.
<Tab> is set in config-cmp.lua but it seems it's not respecting that config.

Also, opening Neovim without doing anything, since it lazy loads the plugin because of event being set(? I suppose, new at packer), if I enter the Cmdline mode, autocompletion works. After going into Insert mode and triggering it an event, autocomplete breaks.
Disabling cmp-path makes Cmdline autocomplete work back again.

  • Vim type (vim/gvim/neovim): Neovim
  • Vim version: v0.7.0-dev+1201-g5760cf87b
  • OS: Windows

Thanks a lot!

init.lua:

require"plugins"

plugins.lua:

local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'

if fn.empty(fn.glob(install_path)) > 0 then
    packer_boostrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
end

vim.cmd [[
augroup packer_user_config
autocmd!
autocmd BufWritePost */nvim/lua/plugins.lua source <afile> | PackerSync
augroup end
]]

local status_ok, packer = pcall(require, "packer")
if not status_ok then
    return
end

packer.init {
    display = {
        open_fn = function()
            return require('packer.util').float { border = "rounded" }
        end,
    },
}

return packer.startup(function(use)
    use { "wbthomason/packer.nvim" }
    use { "hrsh7th/nvim-cmp", config = "require('config-cmp')", event = {'BufRead', 'BufNewFile', 'InsertEnter'}}
    use { "hrsh7th/cmp-path", after = "nvim-cmp" }

    if packer_boostrap then
        require('packer').sync()
    end
end)

config-cmp.lua:

local cmp = require'cmp'
local luasnip = require"luasnip"

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 = '  ',
}

local has_words_before = function()
    local line, col = unpack(vim.api.nvim_win_get_cursor(0))
    return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end

cmp.setup({
    mapping = {
        ['<C-d>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
        ['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
        ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
        ['<C-y>'] = cmp.config.disable, -- If you want to remove the default `<C-y>` mapping, You can specify `cmp.config.disable` value.
        ['<C-e>'] = cmp.mapping({
            i = cmp.mapping.abort(),
            c = cmp.mapping.close(),
        }),
        ['<CR>'] = cmp.mapping.confirm({
            behavior = cmp.ConfirmBehavior.Insert,
            select = false
        }),
        ["<Tab>"] = cmp.mapping(function(fallback)
            if cmp.visible() then
                cmp.select_next_item()
            elseif has_words_before() then
                cmp.complete()
            else
                fallback()
            end
        end, { "i", "s" }),
    },
    sources = cmp.config.sources({
        { name = 'luasnip' }, -- For luasnip users.
    },
    {
        { name = 'buffer' },
        }),
    formatting = {
        fields = {"kind", "abbr", "menu"},
        format = function(entry, vim_item)
            vim_item.kind = string.format('%s %s', cmp_kinds[vim_item.kind] or "", vim_item.kind)
            vim_item.menu = ({
                nvim_lsp = "[LSP]",
                nvim_lua = "[Lua]",
                luasnip = "[LuaSnip]",
                buffer = "[Buffer]",
            })[entry.source.name]
            return vim_item
        end,
    },
    experimental = {
        ghost_text = true,
    },
})

-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
    sources = cmp.config.sources({
    { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
    }, {
        { name = 'buffer' },
        })
})

-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
    sources = {
    { name = 'buffer' }
    }
})

-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
    sources = cmp.config.sources({
    { name = 'path' }
    }, {
        { name = 'cmdline' }
        })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant