hrsh7th / cmp-vsnip

nvim-cmp source for vim-vsnip
MIT License
90 stars 4 forks source link

Duplicate expansion #7

Closed hinell closed 1 year ago

hinell commented 1 year ago

https://user-images.githubusercontent.com/8136158/215357577-b24fbfae-6f15-4062-980b-5600c9495515.mp4

Having a weird duplicate expansion. Tab keys aren't working for jumps.

--Approximate config
-- plugins-snippets.lua

local cmp = require("cmp")
cmp.setup({

["<CR>"] = cmp.mapping.confirm({ select = true }),
["<C-S-j>"] = cmp.mapping(function(fallback)
    if vim.fn["vsnip#jumpable"](1) == 1 then
         feedkey("<Plug>(vsnip-jump-next")
    else
        fallback()
    end
end, {  "s" }),
["<Tab>"] = cmp.mapping(function(fallback)
 --  elseif vim.fn["vsnip#available"](1) == 1 then
    if vim.fn["vsnip#jumpable"](1) == 1 then
         feedkey("<Plug>(vsnip-jump-next", "")
    elseif cmp.visible() then
        cmp.select_next_item()
    elseif has_words_before() then
        cmp.complete()
    else
      --The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
        fallback()
     end
end, { "i", "s" }),

["<S-Tab>"] = cmp.mapping(function()
  if vim.fn["vsnip#jumpable"](-1) == 1 then
      feedkey("<Plug>(vsnip-jump-prev)", "")
  elseif cmp.visible() then
      cmp.select_prev_item()
  end
end, { "i", "s" }),

...
end -- setup end
Snippet:
    "workspace doc open": {
        "prefix": "doc.open.content",
        "body": [
            "workspace.openTextDocument({",
            "    content : ${1:\"File content\"},",
            "    language: \"${2|javascript,typescript,texmate.snippet|}\"",
            "});"
        ],
        "description": "Open vs code workspace document"
    }

Version

hinell commented 1 year ago

Closing this issue, cause the original problem may come from two consequent calls like:

...
cmp.confirm()
luasnip.expand()

Watch out your version!

hinell commented 1 year ago

See also related discussion https://github.com/hrsh7th/nvim-cmp/discussions/1447