neoclide / coc.nvim

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

[coc.nvim]: Error on notification "openLink": Buffer 9 not attached, not a normal buffer, buftype "help" #4831

Closed Freed-Wu closed 7 months ago

Freed-Wu commented 7 months ago

Result from CocInfo

## versions

vim version: NVIM v0.9.4
node version: v21.2.0
coc.nvim version: 0.0.82-d1568d56 2023-09-29 19:43:34 +0800
coc.nvim directory: /home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release
term: tmux
platform: linux

## Log of coc.nvim

2023-12-11T21:25:49.635 INFO (pid:3328427) [extension:coc-git] - Looking for git in: git
2023-12-11T21:25:49.818 INFO (pid:3328427) [extension:coc-tabnine] - Using tabnine from /home/wzy/.config/coc/extensions/coc-tabnine-data/binaries/4.53.0/x86_64-unknown-linux-musl/TabNine
2023-12-11T21:25:50.060 WARN (pid:3328427) [workspace] - workspace.createStatusBarItem is deprecated, please use window.createStatusBarItem instead. 
    at c.init (/home/wzy/.config/coc/extensions/node_modules/coc-leetcode/out/index.js:1:12315)
    at new c (/home/wzy/.config/coc/extensions/node_modules/coc-leetcode/out/index.js:1:12274)
2023-12-11T21:25:50.075 INFO (pid:3328427) [plugin] - coc.nvim initialized with node: v21.2.0 after 1132
2023-12-11T21:25:50.099 WARN (pid:3328427) [workspace] - workspace.createStatusBarItem is deprecated, please use window.createStatusBarItem instead. 
    at t.initStatusBar (/home/wzy/.config/coc/extensions/node_modules/coc-spell-checker/out/index.js:1:156009)
    at t.activate (/home/wzy/.config/coc/extensions/node_modules/coc-spell-checker/out/index.js:1:23162)
2023-12-11T21:25:50.133 INFO (pid:3328427) [language-client-index] - Language server "cSpell" started with 3328602
2023-12-11T21:25:50.139 ERROR (pid:3328427) [events] - Error on event: CursorHold Error: Buffer 1 not attached, not a normal buffer, buftype "nofile"
    at FE.getAttachedDocument (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:194:3403)
    at $y.getCurrentState (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:277:34038)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Ly.getLinks (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:2812)
    at async Ly.getCurrentLink (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:2948)
    at async Ly.showTooltip (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:2601)
    at async /home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:2044
2023-12-11T21:25:50.908 INFO (pid:3328427) [attach] - receive notification: doAutocmd [ 3 ]
2023-12-11T21:25:51.084 INFO (pid:3328427) [attach] - receive notification: doAutocmd [ 3 ]
2023-12-11T21:25:51.487 ERROR (pid:3328427) [events] - Error on event: CursorHold Error: Buffer 2 not attached, not a normal buffer, buftype "help"
    at FE.getAttachedDocument (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:194:3403)
    at $y.getCurrentState (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:277:34038)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Ly.getLinks (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:2812)
    at async Ly.getCurrentLink (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:2948)
    at async Ly.showTooltip (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:2601)
    at async /home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:2044
2023-12-11T21:25:53.588 ERROR (pid:3328427) [events] - Error on event: CursorHold Error: Buffer 2 not attached, not a normal buffer, buftype "help"
    at FE.getAttachedDocument (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:194:3403)
    at $y.getCurrentState (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:277:34038)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Ly.getLinks (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:2812)
    at async Ly.getCurrentLink (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:2948)
    at async Ly.showTooltip (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:2601)
    at async /home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:2044
2023-12-11T21:25:55.090 INFO (pid:3328427) [attach] - receive notification: openLink []
2023-12-11T21:25:55.096 ERROR (pid:3328427) [attach] - Error on notification openLink Error: Buffer 2 not attached, not a normal buffer, buftype "help"
    at FE.getAttachedDocument (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:194:3403)
    at $y.getCurrentState (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:277:34038)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Ly.getLinks (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:2812)
    at async Ly.getCurrentLink (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:2948)
    at async Ly.openCurrentLink (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:265:3548)
    at async Gy.cocAction (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:277:46159)
    at async EventEmitter.<anonymous> (/home/wzy/.local/share/nvim/repos/github.com/neoclide/coc.nvim_release/build/index.js:277:47778)
2023-12-11T21:25:59.443 INFO (pid:3328427) [attach] - receive notification: showInfo []

Describe the bug

If a document link is in a help buffer, it will throw error:

[coc.nvim]: Error on notification "openLink": Buffer 9 not attached, not a normal buffer, buftype "help"

Reproduce the bug

Install vimtex,

:h vimtex
:/http

Then press the hotkey to open the document link. Trigger the error.

screen-2023-12-11-21-27-47

fannheyward commented 7 months ago

It's expected. The buffer document is not created by coc.nvim, or attached to coc.nvim's management, when you fire any actions to it, coc.nvim has no idea to handle it, an error is throwing.

Maybe we can try-catch to hide this error, but this brings another issue: no response on actions.

Freed-Wu commented 6 months ago

Oh, I see. Currently I add the following code to avoid this problem:

ftplugin/help.vim:

nnoremap <silent><buffer> gx :<C-U>call pandoc#hypertext#OpenSystem()<CR>
xnoremap <silent><buffer> gx :<C-U>call pandoc#hypertext#OpenSystem(getline('.')[col('v') - 1:col('''>') - 1])<CR>

These functions come from https://github.com/vim-pandoc/vim-pandoc

Freed-Wu commented 6 months ago

Can we provide a fallback, when it will throw an error, use a traditional method to open the link under the cursor?

fannheyward commented 6 months ago

provide a fallback

The openLink action returns true for success, you can check this in vim function to run gx to open the link.

Freed-Wu commented 6 months ago

openLink action will throw an error and return nothing when fail. Can it return v:false when fail?

fannheyward commented 6 months ago
function! OpenLink() abort
  try
    CocActionAsync('openLink')
  catch
    call pandoc#hypertext#OpenSystem()
  endtry
endfunction