Giter Site home page Giter Site logo

nvim-cmp's Introduction

nvim-cmp

A completion engine plugin for neovim written in Lua. Completion sources are installed from external repositories and "sourced".

demo.mp4

Readme!

  1. There is a GitHub issue that documents breaking changes for nvim-cmp. Subscribe to the issue to be notified of upcoming breaking changes.
  2. This is my hobby project. You can support me via GitHub sponsors.
  3. Bug reports are welcome, but don't expect a fix unless you provide minimal configuration and steps to reproduce your issue.
  4. The cmp.mapping.preset.* is pre-defined configuration that aims to mimic neovim's native like behavior. It can be changed without announcement. Please manage key-mapping by yourself.

Concept

  • Full support for LSP completion related capabilities
  • Powerful customizability via Lua functions
  • Smart handling of key mappings
  • No flicker

Setup

Recommended Configuration

This example configuration uses vim-plug as the plugin manager and vim-vsnip as a snippet plugin.

call plug#begin(s:plug_dir)
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'

" For vsnip users.
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'

" For luasnip users.
" Plug 'L3MON4D3/LuaSnip'
" Plug 'saadparwaiz1/cmp_luasnip'

" For ultisnips users.
" Plug 'SirVer/ultisnips'
" Plug 'quangnguyen30192/cmp-nvim-ultisnips'

" For snippy users.
" Plug 'dcampos/nvim-snippy'
" Plug 'dcampos/cmp-snippy'

call plug#end()

lua <<EOF
  -- Set up nvim-cmp.
  local cmp = require'cmp'

  cmp.setup({
    snippet = {
      -- REQUIRED - you must specify a snippet engine
      expand = function(args)
        vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
        -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
        -- require('snippy').expand_snippet(args.body) -- For `snippy` users.
        -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
        -- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+)
      end,
    },
    window = {
      -- completion = cmp.config.window.bordered(),
      -- documentation = cmp.config.window.bordered(),
    },
    mapping = cmp.mapping.preset.insert({
      ['<C-b>'] = cmp.mapping.scroll_docs(-4),
      ['<C-f>'] = cmp.mapping.scroll_docs(4),
      ['<C-Space>'] = cmp.mapping.complete(),
      ['<C-e>'] = cmp.mapping.abort(),
      ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
    }),
    sources = cmp.config.sources({
      { name = 'nvim_lsp' },
      { name = 'vsnip' }, -- For vsnip users.
      -- { name = 'luasnip' }, -- For luasnip users.
      -- { name = 'ultisnips' }, -- For ultisnips users.
      -- { name = 'snippy' }, -- For snippy users.
    }, {
      { name = 'buffer' },
    })
  })

  -- To use git you need to install the plugin petertriho/cmp-git and uncomment lines below
  -- Set configuration for specific filetype.
  --[[ cmp.setup.filetype('gitcommit', {
    sources = cmp.config.sources({
      { name = 'git' },
    }, {
      { name = 'buffer' },
    })
 })
 require("cmp_git").setup() ]]-- 

  -- 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' }
    }
  })

  -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
  cmp.setup.cmdline(':', {
    mapping = cmp.mapping.preset.cmdline(),
    sources = cmp.config.sources({
      { name = 'path' }
    }, {
      { name = 'cmdline' }
    }),
    matching = { disallow_symbol_nonprefix_matching = false }
  })

  -- Set up lspconfig.
  local capabilities = require('cmp_nvim_lsp').default_capabilities()
  -- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
  require('lspconfig')['<YOUR_LSP_SERVER>'].setup {
    capabilities = capabilities
  }
EOF

Where can I find more completion sources?

Have a look at the Wiki and the nvim-cmp GitHub topic.

Where can I find advanced configuration examples?

See the Wiki.

nvim-cmp's People

Contributors

abzcoding avatar amarakon avatar dmitmel avatar f3fora avatar figsoda avatar folke avatar hexium310 avatar hrsh7th avatar iron-e avatar joebb97 avatar kjuq avatar kulabun avatar lewis6991 avatar lvimuser avatar lyude avatar mariasolos avatar mcauley-penney avatar plankcipher avatar smjonas avatar stnley avatar stvhuang avatar terrortylor avatar theory-of-everything avatar tmillr avatar tomtomjhj avatar tummetott avatar tzachar avatar uga-rosa avatar wookayin avatar yuys13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nvim-cmp's Issues

