neoclide/coc.nvim

`"diagnostic.separateRelatedInformationAsDiagnostics"` makes everything of customized typescript LS super lag in the file with lots of diagnostics

hexh250786313 opened this issue · 3 comments

Result from CocInfo

Click to see
## versions

vim version: NVIM v0.10.0
node version: v18.20.0
coc.nvim version: 0.0.82-6e1efbf5 2024-07-11 17:12:22 +0800
coc.nvim directory: /home/hexh/workspace/hexh/coc.nvim
term: tmux
platform: linux

## Log of coc.nvim

2024-07-12T11:44:24.571 INFO (pid:164413) [configurations] - Add folder configuration from file: /home/hexh/workspace/hexh/coc.nvim/.vim/coc-settings.json
2024-07-12T11:44:24.761 INFO (pid:164413) [plugin] - coc.nvim initialized with node: v18.20.0 after 345
2024-07-12T11:44:24.765 INFO (pid:164413) [services] - LanguageClient typescript state change: stopped => starting
2024-07-12T11:44:24.770 INFO (pid:164413) [language-client-index] - Language server "languageserver.typescript" started with 164456
2024-07-12T11:44:24.858 INFO (pid:164413) [services] - LanguageClient typescript state change: starting => running
2024-07-12T11:44:24.869 INFO (pid:164413) [services] - service languageserver.typescript started
2024-07-12T11:44:35.982 INFO (pid:164413) [attach] - Request action: jumpDefinition []
2024-07-12T11:44:38.982 ERROR (pid:164413) [timing] - Request timeout after 3000ms
2024-07-12T11:45:05.163 INFO (pid:164413) [attach] - receive notification: showInfo []

Describe the bug

"diagnostic.separateRelatedInformationAsDiagnostics" makes everything of customized typescript LS super lag in the file with lots of diagnostics.

Reproduce the bug

npm install -g typescript-language-server typescript # or vtsls
git clone https://github.com/hexh250786313/test-coc
cd test-coc

Change the following lines to the actual file and directory in mini.vim.

let g:test_coc_path = '/path/to/test-coc'
set runtimepath^=/path/to/coc.nvim
  • Start nvim with command: nvim --clean -u ./mini.vim /path/to/coc.nvim/build/index.js.
  • Wait for the language server to finish initializing.
  • Go to line 179 and move cursor to module2.
  • Press gr for call CocAction('jumpReferences').
  • Nvim becomes super slow or even freezes.

Then change the "diagnostic.separateRelatedInformationAsDiagnostics" back to 0 (false) in mini.vim. Everything of the customized typescript LS work fine even though it's not as fast as coc-tsserver.

In that case, do not enable separateRelatedInformationAsDiagnostics.

The LSP defined the Diagnostic.relatedInformation only, the client should decide how to display them. coc.nvim provides separateRelatedInformationAsDiagnostics and disables it by default. If enable it, coc.nvim will expand the array to diagnostics to use.

In this case, the server returns lots of relatedInformation, makes the client slow to work. What can the client do?

  1. limit the count of relatedInformation, I don't think it's the way, client shouldn't omit any of them
  2. improve the displaying performance, depends on vim/nvim, lots of ext marks always cause lagging.

@fannheyward Thank you for the detailed explanation.

The LSP defined the Diagnostic.relatedInformation only, the client should decide how to display them. coc.nvim provides separateRelatedInformationAsDiagnostics and disables it by default.

In that case, I'd suggest providing an additional, better performing way of displaying related info. For example, to modify only the contents of the message without creating additional ext marks, as in this part of the separateDiagnostics code:

if (diagnostic.relatedInformation?.length) {
let message = `${diagnostic.message}\n\nRelated diagnostics:\n`
for (const info of diagnostic.relatedInformation) {
const basename = path.basename(URI.parse(info.location.uri).fsPath)
const ln = info.location.range.start.line
message = `${message}\n${basename}(line ${ln + 1}): ${info.message}`

Or, as in vsc, provide path information:

image

coc-pretty-ts-errors achieves a similar effect, but it only works for typescript LS:

image

If it is possible, I will create a related PR for coc.nvim to provide a new option to display this information shortly.

modify only the contents of the message without creating additional ext marks

This sounds a better way, will reduce diagnostics in buffer, only show in floating window.