coc.nvim icon indicating copy to clipboard operation
coc.nvim copied to clipboard

"Cannot read properties of undefined (reading 'length')", CoC stops working

Open xi-lef opened this issue 6 months ago • 3 comments

Result from CocInfo

versions

vim version: VIM - Vi IMproved 9.1 9010000 node version: v21.5.0 coc.nvim version: 0.0.82-d1568d56 2023-09-29 19:43:34 +0800 coc.nvim directory: /home/felix/.vim/plugged/coc.nvim term: dumb platform: linux

Log of coc.nvim

2024-01-28T00:02:50.397 INFO (pid:106164) [plugin] - coc.nvim initialized with node: v21.5.0 after 147 2024-01-28T00:02:50.405 INFO (pid:106164) [services] - LanguageClient clangd state change: stopped => starting 2024-01-28T00:02:50.407 INFO (pid:106164) [language-client-index] - Language server "clangd" started with 106178 2024-01-28T00:02:50.422 INFO (pid:106164) [services] - LanguageClient clangd state change: starting => running 2024-01-28T00:02:50.427 INFO (pid:106164) [services] - service clangd started 2024-01-28T00:02:51.924 ERROR (pid:106164) [provider-manager] - Provider error on provideSelectionRanges: Dg [Error]: trying to get AST for non-added document at it (/home/felix/.vim/plugged/coc.nvim/build/index.js:27:234) at zn (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7395) at uo (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7518) at Immediate. (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7282) at process.processImmediate (node:internal/timers:478:21) { code: -32602, data: undefined } 2024-01-28T00:02:51.929 ERROR (pid:106164) [completion-complete] - Complete error: clangd Dg [Error]: trying to get preamble for non-added document at it (/home/felix/.vim/plugged/coc.nvim/build/index.js:27:234) at zn (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7395) at uo (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7518) at Immediate. (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7282) at process.processImmediate (node:internal/timers:478:21) { code: -32602, data: undefined } 2024-01-28T00:02:52.019 ERROR (pid:106164) [provider-manager] - Provider error on provideSelectionRanges: Dg [Error]: trying to get AST for non-added document at it (/home/felix/.vim/plugged/coc.nvim/build/index.js:27:234) at zn (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7395) at uo (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7518) at Immediate. (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7282) at process.processImmediate (node:internal/timers:478:21) { code: -32602, data: undefined } 2024-01-28T00:02:52.019 ERROR (pid:106164) [completion-complete] - Complete error: clangd Dg [Error]: trying to get preamble for non-added document at it (/home/felix/.vim/plugged/coc.nvim/build/index.js:27:234) at zn (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7395) at uo (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7518) at Immediate. (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7282) at process.processImmediate (node:internal/timers:478:21) { code: -32602, data: undefined } 2024-01-28T00:02:52.098 ERROR (pid:106164) [provider-manager] - Provider error on provideSelectionRanges: Dg [Error]: trying to get AST for non-added document at it (/home/felix/.vim/plugged/coc.nvim/build/index.js:27:234) at zn (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7395) at uo (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7518) at Immediate. (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7282) at process.processImmediate (node:internal/timers:478:21) { code: -32602, data: undefined } 2024-01-28T00:02:52.099 ERROR (pid:106164) [completion-complete] - Complete error: clangd Dg [Error]: trying to get preamble for non-added document at it (/home/felix/.vim/plugged/coc.nvim/build/index.js:27:234) at zn (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7395) at uo (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7518) at Immediate. (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7282) at process.processImmediate (node:internal/timers:478:21) { code: -32602, data: undefined } 2024-01-28T00:02:52.298 ERROR (pid:106164) [provider-manager] - Provider error on provideDocumentLinks: Dg [Error]: trying to get AST for non-added document at it (/home/felix/.vim/plugged/coc.nvim/build/index.js:27:234) at zn (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7395) at uo (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7518) at Immediate. (/home/felix/.vim/plugged/coc.nvim/build/index.js:26:7282) at process.processImmediate (node:internal/timers:478:21) { code: -32602, data: undefined } 2024-01-28T00:02:52.922 ERROR (pid:106164) [events] - Error on event: TextChangedI TypeError: Cannot read properties of undefined (reading 'length') at Vge (/home/felix/.vim/plugged/coc.nvim/build/index.js:165:4384) at qh.getLineOffsets (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:1264) at qh.offsetAt (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:995) at qh.getText (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:479) at Ff._fireContentChanges (/home/felix/.vim/plugged/coc.nvim/build/index.js:169:2331) at Ff._forceSync (/home/felix/.vim/plugged/coc.nvim/build/index.js:171:294) at Ff._fetchContent (/home/felix/.vim/plugged/coc.nvim/build/index.js:173:1928) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Ff.patchChange (/home/felix/.vim/plugged/coc.nvim/build/index.js:173:1247) at async Promise.all (index 2) 2024-01-28T00:02:53.025 ERROR (pid:106164) [events] - Error on event: TextChangedI TypeError: Cannot read properties of undefined (reading 'length') at Vge (/home/felix/.vim/plugged/coc.nvim/build/index.js:165:4384) at qh.getLineOffsets (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:1264) at qh.offsetAt (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:995) at qh.getText (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:479) at Ff._fireContentChanges (/home/felix/.vim/plugged/coc.nvim/build/index.js:169:2331) at Ff._forceSync (/home/felix/.vim/plugged/coc.nvim/build/index.js:171:294) at Ff.onTextChange (/home/felix/.vim/plugged/coc.nvim/build/index.js:173:1680) at /home/felix/.vim/plugged/coc.nvim/build/index.js:173:5168 at /home/felix/.vim/plugged/coc.nvim/build/index.js:55:4214 at new Promise () 2024-01-28T00:02:53.117 ERROR (pid:106164) [events] - Error on event: TextChangedI TypeError: Cannot read properties of undefined (reading 'length') at Vge (/home/felix/.vim/plugged/coc.nvim/build/index.js:165:4384) at qh.getLineOffsets (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:1264) at qh.offsetAt (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:995) at qh.getText (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:479) at Ff._fireContentChanges (/home/felix/.vim/plugged/coc.nvim/build/index.js:169:2331) at Ff._forceSync (/home/felix/.vim/plugged/coc.nvim/build/index.js:171:294) at Ff.onTextChange (/home/felix/.vim/plugged/coc.nvim/build/index.js:173:1680) at /home/felix/.vim/plugged/coc.nvim/build/index.js:173:5168 at /home/felix/.vim/plugged/coc.nvim/build/index.js:55:4214 at new Promise () 2024-01-28T00:02:53.318 ERROR (pid:106164) [server] - unhandledRejection Promise { TypeError: Cannot read properties of undefined (reading 'length') at Vge (/home/felix/.vim/plugged/coc.nvim/build/index.js:165:4384) at qh.getLineOffsets (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:1264) at qh.offsetAt (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:995) at qh.getText (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:479) at Ff._fireContentChanges (/home/felix/.vim/plugged/coc.nvim/build/index.js:169:2331) at Ff._forceSync (/home/felix/.vim/plugged/coc.nvim/build/index.js:171:294) at vF.stop (/home/felix/.vim/plugged/coc.nvim/build/index.js:253:55424) at vF._startCompletion (/home/felix/.vim/plugged/coc.nvim/build/index.js:253:52425) at vF.triggerCompletion (/home/felix/.vim/plugged/coc.nvim/build/index.js:253:54691) at Timeout. (/home/felix/.vim/plugged/coc.nvim/build/index.js:253:54112) } TypeError: Cannot read properties of undefined (reading 'length') at Vge (/home/felix/.vim/plugged/coc.nvim/build/index.js:165:4384) at qh.getLineOffsets (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:1264) at qh.offsetAt (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:995) at qh.getText (/home/felix/.vim/plugged/coc.nvim/build/index.js:167:479) at Ff._fireContentChanges (/home/felix/.vim/plugged/coc.nvim/build/index.js:169:2331) at Ff._forceSync (/home/felix/.vim/plugged/coc.nvim/build/index.js:171:294) at vF.stop (/home/felix/.vim/plugged/coc.nvim/build/index.js:253:55424) at vF._startCompletion (/home/felix/.vim/plugged/coc.nvim/build/index.js:253:52425) at vF.triggerCompletion (/home/felix/.vim/plugged/coc.nvim/build/index.js:253:54691) at Timeout. (/home/felix/.vim/plugged/coc.nvim/build/index.js:253:54112) 2024-01-28T00:02:55.616 INFO (pid:106164) [attach] - receive notification: openLog []

