Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect auto completion #3290

Closed
khanhnmbk opened this issue Aug 16, 2021 · 39 comments
Closed

Incorrect auto completion #3290

khanhnmbk opened this issue Aug 16, 2021 · 39 comments

Comments

@khanhnmbk
Copy link

khanhnmbk commented Aug 16, 2021

Result from CocInfo

## versions

vim version: VIM - Vi IMproved 8.2 8022815
node version: v16.6.1
coc.nvim version: 0.0.80-8f2b91b437
coc.nvim directory: /home/khanhnguyen/.vim/plugged/coc.nvim
term: dumb
platform: linux

Describe the bug

I use TAB to trigger suggestion and ENTER to select the completion and it worked well before. After PlugUpdate, the completion stops working with incorrect texts inserted (tested with Go and Rust language). Please take a look at this gif for more details: https://imgur.com/a/mI7Shsy

Reproduce the bug

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

  • Create file mini.vim with:
call plug#begin('~/.vim/plugged')
Plug 'fatih/vim-go'
Plug 'rust-lang/rust.vim'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()

set encoding=utf-8

inoremap <silent><expr> <TAB>
     \ pumvisible() ? "\<C-n>" :
     \ <SID>check_back_space() ? "\<TAB>" :
     \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

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

inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
                             \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

CocConfig

{
  "languageserver": {
    "go": {
      "command": "gopls",
      "rootPatterns": ["go.mod"],
      "trace.server": "verbose",
      "filetypes": ["go"]
    }
    }
}
  • Start (neo)vim with command: vim -u mini.vim test.go

  • Operate vim (e.g. Go language)

fmt. -> TAB to show suggestions -> ENTER to select completion

Screenshots (optional)

If applicable, add screenshots to help explain your problem.

@asadmoosvi
Copy link

I can confirm. I am facing the exact same issue.

@khanhnmbk
Copy link
Author

@asadmoosvi Have you recently updated coc?

@fannheyward
Copy link
Member

fannheyward commented Aug 16, 2021

@NguyenMinhKhanhBK as I comment in fannheyward/coc-rust-analyzer#844, I still can't reproduce this error.

mini vimrc:

set nocompatible
set runtimepath^=~/.config/nvim/plugged/coc.nvim
filetype plugin indent on
syntax on
set hidden

CocInfo:

vim version: NVIM v0.6.0-dev+aa07d06bf
node version: v16.6.2
coc.nvim version: 0.0.80-54d0d15d59
coc.nvim directory: /Users/fannheyward/.config/nvim/plugged/coc.nvim
term: iTerm.app
platform: darwin

install coc-rust-analyzer, open a rust file as your code.

@fannheyward
Copy link
Member

@NguyenMinhKhanhBK nvim, I'll test vim now.

@khanhnmbk
Copy link
Author

Thanks @fannheyward , I also try NVIM right now

@asadmoosvi
Copy link

Here have a look at this asciinema. As you can see, it does not show the correct completions. I expect it to show the correct methods for console. It was working fine before I updated today. https://asciinema.org/a/hLtQWkI0PpeIyU0DARX6gkcCY

@fannheyward
Copy link
Member

Reproduced with vim

vim version: VIM - Vi IMproved 8.2 8023350
node version: v16.6.2
coc.nvim version: 0.0.80-54d0d15d59
coc.nvim directory: /Users/fannheyward/.config/nvim/plugged/coc.nvim
term: iTerm.app
platform: darwin

@fannheyward
Copy link
Member

cc @chemzqm, after git bisect, 9c54590 is the first bad commit

@Andoku
Copy link

Andoku commented Aug 30, 2021

@chemzqm I am still experiencing this bug.
CocInfo:

vim version: VIM - Vi IMproved 8.2 8022681
node version: v16.8.0
coc.nvim version: 0.0.80-3086844413
coc.nvim directory: /Users/antontatuev/.vim/plugged/coc.nvim
term: iTerm.app
platform: darwin

