quangnguyen30192 / cmp-nvim-ultisnips

nvim-cmp source for ultisnips
Apache License 2.0
144 stars 19 forks source link

Expand Snippet shows on the command line #70

Open medwatt opened 2 years ago

medwatt commented 2 years ago

I came across this which is basically the same question as this one. Unfortunately, it seems that the issue still exists. Have a look at the video recording below.


local p1, cmp = pcall(require, "cmp")
local p2, cmp_ultisnips_mappings = pcall(require, "cmp_nvim_ultisnips.mappings")

cmp.setup({

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

    sources = {
        { name = "ultisnips" },
        { name = "nvim_lua" },
        { name = "nvim_lsp" },
        { name = "buffer", keyword_length = 5},
        { name = "path" },
    },

    mapping = {
        ['<CR>'] = cmp.mapping.confirm({ select = true }),

        ["<Tab>"] = cmp.mapping(
            function(fallback) cmp_ultisnips_mappings.expand_or_jump_forwards(fallback) end,
            {"i", "s"}),

        ["<S-Tab>"] = cmp.mapping(
          function(fallback) cmp_ultisnips_mappings.jump_backwards(fallback) end,
            {"i", "s"}),
    },

})

https://user-images.githubusercontent.com/17733465/158045172-f8380d7f-3a6d-4eee-b0e3-38364cf78343.mp4

smjonas commented 2 years ago

Thanks for the report, could you share the definition for the frac snippet? If you are already at the last tabstop when pressing Tab, I don't think that this can be fixed since it then calls fallback() which is handled by nvim-cmp.

medwatt commented 2 years ago

Thanks for the report, could you share the definition for the frac snippet? If you are already at the last tabstop when pressing Tab, I don't think that this can be fixed since it then calls fallback() which is handled by nvim-cmp.

context "math()"
snippet // "Fraction" iA
\\frac{$1}{$2}$0
endsnippet
jasonkena commented 2 years ago

@medwatt how did you manage to get the snippet to auto-expand with context "math()"? Adding the context is preventing me from expanding the snippet.

smjonas commented 2 years ago

@jasonkena Until now, custom context snippets were not handled correctly. Now that I had time to add proper support for them, could you quickly test this feature? That would be awesome, I want to be sure I didn't break things! :) They should now only be shown when the custom context function returns True. Here is the PR: #72 (you can use my fork https://github.com/smjonas/cmp-nvim-ultisnips on the custom_context_snippets branch.

jasonkena commented 2 years ago

@smjonas unfortunately, it does not seem to work. On the main branch, I can at least see the snippet in the menu (still being unable to expand it), but using your fork, I can't. Any ideas?

smjonas commented 2 years ago

Yeah sorry, this was a bit of a rushed attempt to implement this... I did test this with 2 custom snippets only and it seemed to work. I'll work on the feature when I have time. Thanks for testing though!