Describe the bug

When creating a file as described below, coc produces error messages and apparently stops working completely: in this example, coc-clangd doesn't work anymore, and with my normal config, other extensions also don't work, which seems to be due to the same error.

Reproduce the bug

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

  1. Create file .vimrc with:
call plug#begin()
Plug 'junegunn/vim-plug'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
let g:coc_global_extensions = ['coc-clangd']

function InsertComment()
    let clear = "\<Esc>0\"_Di" " helper-'function' to clear a line
    execute 'normal! o' . clear . '/*' . "\<CR>" . clear . '*/' . "\<Esc>O" . clear
    startinsert!
endfunction
nnoremap <silent> \c :call InsertComment()<CR>
  1. Open file a.c

  2. Insert a comment with \c (I can't reproduce it without this mapping/function...), type abc inside of the comment, then type abc outside of the comment, so the file looks like this:


/*
abc
*/
abc
  1. CoC stops working and produces error messages, as seen in :CocOpenLog.

This is very specific and weird, but it's a pretty big problem for me. If you need more information etc., I'm glad to help.

xi-lef avatar Jan 27 '24 23:01 xi-lef

Reproduced with Vim only.

In nvim:

  1. open nvim, lines of buffer is ['']
  2. \c and input a, got [ '', '/*', 'a', '*/' ].

But in vim:

  1. open vim, got ['']
  2. \c and a, got [ '', <1 empty item>, 'a' ], this made the issue

With https://github.com/neoclide/coc.nvim/pull/4875, vim got same lines as nvim.

fannheyward avatar Jan 29 '24 09:01 fannheyward

Interesting. #4875 seems to work for me too, so thank you! Hope it can merge soon :wink:
Could you tell me how to view the buffer content in the form like [ '', <1 empty item>, 'a' ]? Maybe I can adjust my InsertComment-function so it doesn't produce this weird empty item.

xi-lef avatar Jan 29 '24 21:01 xi-lef

Log the lines value https://github.com/neoclide/coc.nvim/blob/dev/src/model/textdocument.ts#L30

I don't think it's InsertComment's issue, but buffer content didn't update in time.

fannheyward avatar Jan 30 '24 01:01 fannheyward