coc-clangd: 0.14.1

@fannheyward
Copy link
Member

fannheyward commented Sep 8, 2021

cc @chemzqm I can reproduce this bug with vim once in a while, after increase d68523e#diff-77d8897d9691d166262c50728155ab5b378ee97ef88efe75e7014a7e4337ad0aR80, the bug is gone.

Edit: still happens sometimes.

@fannheyward fannheyward reopened this Sep 8, 2021
@hanleylee
Copy link

hanleylee commented Sep 26, 2021

Here is a simple wordaround:

Plug 'neoclide/coc.nvim', {'branch': 'master', 'commit': '2ad659d8b1a3d7bef7dca7d33c6ab9363a729100', 'do': 'yarn install --frozen-lockfile'}

Just checkout to previous commit 😄

@0BananaBig0
Copy link

I have the same problem while typing C++ code. Have you solved it?

@fannheyward
Copy link
Member

@NguyenMinhKhanhBK @Andoku @hanleylee I've checked this again, and can't reproduce with vim 8.2.3600, can you give it a test?

@fannheyward
Copy link
Member

@user84441 I can't understand your issue from the screenshot.

@yaegassy
Copy link
Contributor

It probably looks like a problem where you expect background: to be auto complete, but it is auto complete as babackground:.

@user84441 I think it would be even easier to understand the situation if you prepare a "movie" (mp4) instead of a still screen capture.

By the way, I was not able to reproduce this problem.

@fannheyward
Copy link
Member

@user84441 got your problem, I missed the ba prefix, but in my tests, I can't reproduce this.

截屏2021-11-19 下午3 21 27

截屏2021-11-19 下午3 21 43

coc.nvim + coc-html + vim 8.2.3600.

@fannheyward
Copy link
Member

inoremap <silent><expr> <CR> pumvisible() ? coc#_select_confirm()
      \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

@0BananaBig0
Copy link

0BananaBig0 commented Nov 19, 2021

inoremap <silent><expr> <CR> pumvisible() ? coc#_select_confirm()
      \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
inoremap <silent><expr> <CR> pumvisible() ? coc#_select_confirm()
      \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

Maybe,I can give you an example which can occur this bug.

My system is ubuntu18.04.6
My vim version is 8.2.3458
My nodejs version is 16.13.0
My yarn version is 1.22.15

