Giter Site home page Giter Site logo

Comments (9)

medwatt avatar medwatt commented on August 16, 2024 1

I haven't tested it extensively, but the issue I reported is now gone.

from cmp-nvim-ultisnips.

smjonas avatar smjonas commented on August 16, 2024

Could you share some additional info on how to reproduce this issue? Where did you put that code? What is the exact error message? Which snippet definitions are you using? Possibly relevant: your Neovim version. I added this to my .vimrc (and I can confirm A snippets are not triggered automatically anymore) but I can't reproduce this issue.

from cmp-nvim-ultisnips.

medwatt avatar medwatt commented on August 16, 2024

I am using Neovim version 0.6. The code I provided in the first post is inside the config file I have for ultisnips.

Here's my cmp config:

local present, cmp = pcall(require, "cmp")

local has_any_words_before = function()
    if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
        return false
    end
    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

local press = function(key)
    vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), "n", true)
end

cmp.setup {

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

    completion = {
        completeopt = "menu,menuone,noselect",
        keyword_length = 1,
    },

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

    mapping = {


        ["<C-e>"] = cmp.mapping.close(),
        ["<CR>"] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }),


        ["<C-Space>"] = cmp.mapping(function(fallback)
            if cmp.visible() then
                if vim.fn["UltiSnips#CanExpandSnippet"]() == 1 then
                    return press("<C-R>=UltiSnips#ExpandSnippet()<CR>")
                end

                cmp.select_next_item()
            elseif has_any_words_before() then
                press("<Space>")
            else
                fallback()
            end
        end, {
        "i",
        "s",
    }),

    ["<Tab>"] = cmp.mapping(function(fallback)
        if vim.fn["UltiSnips#CanJumpForwards"]() == 1 then
            press("<ESC>:call UltiSnips#JumpForwards()<CR>")
        elseif cmp.visible() then
            cmp.select_next_item()
        elseif has_any_words_before() then
            press("<Tab>")
        else
            fallback()
        end
    end, {
    "i",
    "s",
}),

["<S-Tab>"] = cmp.mapping(function(fallback)
    if vim.fn["UltiSnips#CanJumpBackwards"]() == 1 then
        press("<ESC>:call UltiSnips#JumpBackwards()<CR>")
    elseif cmp.visible() then
        cmp.select_prev_item()
    else
        fallback()
    end
end, {
"i",
"s",
    }),
},
}

I am using the default configuration for ultisnips. With the autotrigger disabled, when I am insert mode and press any character, I get the following error.

from cmp-nvim-ultisnips.

smjonas avatar smjonas commented on August 16, 2024

Thank you. Possibly a duplicate of #46? Are you using the latest version of this plugin? Also, we have now added recommended mapping functions you can call - see readme (they do the same as your code).

from cmp-nvim-ultisnips.

medwatt avatar medwatt commented on August 16, 2024

I just updated and tried the recommended settings. I'm still getting the same error.

from cmp-nvim-ultisnips.

smjonas avatar smjonas commented on August 16, 2024

Ok this is weird. Just to be 100% sure: everything works correctly when autotrigger is enabled? I will look into it.

from cmp-nvim-ultisnips.

medwatt avatar medwatt commented on August 16, 2024

Have a look at the video to see exactly what is going on. While experimenting, I noticed that if I press the tab key by itself while in insert mode, the problem does not occur

2021-12-09.21-10-09.mp4

.

from cmp-nvim-ultisnips.

smjonas avatar smjonas commented on August 16, 2024

Could you try this PR? #51
I suspect it is some kind of loading order problem, seems like UltiSnips is not available yet when cmp_nvim_ultisnips is ready.
So I tried to source the UltiSnips file as cmp_nvim_ultisnips starts.

from cmp-nvim-ultisnips.

smjonas avatar smjonas commented on August 16, 2024

Wow I'm a bit surprised that it worked, thanks for testing!

from cmp-nvim-ultisnips.

Related Issues (20)

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.