Disable in buftype prompt

nvim-cmp is enabled even if buftype is prompt. For example when searching in telescope. It would be great if it would be turned off in buftype prompt like with nvim-compe.

Awesome work btw!

Can't trigger lsp completion automatically with sumneko/lua-language-server

Issue Description

Hi, I noticed that nvim-cmp has behavor like this:
image
when I input "key" in cursor, only Text completion pop-up and if I enter <C-space> to invoke cmp-complete that will pop-up complete entries like this:
image
If I delete "key" and input again that behavior sometimes normal and sometimes abnormal.

Person config

My personal nvim config about cmp.

Reproduce code:

Days = {
  "Sunday",
  "Monday",
  "TuesDay",
  "WednesDay",
  "ThursDay",
  "FriDay",
  "SaturDay",
}

for key, value in pairs(Days) do
  print(value .. " " .. key)
end

Please clarify buffer source configuration

The README mentions:

" Setup buffer configuration
autocmd FileType markdown lua require'cmp'.setup.buffer {
\   sources = {
\     { name = 'buffer' },
\   },
\ }

I guess this means something like "use the buffer source only for Markdown files", but it's not clear. Is that what the code is meant to do? And if we want to do this per-filetype configuration, should we leave out { name = 'buffer' } from the sources in the main call to setup?

<CR> script-mapping causes neovim freeze

If I include the mapping option on nvim, nvim freezes when I press the Return key (to create a new line)

Removing mapping completely from setup allows it to work again.

'set completeopt=menuone,noinsert' not respected

Currently it has to be set with nvim-cmp internally:

completion = {
  completeopt = 'menuone,noinsert',
},

Since completeopt is an option which is already built into vim why not just check for it instead of reinventing it a second time in nvim-cmp?

Error when entering '['

Error executing vim.schedule lua callback: ...kai/.local/share/nvim/plugged/nvim-cmp/lua/cmp/entry.lua:58: index out of range
The line number is off (originally 56) because I'm inserting lines for debugging purposes.

It does not happen with '{' or '('.
I'm not sure of the exact conditions, but I'll post them in a moment.

diff --git a/lua/cmp/entry.lua b/lua/cmp/entry.lua
index 73535c6..24db1be 100644
--- a/lua/cmp/entry.lua
+++ b/lua/cmp/entry.lua
@@ -53,6 +53,8 @@ entry.get_offset = function(self)
     if misc.safe(self.completion_item.textEdit) then
       local range = misc.safe(self.completion_item.textEdit.insert) or misc.safe(self.completion_item.textEdit.range)
       if range then
+        print(self.context.cursor_line)
+        print(range.start.character)
         local c = vim.str_byteindex(self.context.cursor_line, range.start.character) + 1
         for idx = c, self.source_offset do
           if not char.is_white(string.byte(self.context.cursor_line, idx)) then

render1629068252893

Snippets not showing up for lua

Minimal vimrc to reproduce issue

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !isdirectory(s:plug_dir)
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'L3MON4D3/LuaSnip'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'saadparwaiz1/cmp_luasnip'
call plug#end()
PlugInstall | quit