My mini .vimrc is
call plug#begin('/.vim/plugged')
Plug 'dracula/vim', { 'as': 'dracula' } " vim theme
Plug 'neoclide/coc.nvim', {'branch': 'master', 'do': 'yarn install --frozen-lockfile'} " 补全插件 build from source code by using yarn: https://yarnpkg.com
" Plug 'neoclide/coc.nvim', {'branch': 'master', 'commit': '2ad659d8b1a3d7bef7dca7d33c6ab9363a729100', 'do': 'yarn install --frozen-lockfile'} " if you has some problem when you use code completeion by press enter key, you should uncomment this line and update coc or learn how to use coc-snippets. Also,maybe the problem still exists, so you should uninstall coc and install coc again, then uncomment this line and update the coc.nvim.
call plug#end()
filetype on
filetype plugin on
filetype indent on
autocmd Filetype verilog nnoremap ` ma?moduleWyiw'a:echo "module -->" @0
syntax enable " 语法高亮,不否认当前颜色设置
set t_Co=256 " 开启256色支持
colorscheme dracula " 颜色主题配置
hi Cursor guifg=#dddfff guibg=#dddfff
hi Cursori guifg=cyan guibg=cyan
set guicursor=n-v-c:ver35-Cursor
set guicursor+=i:ver35-Cursori
set guicursor+=a:blinkon0
inoremap
\ pumvisible() ? "" :
\ check_back_space() ? "" :
\ coc#refresh()
inoremap pumvisible() ? "" : ""
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =# '\s'
endfunction
inoremap pumvisible() ? coc#_select_confirm() :""
inoremap pumvisible() ? coc#_select_confirm()
: "u=coc#on_enter()"
nmap gd (coc-definition)
nmap gn (coc-rename)
nmap gu (coc-references-used)
nmap gr (coc-references)
set updatetime=333
if has("nvim-0.5.0") || has("patch-8.1.1564")
set signcolumn=number
endif
autocmd CursorHold * silent call CocActionAsync('highlight')

My coc-settings.json is
{
"languageserver": {
"svlangserver": {
"module": "/usr/lib/node_modules/@imc-trading/svlangserver/lib/svlangserver.js",
"filetypes": ["systemverilog","vhdl","verilog"],
"settings": {
"systemverilog.includeIndexing": ["/*.{sv,svh}"],
"systemverilog.excludeIndexing": ["test//.sv"],
"systemverilog.defines" : [],
"systemverilog.launchConfiguration": "/usr/local/bin/verilator -sv -Wall --lint-only",
"systemverilog.formatCommand": "/usr/local/bin/verible-verilog-format"
}
}
},
"coc.preferences.rootPatterns": [".git",".hg",".projections.json",".project",".svn",".root"],
"suggest.maxCompleteItemCount":9,
"coc.source.around.firstMatch": false,
"coc.source.buffer.firstMatch": false,
"coc.preferences.jumpCommand":"edit",
"suggest.noselect": true,
"suggest.enablePreselect": false,
"suggest.triggerAfterInsertEnter": true,
"suggest.autoTrigger":"none",
"suggest.detailField": "preview",
"suggest.snippetIndicator": "",
"suggest.echodocSupport": true,
"diagnostic.enable":true,
"diagnostic.displayByAle":false,
"diagnostic.messageTarget": "echo",
"pyright.disableDiagnostics":true,
"clangd.disableDiagnostics": true,
/if you set the value to echo, the function floating windows will close
and some help information will show on the cmdline,otherwise, it will open/
"signature.target": "echo",
"markdownlint.onOpen": false
}

My CocInfo is
versions

vim version: VIM - Vi IMproved 8.2 8023458
node version: v16.13.0
coc.nvim version: 0.0.80-19a630de32
coc.nvim directory: /home/banana/.vim/plugged/coc.nvim
term: dumb
platform: linux
Log of coc.nvim

2021-11-19T15:20:25.606 INFO (pid:4647) [services] - registered service "languageserver.svlangserver"
2021-11-19T15:20:25.728 INFO (pid:4647) [plugin] - coc.nvim 0.0.80-19a630de32 initialized with node: v16.13.0 after 206ms
2021-11-19T15:20:25.730 INFO (pid:4647) [attach] - receive notification: highlight []
2021-11-19T15:20:25.760 INFO (pid:4647) [services] - registered service "clangd"
2021-11-19T15:20:25.761 INFO (pid:4647) [services] - clangd state change: stopped => starting
2021-11-19T15:20:25.767 INFO (pid:4647) [language-client-index] - Language server "clangd" started with 4662
2021-11-19T15:20:25.785 INFO (pid:4647) [services] - clangd state change: starting => running
2021-11-19T15:20:25.794 INFO (pid:4647) [services] - service clangd started
2021-11-19T15:20:28.735 INFO (pid:4647) [attach] - receive notification: showInfo []

My test code is hello.cpp:
#include
using namespace std;
class HelloPrint
{
public:
HelloPrint(int argc, char **argv);
int printHello(void);

private:
int number;
char **content;
};
HelloPrint::HelloPrint(int argc, char **argv)
{
number = argc;
content = argv;
};
int HelloPrint::printHello(void)
{
int i;
if (number < 4 || number > 5)
{
cout << "There is something!";
}
else
{
for (i = 1; i < number - 1; i++)
{
if (i == 2)
{
cout << *(content + 4) << " ";
}
else
{
cout << *(content + i) << " ";
}
};
cout << *(content + 2) << "!" << endl;
};
return 0;
};
int TestPrint(int argc, char **argv)
{
int number;
char **content;
number = argc;
content = argv;
std::cout<<number<<std::endl;
std::cout<<*content<<std::endl;
std::cout<<*argv<<std::endl;
return 0;
};
int main(int argc, char **argv)
{
HelloPrint example(argc, argv);
TestPrint(argc, argv);
std::cout << "Hello" << std::endl;
example.printHello();
}

My process of generating a bug is
gvim hello.cpp
jump to the 58th lines
press A
Press enter
input two characters: ex
press tab
press enter
You will see an error word examplele
But the right word is example

That is all. Thanks very much.

@yaegassy
Copy link
Contributor

yaegassy commented Nov 19, 2021

@user84441 I tried with this mapping described in the README of coc.nvim written by fannheyward. The problem was not reproduced. By the way, I always use <C-y>.

inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

Capture(mp4):

Vim8 (v8.2.3607)

coc-issue-3290-1.mp4

@0BananaBig0
Copy link

0BananaBig0 commented Nov 19, 2021

@user84441 got your problem, I missed the ba prefix, but in my tests, I can't reproduce this.
截屏2021-11-19 下午3 21 27
截屏2021-11-19 下午3 21 43
coc.nvim + coc-html + vim 8.2.3600.

You have used inoremap pumvisible() ? coc#_select_confirm() : "u=coc#on_enter()" for auto complete? Try to use this with enter. Probably your computer pretty fast and you need many times trying to reproduce this.

These methods can avoid it
First method:
uninstall coc.nvim
use this Plug 'neoclide/coc.nvim', {'branch': 'master', 'do': 'yarn install --frozen-lockfile'} to install coc.nvim
and then add this Plug 'neoclide/coc.nvim', {'branch': 'master', 'commit': '2ad659d8b1a3d7bef7dca7d33c6ab9363a729100', 'do': 'yarn install --frozen-lockfile'} to your .vimrc and update coc.nvim

Second method:
Not press enter to complete the word. You can use Tab to choose which word you want to complete and then press any key except enter.

@fannheyward
Copy link
Member

fannheyward commented Nov 19, 2021

@Banana-Two try vim 8.2.3600, tested with your hello.cpp, tab to choose and <cr> to confirm, can't reproduce.

@ghost
Copy link

ghost commented Nov 19, 2021

@Banana-Two try vim 8.2.3600, tested with your hello.cpp, tab to choose and <cr> to confirm, can't reproduce.

Okay then. It should be the first item in the complete list. Another example. C++. I'm trying to complete const with con FAST with enter:

inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"


> vim version: VIM - Vi IMproved 8.2 8023619
> node version: v14.18.1
> coc.nvim version: 0.0.80-03c9add7cd
> coc.nvim directory: /home/user/.vim/plugged/coc.nvim
> term: dumb
> platform: linux

2021-11-19.11-52-38.mp4

@fannheyward
Copy link
Member

fannheyward commented Nov 19, 2021

@user84441 You mean you input con and enter, got constcon? What's language server do you use? Where did the const came from?

I'm using coc-clangd:

截屏2021-11-19 下午4 04 38

con will result the completions list, const is the first item, enter to confirm it.

Tested on macOS.

@ghost
Copy link

ghost commented Nov 19, 2021

@user84441 You mean you input con and enter, got constcon? What's language server do you use? Where did the const came from

@user84441 You mean you input con and enter, got constcon? What's language server do you use? Where did the const came from?

I'm using coc-clangd:

截屏2021-11-19 下午4 04 38

con will result the completions list, const is the first item, enter to confirm it.

Tested on macOS.

Reproduced with char (ch and enter).

2021-11-19.12-08-48.mp4

@fannheyward
Copy link
Member

@user84441 repeated about 20 times, still can't reproduce, have no idea about this.

@0BananaBig0
Copy link

@fannheyward
I just tried it at vim 8.2.3600 and the latest version. The error still exists if I comment Plug 'neoclide/coc.nvim', {'branch': 'master', 'commit': '2ad659d8b1a3d7bef7dca7d33c6ab9363a729100', 'do': 'yarn install --frozen-lockfile'} and update coc.nvim. But in neovim v0.5.1, this error doesn't occur.

@0BananaBig0
Copy link

@user84441 repeated about 20 times, still can't reproduce, have no idea about this.

Okay. Sorry all of you for spamming about my problem(about all of LSP). I need just to upgrade my PC then. Thanks by the way.
Maybe you can try neovim,if you don't care about the gui.

@khanhnmbk
Copy link
Author

@NguyenMinhKhanhBK @Andoku @hanleylee I've checked this again, and can't reproduce with vim 8.2.3600, can you give it a test?

I can't reproduce with vim 8.2 and latest master of coc. Seems it was fixed

@Andoku
Copy link

Andoku commented Nov 19, 2021

I am still experiecing the same problem

vim version: VIM - Vi IMproved 8.2 8022681
node version: v17.0.1
coc.nvim version: 0.0.80-03c9add7cd
coc.nvim directory: /Users/antontatuev/.vim/plugged/coc.nvim
term: iTerm.app
platform: darwin
2021-11-20.00.41.39.mov

@0BananaBig0
Copy link

@fannheyward
Here is a virtual machine link. My Virtual Machine Ubuntu18
Maybe you can download it to test. Its root's password is 0311
If this link not work, tell me your e-mail address,please. I will send you the link again.
I always use it to test somethings. The virtual machine is similar with my Ubuntu18 which has the same problem and is not a virtual machine.
The process of reproducing the bug is :
Open VMWorkstation16
Open Ubuntu18 Virtual Machine
If you find the screen looks very small, please exit the full screen at first and then enter the full screen again.
Open the terminal and execute the following commands:
cd study_ws/src/hello
gvim hello.cpp
In the gvim do the following operations:
jump to the 47th lines
press A
press enter
input two characters ex
press tab
press enter
the error word examplele will be completed.
If the error not occurs, you can then input two characters .p
press tab
press enter
the error word printHello()lo will be completed.
That's all! Thanks very much.

@0BananaBig0
Copy link

@Andoku

These methods can avoid it
First method:
uninstall coc.nvim
use this Plug 'neoclide/coc.nvim', {'branch': 'master', 'do': 'yarn install --frozen-lockfile'} to install coc.nvim
and then add this Plug 'neoclide/coc.nvim', {'branch': 'master', 'commit': '2ad659d8b1a3d7bef7dca7d33c6ab9363a729100', 'do': 'yarn install --frozen-lockfile'} to your .vimrc and update coc.nvim

Second method:
Not press enter to complete the word. You can use Tab to choose which word you want to complete and then press any key except enter.

Third method:
Maybe you can try neovim, if you don't care about the gui.

@fannheyward
Copy link
Member

@Andoku as I commented above, try vim 8.2.3600+, I can't reproduce this now.

@n1ghtmare
Copy link

n1ghtmare commented Dec 12, 2021

Just here to report that I have the exact same issue (I'm on neovim v0.6.0). On Arch Linux. I tried what @Banana-Two suggested, but unfortunately didn't work.

Any suggestions? I'm so used to pressing enter for the first time that this is driving me nuts.

EDIT: Sorry, turns out my issue is "similar", when I press Enter instead of auto-completing and selecting the first item I get a new line (no text).

@chemzqm
Copy link
Member

chemzqm commented Dec 24, 2021

Can't reproduce, try lastest coc.nvim.

Or provide connection log, please follow these steps:

  • Add let g:node_client_debug = 1 to your vimrc, save your vimrc and exit vim.
  • Restart your vim/neovim to make the issue happen.
  • Get the log filepath by :echo $NODE_CLIENT_LOG_FILE
  • Attach the log file or paste content from the log.

@xulongwu4
Copy link

xulongwu4 commented Dec 31, 2021

@chemzqm @fannheyward I am on the latest release branch and I am still experiencing this issue. My vim version is 8.2.3956. I don't have this issue on neovim 0.5.1.

GIF for the issue:

Peek 2021-12-31 13-43

Log file for operations in the gif:

coc.log

@xulongwu4
Copy link

After updating to d454b57 on the release branch, I don't have this problem any more.

@GZGavinZhao
Copy link

GZGavinZhao commented Jan 12, 2022

Same here, I used to get super annoyed by this, but after updating it on the release branch today, the problem magically disappeared!

Just for reference, my config is:

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Nov 26 2021 16:12:23)
Included patches: 1-3575
Modified by Solus
Compiled by Solus
Huge version with GTK3 GUI.  Features included (+) or not (-):

My language server is clangd:

{
	"languageserver": {
		"clangd": {
			"command": "clangd",
			"filetypes": [
				"c",
				"cpp"
			],
			"rootPatterns": [
				"compile_commands.json",
				".git"
			],
			"args": [
				"--compile-commands-dir=build",
				"--compile_args_from=filesystem",
				"--all-scopes-completion",
				"--background-index",
				"--clang-tidy",
				"--cross-file-rename",
				"--completion-parse=always",
				"--completion-style=detailed",
				"--function-arg-placeholders",
				"--header-insertion-decorators",
				"--header-insertion=never",
				"--limit-results=0",
				"--pch-storage=memory"
			]
		}
}

@0BananaBig0
Copy link

0BananaBig0 commented Jan 12, 2022

Me too. After updating the lastest version of coc.nvim, the problem of incorrect auto completion disappear. But another problem occurs. After using ”enter“ key to choose the completion word, the result of withdrawal will be modified. Only vim will have this question. Only using ”enter“ key to finish completion will have this problem.
My vim version is 8.2.3458. I use coc-clangd.
This my minimum .vimrc:

call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'master', 'do': 'yarn install --frozen-lockfile'} " 补全插件  build from source code by using yarn: https://yarnpkg.com
call plug#end()

  inoremap <silent><expr> <TAB>
        \ pumvisible() ? "\<C-n>" :
        \ <SID>check_back_space() ? "\<TAB>" :
        \ coc#refresh()
  inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  function! s:check_back_space() abort
    let col = col('.') - 1
    return !col || getline('.')[col - 1]  =~# '\s'
  endfunction
  " Make <CR> auto-select the first completion item
  inoremap <silent><expr> <CR> pumvisible() ? coc#_select_confirm() :"\<CR>"
  " Make <S-CR> auto-select the first completion item and notify coc.nvim to
  " format on shift-enter, <S-CR> could be remapped by other vim plugin
  " because it will trigger CmdLineLeave to affect the fcitx-remote, so I
  " only use it when I type codes
  inoremap <silent><expr> <S-CR> pumvisible() ? coc#_select_confirm()
          \: "\<C-g>u\<S-CR>\<c-r>=coc#on_enter()\<S-CR>"

The question is described in detail as following:
Before completing, the code is as following:
image
After multiple times completion by "enter" key, the code is as following:
image
After multiple times withdrawal by "u" key, the code is as following:
image
And then if I close this window, it will not ask me to save the content. And the code will become the original code:
image

This my minimum .vimrc:
vimrc.txt
This my test code:
hello.cpp.txt

@chemzqm
Copy link
Member

chemzqm commented Jan 24, 2022

@Banana-Two Can't reproduce with same vim version, could be issue with vim on your terminal.

Try update coc.nvim and if the problem still exists, open new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests