neoclide / coc.nvim

Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Other
24.2k stars 954 forks source link

autocomplete extra characters #4506

Closed Joenhle closed 1 year ago

Joenhle commented 1 year ago

Result from CocInfo

2023-02-06T18:17:56.881 TRACE (pid:4184) [attach] - Notification autocmd: TextChangedI 1 {
  lnum: 19,
  col: 27,
  changedtick: 487,
  line: '\t\t\tfor (int i = 0; i <lv5l count; i++) {'
}
2023-02-06T18:17:56.881 DEBUG (pid:4184) [completion] - trigger completion with {
  input: 'lv5l',
  position: { line: 18, character: 26 },
  line: '\t\t\tfor (int i = 0; i <lv5l count; i++) {',
  followWord: '',
  filetype: 'cpp',
  linenr: 19,
  col: 22,
  colnr: 27,
  bufnr: 1,
  word: 'lv5l',
  changedtick: 487,
  synname: '',
  filepath: '/Users/huangjunhao/leetcode/c++/最长连续序列_/main.cpp',
  triggerCharacter: 'l'
}
2023-02-06T18:17:56.884 INFO (pid:4184) [snippets-session] - Unable to find changed placeholder, cancel snippet session
2023-02-06T18:17:56.885 DEBUG (pid:4184) [snippets-session] - session 1 cancelled
2023-02-06T18:17:56.890 DEBUG (pid:4184) [completion-complete] - Source "file" finished with 0 items ms cost: 0
2023-02-06T18:17:56.891 DEBUG (pid:4184) [completion-complete] - Source "snippets" finished with 8 items ms cost: 1
2023-02-06T18:17:56.891 DEBUG (pid:4184) [completion-complete] - Source "around" finished with 0 items ms cost: 1
2023-02-06T18:17:56.891 DEBUG (pid:4184) [completion-complete] - Source "buffer" finished with 0 items ms cost: 1
2023-02-06T18:17:56.987 DEBUG (pid:4184) [completion-complete] - Source "languageserver.ccls" finished with 0 items ms cost: 97
2023-02-06T18:17:57.598 TRACE (pid:4184) [attach] - Notification autocmd: WinLeave 1003
2023-02-06T18:17:57.598 TRACE (pid:4184) [attach] - Notification autocmd: WinEnter 1135
2023-02-06T18:17:57.600 TRACE (pid:4184) [attach] - Notification autocmd: BufEnter 61
2023-02-06T18:17:57.600 TRACE (pid:4184) [attach] - Notification autocmd: CursorMoved 61 [ 4431, 1 ]

Describe the bug

When I use autocomplete, I sometimes generate extra characters, usually four or five, in the form of lvxxx.

example1 before tab

image

after tab

image

example2 before tab

image

aftertab

image

Reproduce the bug

We will close your issue when you don't provide minimal vimrc and we can't reproduce it

" 设置vimrc修改保存后立刻生效,不用重新打开
autocmd BufWritePost $MYVIMRC source $MYVIMRC

" 退出插入模式指定类型的文件自动保存
au InsertLeave * write
let autosave=0.2
"set updatetime=100

call plug#begin('~/.vim/plugged')

"fzf
Plug 'junegunn/fzf', { 'do': {-> fzf#install()} }
Plug 'junegunn/fzf.vim'
Plug 'airblade/vim-rooter'

"git
Plug 'mhinz/vim-signify'

" vim floaterm terminal
Plug 'voldikss/vim-floaterm'

Plug 'octol/vim-cpp-enhanced-highlight'

" Make sure you use single quotes

" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'

Plug 'rafi/awesome-vim-colorschemes'

" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'

Plug 'majutsushi/tagbar'

" 可以在文档中显示 git 信息
Plug 'airblade/vim-gitgutter'

" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips'

" Snippets are separated from the engine. Add this if you want them:
Plug 'honza/vim-snippets'

" nerdtree
Plug 'preservim/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'ryanoasis/vim-devicons'

Plug 'tpope/vim-fireplace', { 'for': 'clojure' }

" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'branch':'master', 'do': ':GoUpdateBinaries' }

Plug 'neoclide/coc.nvim', {'branch': 'release'}

Plug 'skywind3000/vim-terminal-help'

" 自动引号括号补全
Plug 'jiangmiao/auto-pairs'

" 悬浮终端
Plug 'voldikss/vim-floaterm'
" 代码补全

" 配色方案
" colorscheme neodark
Plug 'KeitaNakamura/neodark.vim'
" colorscheme monokai
Plug 'crusoexia/vim-monokai'
" colorscheme github 
Plug 'acarapetis/vim-colors-github'
" colorscheme one 
Plug 'rakr/vim-one'

" Initialize plugin system
call plug#end()

let g:python3_host_prog='/Users/huangjunhao/.pyenv/versions/3.10.2/bin/python3'

let $NVIM_COC_LOG_LEVEL = 'trace'

"==============================================================================
" 主题配色 
"==============================================================================

" 开启24bit的颜色,开启这个颜色会更漂亮一些
set termguicolors
" 配色方案, 可以从上面插件安装中的选择一个使用 
colorscheme ayu " 主题
set background=dark " 主题背景 dark-深色; light-浅色

"############# 00 插 键 配 置 ##################

" <leader> 按键设置

let mapleader='\'
let g:mapleader='\'

"tab page config
nnoremap gc :tabclose<CR>

"fzf config
nnoremap <Leader>f :Files<CR>
nnoremap <Leader>g :Rg<CR>

"better window navigation
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

"auto-pairs 
"修改括号删除的匹配误差问题
let g:AutoPairsMapBS=0

let g:go_def_mode='gopls'
let g:go_info_mode='gopls'

"vim-cpp-enhanced-highlight
let g:cpp_class_scope_highlight = 1
let g:cpp_member_variable_highlight = 1
let g:cpp_class_decl_highlight = 1
let g:cpp_posix_standard = 1
let g:cpp_experimental_simple_template_highlight = 1

"悬浮终端配置
let g:floaterm_keymap_new    = '<Leader>nt'
let g:floaterm_keymap_toggle = '<Leader>t'
let g:floaterm_borderchars = ['','','','','','','','']

" ultisnips
let g:UltiSnipsExpandTrigger="<tab>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"

"==============================================================================
" vim-go 插件
"==============================================================================
"map <leader>1 :GoRun<CR>
"map 5 :GoDecls<CR>
"map 4 :GoCallers<CR>
"map 3 :GoReferrers<CR>
"map 6 :GoImplements<CR>
"map 1 :GoDef<CR>
map <leader>m :map<CR>

let g:go_fmt_command = "goimports" " 格式化将默认的 gofmt 替换
let g:go_autodetect_gopath = 1
let g:go_list_type = "quickfix"

let g:go_version_warning = 1
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_methods = 1
let g:go_highlight_generate_tags = 1

"==============================================================================
" NERDTree 插件
"==============================================================================

set encoding=UTF-8
set guifont=hack_Nerd_Font:h11

" 打开和关闭NERDTree快捷键
nnoremap <leader>n :NERDTreeFocus<CR>
nnoremap <C-n> :NERDTree<CR>
nnoremap <C-t> :NERDTreeToggle<CR>
" Start NERDTree. If a file is specified, move the cursor to its window.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif

" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif

" 显示行号
let NERDTreeShowLineNumbers=1
" 打开文件时是否显示目录
let NERDTreeAutoCenter=1
" 是否显示隐藏文件
let NERDTreeShowHidden=1
" 设置宽度
" let NERDTreeWinSize=31
" 忽略一下文件的显示
let NERDTreeIgnore=['\.pyc','\~$','\.swp']
" 打开 vim 文件及显示书签列表
let NERDTreeShowBookmarks=2
" 在终端启动vim时,共享NERDTree
let g:nerdtree_tabs_open_on_console_startup=1

"==============================================================================
"  nerdtree-git-plugin 插件
"==============================================================================
let g:NERDTreeIndicatorMapCustom = {
    \ "Modified"  : "✹",
    \ "Staged"    : "✚",
    \ "Untracked" : "✭",
    \ "Renamed"   : "➜",
    \ "Unmerged"  : "═",
    \ "Deleted"   : "✖",
    \ "Dirty"     : "✗",
    \ "Clean"     : "✔︎",
    \ 'Ignored'   : '☒',
    \ "Unknown"   : "?"
    \ }

"==============================================================================
"  majutsushi/tagbar 插件
"==============================================================================
let g:Tlist_Ctags_Cmd='/usr/local/Cellar/ctags/5.8_2/bin/ctags'
" majutsushi/tagbar 插件打开关闭快捷键
map <F3> :TagbarToggle<CR>

let g:tagbar_type_go = {
    \ 'ctagstype' : 'go',
    \ 'kinds'     : [
        \ 'p:package',
        \ 'i:imports:1',
        \ 'c:constants',
        \ 'v:variables',
        \ 't:types',
        \ 'n:interfaces',
        \ 'w:fields',
        \ 'e:embedded',
        \ 'm:methods',
        \ 'r:constructor',
        \ 'f:functions'
    \ ],
    \ 'sro' : '.',
    \ 'kind2scope' : {
        \ 't' : 'ctype',
        \ 'n' : 'ntype'
    \ },
    \ 'scope2kind' : {
        \ 'ctype' : 't',
        \ 'ntype' : 'n'
    \ },
    \ 'ctagsbin'  : 'gotags',
    \ 'ctagsargs' : '-sort -silent'
\ }

let g:airline_theme='Cobalt 2'

"############# 11  Vim 自有配置 ##############

"解决coc提示的时候tap键无法触发的问题
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

"inoremap <silent><expr> <Tab> coc#pum#visible() ? coc#_select_confirm() : "\<Tab>"

inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
\ CheckBackSpace() ? "\<TAB>" :
\ coc#refresh()

function! CheckBackSpace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1]  =~# '\s'
endfunction

let g:coc_snippet_next = '<tab>'

" GoTo code navigation
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
nmap <silent> gf <Plug>(coc-format)

"Use K to show documentation in preview window
nnoremap <silent> K :call ShowDocumentation()<CR>

function! ShowDocumentation()
  if CocAction('hasProvider', 'hover')
    call CocActionAsync('doHover')
  else
    call feedkeys('K', 'in')
  endif
endfunction

"Highlight the symbol and its references when holding the cursor
autocmd CursorHold * silent call CocActionAsync('highlight')

"分屏窗口移动, Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l

map 2 <C-o>

" 命令行模式增强,ctrl - a到行首, -e 到行尾
cnoremap <C-a> <Home>
cnoremap <C-e> <End>

" 去掉搜索高亮
noremap <silent><leader>/ :nohls<CR>

" 快速保存和退出
" Quickly close the current window
nnoremap <leader>q :q<CR>
" Quickly save the current file
nnoremap <leader>w :w<CR>

" 在Visual模式时,按Ctrl+c复制选择的内容
vmap <C-c> "+y

syntax on " 自动语法高亮
set ambiwidth=double " 设置为双字宽显示,否则无法完整显示如:☆
set backspace=2 " 解决 backspace 按键删除的问题 http://cenalulu.github.io/linux/why-my-backspace-not-work-in-vim/
set cursorline " 突出显示当前行
"set cursorcolumn " 突出显示当前列
set clipboard+=unnamed " 共享剪贴板 http://www.vitah.net/posts/9ddf2fa9/
set encoding=utf-8
set fileencoding=utf-8
set fileformat=unix "从Win上复制文件时,避免换行符错误
set hlsearch " 搜索时高亮显示被找到的文本
set ignorecase smartcase " 搜索时忽略大小写,但在有一个或以上大写字母时仍保持对大小写敏感
set incsearch " 输入搜索内容时就显示搜索结果
set ignorecase " 搜索时忽略大小写
set laststatus=2 " 显示状态栏 (默认值为 1, 无法显示状态栏)
set magic " 设置魔术
set mouse=a     " 启用鼠标
set nocompatible " 关闭 vi 兼容模式,避免以前版本的一些bug和局限
set number " 显示行号
"set paste  " 解决拷贝的时遇到注释会自动注释后续所有行的问题
set ruler " 打开状态栏标尺 在编辑过程中,在右下角显示光标位置的状态行
set showmatch " 显示匹配的括号
set showcmd " 输入的命令显示出来

" 适配 python 宽度的设定
set shiftwidth=4 " 设定 << 和 >> 命令移动时的宽度为 4
set softtabstop=4 " 使得按退格键时可以一次删掉 4 个空格
set smartindent " 开启新行时使用智能自动缩进
set tabstop=4 " 设定 tab 显示的宽度为 4
set smartindent "智能缩进,智能的选择对齐方式
set cindent "C语言风格缩进"
set autoindent "自动缩进 启用自动对齐功能,把上一行的对齐格式应用到下一行

"window border
set fillchars=vert:\ ,
highlight VertSplit guibg=darkgrey guifg=Black ctermbg=2 ctermfg=0

"for copy and paste
"
:behave mswin
:set clipboard=unnamedplus
:smap <C-x> <C-g>x
:imap <C-v> <Esc>pi
:smap <C-v> <C-g>p
:smap <Del> <C-g>"_d
:smap <C-c> <C-g>y
:smap <Tab> <C-g>1> 
:smap <S-Tab> <C-g>1

Screenshots (optional)

If applicable, add screenshots to help explain your problem.

fannheyward commented 1 year ago

Can't reproduce with another language server, looks like ccls returns some extra for this, we need ccls's response to debug this. https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel

Joenhle commented 1 year ago

I found 'lv5l' in the ccls's log, do you need the full contents of this file?

[Trace - 19:16:15.088] Sending notification 'textDocument/didChange'.
Params: {
    "textDocument": {
        "uri": "file:///Users/huangjunhao/leetcode/c%2B%2B/%E6%9C%80%E9%95%BF%E8%BF%9E%E7%BB%AD%E5%BA%8F%E5%88%97_/main.cpp",
        "version": 7
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 18,
                    "character": 18
                },
                "end": {
                    "line": 18,
                    "character": 18
                }
            },
            "text": "lv5l",
            "rangeLength": 0
        }
    ]
}
Joenhle commented 1 year ago
image

I just chose the 'for (i = 0; i < count; ++i' in the autocomplete list. why the log send notification 'textDocument/didChange' with 'lv5l' soon

Joenhle commented 1 year ago

bug from :behave mswin in my config