lua <<EOF
local ls = require('luasnip')
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
-- Create Some Snippets
ls.snippets = {
    lua = {
      s({ trig = 'req', dscr = 'Require Module' }, {
      t({ 'local ' }),
      f(function(args)
        local mod = args[1][1]
        return { mod:match('([^.()]+)[()]*$') }
      end, {
        1,
      }),
      t({ " = require('" }),
      i(1),
      t({ "')" }),
      i(0),
      })
    },
    python = {
      s({ trig = 'req', dscr = 'Require Module' }, {
      t({ 'local ' }),
      f(function(args)
        local mod = args[1][1]
        return { mod:match('([^.()]+)[()]*$') }
      end, {
        1,
      }),
      t({ " = require('" }),
      i(1),
      t({ "')" }),
      i(0),
      })
    }
}
local cmp = require'cmp'
cmp.setup {
  -- You should change this example to your chosen snippet engine.
  snippet = {
    expand = function(args)
      require('luasnip').lsp_expand(args.body)
    end
  },

  -- You must set mapping.
  mapping = {
    ['<C-p>'] = cmp.mapping.item.prev(),
    ['<C-n>'] = cmp.mapping.item.next(),
    ['<C-d>'] = cmp.mapping.scroll.up(),
    ['<C-f>'] = cmp.mapping.scroll.down(),
    ['<C-Space>'] = cmp.mapping.complete(),
    ['<C-e>'] = cmp.mapping.close(),
    ['<CR>'] = cmp.mapping.confirm({
      behavior = cmp.ConfirmBehavior.Replace,
      select = true,
    })
  },

  -- You should specify your *installed* sources.
  sources = {
    { name = 'nvim_lsp' },
    { name = 'luasnip' }
  },
}
 require('lspconfig').sumneko_lua.setup({
   cmd = custom_cmd_here,
  on_attach = custom_on_attach_here
})

 require('lspconfig').pyright.setup({
   cmd = custom_cmd_here,
  on_attach = custom_on_attach_here
})

  require('cmp_nvim_lsp').setup {}
EOF

Description

The req snippet doesn't show up for lua. however it shows up for python

Expected Behaviour

req snippet to show up for both lua and python filetypes.

Actual Behaviour

Completion Menu For Python

Screenshot 2021-08-13 at 01 06 31

Completion Menu For Lua

Screenshot 2021-08-13 at 01 05 23

Manually trigger completion menu

I usually prefer manually doing C-Space to bring up completion which could be achieved in nvim-compe by setting autocomplete = false.

Is there such an option in this plugin ? I can't seem to find it by looking at the docs and the code.

`def __init__()` from Python is being completed incorrectly

Not sure if this is the right spot to report this bug, so please tell me if it isn't.

When trying to complete def __init__() the first option completes to def __init__(self) -> None:^@ super().__init__(). I'm guessing the ^@ is supposed to be converted to a newline. I'm using the pyright language server.

Support source priorities

This can be achieved by using the sortText of each completion item, but seems a bit hacky.
I think that supporting a general ranking between sources is more flexible.

redundant candidates from different source.

How should I config to remove the redundant candidates from popmenu, e.g. library from both buffer and lsp, I would like to only keep buffer candidates. Thanks!

Screenshot_2021-08-17_16-24-08

my settings.

lua << EOF
local cmp = require'cmp'
cmp.setup {
  mapping = {
    ['<C-p>'] = cmp.mapping.prev_item(),
    ['<C-n>'] = cmp.mapping.next_item(),
    ['<C-d>'] = cmp.mapping.scroll(-4),
    ['<C-f>'] = cmp.mapping.scroll(4),
    ['<C-Space>'] = cmp.mapping.complete(),
    ['<C-e>'] = cmp.mapping.close(),
    ['<CR>'] = cmp.mapping.confirm({
      behavior = cmp.ConfirmBehavior.Replace,
      select = true,
    })
  },

  sources = {
      { name = 'buffer' },
      { name = 'nvim_lsp' },
      { name = 'path' },
  },

  documentation = false,
}

require('cmp_nvim_lsp').setup {}
EOF

Mapping customization API

Currently, the mapping configuration can be accepted function(core: cmp.Core, fallback: function) but I don't want to export cmp.Core interface.

So we should consider mapping helper interface etc.

customize completion menu with native CompletionItemKind instead of lspkind-nvim

With nvim-compe I could customize the completion-menu-icons by simply defining the lsp-native CompletionItemKind:

require('vim.lsp.protocol').CompletionItemKind = {
    '๏”ซ', -- 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
}

nvim-cmp doesn't recognize it and your README suggests to use lspkind-nvim which itself uses CompletionItemKind in the background. Is it possible to define completion-menu by myself with CompletionItemKind without lspkind-nvim?

vsnip does not work with lsp

How can I get vsnip to work with nvim-cmp-lsp?

plugins:

  use {
    'hrsh7th/nvim-cmp',
    after = 'nvim-lspconfig',
    config = function() require'config/nvim-compe' end,
  }
  use {
    'hrsh7th/cmp-nvim-lsp',
    after = 'nvim-cmp',
    config = function() require('cmp_nvim_lsp').setup {} end,
  }
  use {
    'hrsh7th/vim-vsnip',
    after = 'nvim-cmp',
  }
  use {
    'hrsh7th/vim-vsnip-integ',
    after = 'vim-vsnip',
  }

config:

local cmp = require'cmp'

cmp.setup {
  snippet = {
    expand = function(args)
      vim.fn['vsnip#anonymous'](args.body)
    end
  },
  mapping = {
    ['<C-p>'] = cmp.mapping.prev_item(),
    ['<C-n>'] = cmp.mapping.next_item(),
    ['<C-d>'] = cmp.mapping.scroll(-4),
    ['<C-f>'] = cmp.mapping.scroll(4),
    ['<C-Space>'] = cmp.mapping.complete(),
    ['<C-e>'] = cmp.mapping.close(),
    ['<C-y>'] = cmp.mapping.confirm({
      behavior = cmp.ConfirmBehavior.Replace,
      select = true,
    })
  },
  sources = {
    { name = 'nvim_lsp' }
  },
}

~/.vsnip/global.json:

{
  "diso": {
    "prefix": "diso",
    "body": ["${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}T${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}"],
    "description": "ISO date time stamp"
  }
}

results in a json file:
image

Can't disable preselect

nvim-compe has option to disable preselect for all completion items.
But it seems that It's always preselected.

preselect false with gopls

I recently started learning go, and it was annoying that it preselected the first completion. I found a fix for this with compe, but can't seem to find a similar setting in this plugin. Is there anything like this available? And if not, is it possible to add this?

See this for reference: hrsh7th/nvim-compe#52

Integration with steelsojka/pears.nvim

Hey @hrsh7th, hope you are doing well!

How should I go about mapping enter to work with cmp and pears? For compe I had:

require('pears').setup(function(conf)                                          
  -- Integrate with compe.                                                     
  conf.on_enter(function(pears_on_enter)                                       
    if vim.fn.pumvisible() == 1 and vim.fn.complete_info().selected ~= -1 then 
      return vim.fn['compe#confirm'] '<CR>'                                    
    else                                                                       
      pears_on_enter()                                                         
    end                                                                        
  end)                                                                         
                                                                               
  conf.pair('<', nil)                                                          
end)                                                                           

Now, with cmp I also have that CR mapping:

['<CR>'] = cmp.mapping.confirm {
  behavior = cmp.ConfirmBehavior.Replace,
  select = true,
},

:imap <CR> returns

i  <CR>        *@v:lua.cmp.utils.keymap.expr("i", "<CR>")

So I assume cmp gets loaded after cmp and overrides the mapping. How to marry the two together?

Thanks!

Using tab to indent with check_backspace hangs neovim

If I use the following setup, and I use <Shift-I><Tab> on any line with text, neovim hangs:

function T(str)
  return vim.api.nvim_replace_termcodes(str, true, true, true)
end

cmp.setup({

  snippet = {
    expand = function(args)
      return require("luasnip").lsp_expand(args.body)
    end,
  },

  completion = {
    completeopt = "menu,menuone,noinsert",
  },

  mapping = {
    ["<C-p>"] = cmp.mapping.select_prev_item(),
    ["<C-n>"] = cmp.mapping.select_next_item(),
    ["<C-d>"] = cmp.mapping.scroll_docs(-4),
    ["<C-f>"] = cmp.mapping.scroll_docs(4),
    ["<C-Space>"] = cmp.mapping.complete(),
    ["<C-e>"] = cmp.mapping.close(),
    ["<ESC>"] = cmp.mapping.close(),
    ["<CR>"] = cmp.mapping.confirm({
      behavior = cmp.ConfirmBehavior.Replace,
      select = true,
    }),
    ["<Tab>"] = function(fallback)
      if vim.fn.pumvisible() == 1 then
        vim.fn.feedkeys(T("<C-n>"), "n")
      elseif check_backspace() then
        return vim.fn.feedkeys(T("<Tab>"))
      elseif luasnip.expand_or_jumpable() then
        vim.fn.feedkeys(T("<Plug>luasnip-expand-or-jump"), "")
      else
        fallback()
      end
    end,
    ["<S-Tab>"] = function(_, fallback)
      if vim.fn.pumvisible() == 1 then
        vim.fn.feedkeys(T("<C-p>"), "n")
      elseif luasnip.jumpable(-1) then
        vim.fn.feedkeys(T("<Plug>luasnip-jump-prev"), "")
      else
        fallback()
      end
    end,
  },
  sources = {
    { name = "buffer" },
  },
})

If I comment the following lines, then it does not hang:

      elseif check_backspace() then
        return vim.fn.feedkeys(T("<Tab>"))

However, I'm no longer able to use <Tab> to indent in insert mode.

How to use with nvim-autopairs ?

This mapping stopped working on c2f8729.

local npairs = require('nvim-autopairs')
npairs.setup {}
_G.cmp_npairs_cr = function ()
  if vim.fn.pumvisible() == 1 then
    return cmp.utils.keymap.expr('<cr>')
  else
    return npairs.autopairs_cr()
  end
end

vim.api.nvim_set_keymap("i", "<cr>", "v:lua.cmp_npairs_cr()", {expr = true, noremap = true})

Plans on making it faster than coq.nvim?

Hello, I was just wondering if they were perhaps planning to make this plugin faster than nvim-compe and coq.nvim. Like recently, for example, Telescope pushed a feature for asynchronous matching which greatly improved the speed.

Also, I see that there is source creation, any plans on making sort creation too?

Snippet completion triggered without prefix

Working on migration from nvim-compe to here, and I have this issue, where snippet completions got triggered even when I haven't type anything yet.

Actual Behavior

  • Snippet completions got triggered without any prefix

  • Example in typescript
    image

  • Example in ruby
    image

Expected Behavior

  • I am expecting that snippets completion should only be triggered if I type in the prefix.

Config

local cmp = require 'cmp'
cmp.setup {
  completion = {
    completeopt = 'menu,menuone,noinsert'
  },
  snippet = {
    expand = function(args)
        vim.fn['vsnip#anonymous'](args.body)
    end
  },
  mapping = {
    ['<C-p>'] = cmp.mapping.prev_item(),
    ['<C-n>'] = cmp.mapping.next_item(),
    ['<C-d>'] = cmp.mapping.scroll(-4),
    ['<C-f>'] = cmp.mapping.scroll(4),
    ['<C-Space>'] = cmp.mapping.complete(),
    ['<C-e>'] = cmp.mapping.close(),
    ['<CR>'] = cmp.mapping.confirm {
      behavior = cmp.ConfirmBehavior.Replace,
      select = true,
    },
    ['<Tab>'] = cmp.mapping.mode({ 'i', 's' }, function(_, fallback)
      if vim.fn.pumvisible() == 1 then
        vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n')
      else
        fallback()
      end
    end),
    ['<S-Tab>'] = cmp.mapping.mode({ 'i', 's' }, function(_, fallback)
      if vim.fn.pumvisible() == 1 then
        vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-p>', true, true, true), 'n')
      else
        fallback()
      end
    end),
  },
  sources = {
    { name = 'nvim_lsp' },
    { name = 'vsnip' },
  },
}

Use tab together with luasnip

With compe I had {s-,}tab mapped as such

local check_back_space = function()
  local col = vim.fn.col '.' - 1
  return col == 0 or vim.fn.getline('.'):sub(col, col):match '%s' ~= nil
end

_G.tab_complete = function()
  if vim.fn.pumvisible() == 1 then
    return t '<C-n>'
  elseif luasnip.expand_or_jumpable() then
    return t '<Plug>luasnip-expand-or-jump'
  elseif check_back_space() then
    return t '<Tab>'
  else
    return vim.fn['compe#complete']()
  end
end

_G.s_tab_complete = function()
  if vim.fn.pumvisible() == 1 then
    return t '<C-p>'
  elseif luasnip.jumpable(-1) then
    return t '<Plug>luasnip-jump-prev'
  else
    return t '<S-Tab>'
  end
end

map({ 'i', 's' }, '<Tab>', 'v:lua.tab_complete()', { expr = true, noremap = false })
map({ 'i', 's' }, '<S-Tab>', 'v:lua.s_tab_complete()', { expr = true, noremap = false })

so depending if pum was visible it would jump between placeholders or navigate menu.

How can I replicate it with cmp, currently having:

  mapping = {
    ['<S-Tab>'] = cmp.mapping.prev_item(),
    ['<Tab>'] = cmp.mapping.next_item(),
}

?

Thanks!

Core isn't exposed for the new mapping API

Hey, I am having trouble converting my cmp config to the new mapping API.

Before the new mapping API, I was able to do the following.

...
  ["<C-Space>"] = cmp.mapping.mode({ "i" }, function(core, fallback)
    local types = require("cmp.types")
    if fn.pumvisible() == 1 then
      core.reset()
    else
      core.complete(core.get_context({ reason = types.cmp.ContextReason.Manual }))
    end
  end),
...

Now fallback is the first argument, so I assumed core would be the second, but I guess its not exposed no longer, because the following code fails.

...
  ["<C-Space>"] = function(fallback, core)
    local types = require("cmp.types")
    if fn.pumvisible() == 1 then
      core.reset()
    else
      core.complete(core.get_context({ reason = types.cmp.ContextReason.Manual }))
    end
  end,
...

The candidate display is wrong.

The source is nvim_lsp (sumneko_lua).

image

image

If I return to normal mode with esc from the first picture, the display will remain like this.

image

I am using lspkind, but this is not relevant.

0x0 when use `complete`

I don't know why, but every time I try to force the completion (<c-space>), it inserts 0x0. Do you know what I'm doing wrong?

My mappings:

local cmp = require'cmp'

cmp.setup {
  snippet = {
    expand = function(args)
      -- You must install `vim-vsnip` if you set up as same as the following.
      vim.fn['vsnip#anonymous'](args.body)
    end
  },
  mapping = {
    ['<C-p>'] = cmp.mapping.prev_item(),
    ['<C-n>'] = cmp.mapping.next_item(),
    ['<C-Space>'] = cmp.mapping.complete(),
    ['<C-e>'] = cmp.mapping.close(),
    ['<C-y>'] = cmp.mapping.confirm({
      behavior = cmp.ConfirmBehavior.Replace,
      select = true,
    })
  },
  sources = {
    { name = 'nvim_lsp' },
    { name = 'vsnip' }
  },
}

Completions replace improper words

Description

In some cases when I complete one of the completions, it replaces the text that follows.

Expected behavior

The text that follows (i.e. after the cursor caret) remains untouched.

Actual behavior

The text that follows (i.e. after the cursor caret) is removed.

Example

Checkout on the video below how do_something completion replaced A, while my intention was to simply wrap A (i.e. pass it to do_something).

asciicast

def do_something(value):
    return value

A = "A"

if "foo" == A:
    pass

Config

         cmp.setup({
            completion = {
               completeopt = vim.o.completeopt,
            },

            snippet = {
               expand = function(args)
                  vim.fn["vsnip#anonymous"](args.body)
               end
            },

            mapping = {
               ["<C-p>"] = cmp.mapping.prev_item(),
               ["<C-n>"] = cmp.mapping.next_item(),
               ["<C-d>"] = cmp.mapping.scroll(-4),
               ["<C-f>"] = cmp.mapping.scroll(4),
               ["<C-Space>"] = cmp.mapping.complete(),
               ["<C-e>"] = cmp.mapping.close(),
               ["<CR>"] = cmp.mapping.confirm({
                  behavior = cmp.ConfirmBehavior.Replace,
                  select = true,
               })
            },

            formatting = {
               format = function(entry, vim_item)
                  vim_item.kind = string.format("%s %s", LSP_KIND_SIGNS[vim_item.kind], vim_item.kind)
                  return vim_item
               end
            },

            sources = {
               { name = "nvim_lsp" },
               { name = "buffer" },
               { name = "path" },
            },
         })

Language servers

Tried the following:

  • pyright 1.1.162
  • pylsp v1.2.1

How to disable documentation-window?

Hi. Is it possible to disable the documentation-window from being displayed all the time? I like to open it manually when I need it. With compe I could do so by setting documentation = false;
I tried documentation = { }, in cmp but it didn't work. Thank you.

Autocomplete not working with code in Rust Docs

Awesome work on the plugin, works almost perfectly for me,
Just one problem though, I don't get autocomplete in Rust docs, works outside of it though.

I'm using the default capabilities provided here

Something else I need to check?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.