hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
8.05k stars 399 forks source link

Error detected while processing TextChangedI Autocommands for "*" #1310

Closed LamprosPitsillos closed 1 year ago

LamprosPitsillos commented 1 year ago

FAQ

Announcement

Minimal reproducible full config

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 !filereadable(s:plug_dir .. '/plug.vim')
  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 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'neovim/nvim-lspconfig'
Plug 'onsails/lspkind-nvim',
call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
  snippet = {
  },

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

  sources = cmp.config.sources({
    { name = "nvim_lsp" },
    { name = "buffer" },
  }),
}
EOF

lua << EOF
local cmp = require("cmp")
local lspkind = require("lspkind")
---@diagnostic disable-next-line: redundant-parameter
cmp.setup({
    snippet = {
    },
    formatting = {
        -- Youtube: How to set up nice formatting for your sources.
        format = lspkind.cmp_format({
            mode = "symbol_text",
            maxwidth = 60
        }),
    },
    window = {
        completion = cmp.config.window.bordered(),
        documentation = cmp.config.window.bordered(),
    },
    mapping = {
        ["<C-b>"] = 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-e>"] = cmp.mapping.abort(),
        ["<CR>"] = cmp.mapping.confirm({ select = true }),

        ["<C-j>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
        ["<C-k>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
    },
    sources = cmp.config.sources({
        { name = "nvim_lsp" },
        -- { name = "luasnip" }, -- For luasnip users.
        -- { name = "treesitter" },
        { name = "path", max_item_count = 10 },
        { name = "cmdline", max_item_count = 10 },
        -- { name = "neorg" },
        -- { name = "zsh" },
    }, {
        { name = "buffer" },
    }),
})

  --[[ -- 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({ "/", "?" }, {
    completion = {
        autocomplete = true,
    },
    mapping = cmp.mapping.preset.cmdline({

        ["<C-j>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
        ["<C-k>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
        ["<CR>"] = cmp.mapping.confirm({ select = true }),
    }),
    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({

        ["<C-j>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
        ["<C-k>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
        ["<CR>"] = cmp.mapping.confirm({ select = true }),
    }),
    sources = cmp.config.sources({
        { name = "path" },
    }, {
        { name = "cmdline" },
    }),
})

local capabilities = require('cmp_nvim_lsp').default_capabilities()

require'lspconfig'.clangd.setup {
  capabilities = capabilities,
}
EOF

Description

I get TextChangedI Autocommands for "*" error while typing

Steps to reproduce

Use above config and follow the video snippets provided below.

Expected behavior

No error to happen at all

Actual behavior

On a MD file

In this case i get this error

Error detected while processing TextChangedI Autocommands for "*":                                       
E20: Mark not set

https://user-images.githubusercontent.com/61395246/202475604-2b7b32a8-059f-4cff-8c7f-431298a06011.mp4

On a CPP file

In this case i get this

Error detected while processing TextChangedI Autocommands for "*":                                       
E481: No range allowed    

https://user-images.githubusercontent.com/61395246/202475630-ede0ffe4-f896-4f11-b241-f8164e1d6bae.mp4

Additional context

NVIM v0.9.0-dev-288+g69507c020
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by inferno@InfernoPC

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

OS: Artix Linux x86_64

ghost commented 1 year ago

I got the same error when I was trying insert some text inside string that is a property or a value of a JavaScript object literal. In my case, it shows 'E20: Mark not set' or 'E16: Invalid range'. If this is a bug, hope it fixed soon.

benbrastmckie commented 1 year ago

Yeah, me too trying to write LaTeX with the Lua config I've been working on. I notice that it mostly gives errors when I try to start lines with \ which happens all the time in LaTeX. Hope its an easy fix.

wookayin commented 1 year ago

Trying to reproduce the error but with the provided minimal config I don't run into the error. In your video definitely a different, full user config is being used.

To make a guess, this bug is happening because the completion item is executed literally as a vim command. Try :\usepackage in vim cmdline and you'll get an E10 error. Not sure which line of the nvim-cmp is calling vim.cmd wrongly. Can anybody provide a fully reproducible config?

LamprosPitsillos commented 1 year ago

Trying to reproduce the error but with the provided minimal config I don't run into the error. In your video definitely a different, full user config is being used.

To make a guess, this bug is happening because the completion item is executed literally as a vim command. Try :\usepackage in vim cmdline and you'll get an E10 error. Not sure which line of the nvim-cmp is calling vim.cmd wrongly. Can anybody provide a fully reproducible config?

Strange, I really did use the minimal config for the second clip, maybe it has to do with any caching from my normal neovim ? How can i rerun the tests cleanly,so that i can be sure the min config produces the issue?

bchopson commented 1 year ago

I can reproduce this error by enabling the cmp-cmdline source.

hrsh7th commented 1 year ago

Please remove cmp-cmdline from global sources and add cmp-cmdline for the cmdline setup function.

LamprosPitsillos commented 1 year ago

Please remove cmp-cmdline from global sources and add cmp-cmdline for the cmdline setup function.

This solved it for me ,thanks again for your hard work!

lucianchauvin commented 3 months ago

Please remove cmp-cmdline from global sources and add cmp-cmdline for the cmdline setup function.

What does this mean exactly? I've removed cmp-cmdline from my plugins yet I am still having this issue on NVIM v0.10.1.

Specifically, opening a .tex file an typing \ causes this:

Error detected while processing TextChangedI Autocommands for "*"..function UltiSnips#TrackChange[1]..provider#python3#Call:
line    1:
E5108: Error executing lua Vim:<global-snippets>:60: SyntaxWarning: invalid escape sequence '\h'
stack traceback:
        [C]: at 0x5baf91587200

Any help would be greatly appreciated. Thanks!

Shougo commented 3 months ago

Hm... It seems UltiSnips error instead of nvim-cmp.

lucianchauvin commented 3 months ago

Yeah not really sure if this is an Ultisnips or nvim-cmp issue but it seems very similar to this.

Shougo commented 3 months ago

The error is not reproduced when nvim-cmp is disabled?

lucianchauvin commented 3 months ago

The error is not reproduced when nvim-cmp is disabled?

No, it is not. I will go bark up someone else's tree.