coq_nvim icon indicating copy to clipboard operation
coq_nvim copied to clipboard

Neovim freezes up when using tsserver

Open heygarrett opened this issue 4 years ago • 7 comments

Using coq, sometimes when typing or exiting insert mode in a TypeScript file Neovim freezes for 1-3 seconds, but only when tsserver is in my LSP config:

local nvim_lsp = require('lspconfig')
local coq = require('plugins/coq')
local on_attach = require('utils/on-attach')
local capabilities = vim.lsp.protocol.make_client_capabilities()

local servers = {
	'pyright',
	'rust_analyzer',
	'sourcekit',
	'jsonls',
	'tsserver',
	'svelte',
}

for _, lsp in ipairs(servers) do
	nvim_lsp[lsp].setup(coq.lsp_ensure_capabilities({
		on_attach = on_attach,
		capabilities = capabilities,
	}))
end

Here's my coq config:

vim.g.coq_settings = {
	auto_start = true,
	clients = {
		['tmux.enabled'] = false,
		['snippets.warn'] = {},
	},
	['keymap.jump_to_mark'] = '<c-n>',
}

require('coq_3p') {
	{src = 'nvimlua', short_name = 'nLUA'}
}

return require('coq')

Here are some screen recordings of exiting insert mode:

coq enabled and tsserver in LSP config (I hit escape around the same time the diagnostics signs disappear):
https://user-images.githubusercontent.com/1154912/135338373-48d890b7-8e29-4d65-941b-7d0792c2bfad.mov

coq disabled and tsserver still in LSP config:
https://user-images.githubusercontent.com/1154912/135338557-58352d72-0c4e-408f-afb2-b0df46198b5d.mov

coq enabled and tsserver removed from LSP config:
https://user-images.githubusercontent.com/1154912/135338658-25336151-96b0-42e7-bdc3-451dd3968890.mov

❯ nvim --version NVIM v0.6.0-dev+nightly-885-g9ca7b6b71 Build type: Release LuaJIT 2.1.0-beta3 Compiled by [email protected]

Features: +acl +iconv +tui See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/opt/homebrew/Cellar/neovim/HEAD-9ca7b6b/share/nvim"

Run :checkhealth for more info

Let me know if I can provide any additional information that would be useful.

heygarrett avatar Sep 29 '21 19:09 heygarrett

sorry I cant tell from the videos whats happening,

so

  • coq + tsserver -> lag,

  • no coq + tsserver -> no lag

  • coq + no tsserver -> no lag

?


in either case, can you please pull latest and see if it still happens, I implemented a workaround for rlanguageserver sending bad results, and I think it might have affected tserver too (because the workaround needed a fairly slow calculation)

I just pushed some updates to the workaround and hopefully, it will be a good compromise between speed and "workaroundness"

ms-jpq avatar Oct 03 '21 01:10 ms-jpq

Sorry, I should have been more descriptive! In each of the three videos I'm entering insert mode with a, typing a space and then exiting insert mode with <esc> (or <c-[>). But yes, only when both coq and tsserver are enabled do I get lag.

Unfortunately I'm not seeing any difference after pulling the latest changes, but I just noticed something else after reproducing the issue with a minimal init file:

local install_path = vim.fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim'
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
	vim.fn.system({'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path})
	vim.api.nvim_command('packadd packer.nvim')
end

require('packer').startup({
	function(use)
		use 'wbthomason/packer.nvim'
		use 'neovim/nvim-lspconfig'
		use {'ms-jpq/coq_nvim', branch = 'coq', run = ':COQdeps'}
	end
})

vim.g.coq_settings = {
	auto_start = true,
}

require('coq')

require('lspconfig').tsserver.setup{}

vim.opt.number = true
vim.opt.signcolumn = 'yes'

If I don't exit insert mode right away the completion menu opens after a similar amount of lag time (after which I can exit insert mode without lag):

https://user-images.githubusercontent.com/1154912/135759171-d4c4fa5b-437e-4d98-83ea-508737e3beb8.mov

I don't see the completion menu pop up at all with my regular config.

heygarrett avatar Oct 03 '21 14:10 heygarrett

I'm seeing the same issue where it often freezes as I start typing Here are my settings. I am using neovim nightly and commit 6712db48a8c90580e327ce16fcfa4eb74c58ef69 of coq_nvim if that affects things.

lsp.eslint.setup(coq.lsp_ensure_capabilities{
  settings = {
    codeAction = {
      disableRuleComment = {
        enable = true,
        location = "separateLine"
      },
      showDocumentation = {
        enable = true,
      },
    },
    codeActionOnSave = {
      enable = true,
      mode = "all",
    },
    packageManager = "yarn",
    quiet = true,
  },
})
lsp.tsserver.setup(coq.lsp_ensure_capabilities{
  flags = {
    debounce_text_changes = 500;
  },
})

vim.g.coq_settings = {
  auto_start = 'shut-up',
  xdg = true,
  clients = {
    lsp = {
      resolve_timeout = 0.02,
    },
    tree_sitter = {
      slow_threshold = 0.025,
    },
    buffers = {
      match_syms = true,
      same_filetype = true,
    },
  },
  limits = {
    completion_auto_timeout = 0.05,
  },
}

Looking at htop and it is the python process running coq that's blocking. It pretty solidly uses ~100% cpu for quite a while (I've measured up to 30 seconds). I've disabled treesitter and removed snippets to see if that helped to no noticeable impact.

ruler501 avatar Dec 24 '21 19:12 ruler501

@ruler501 did you figure what was happening? I am having this problem and at times the editor is completely unusable and using 100% CPU with a python process.

academo avatar Mar 31 '22 09:03 academo

I have this same issue, and seems like I can reproduce it 100% of the time like this:

(Requires cdktf for project bootstrapping and npm)

mkdir coq-freeze-sample
cd coq-freeze-sample
cdktf init --template=typescript --local # accept the defaults by hitting enter a few times
npm install @cdktf/provider-aws
nvim

Then open main.ts, and type in anything random slowly and press <esc>. nvim should freeze, if it didn't then enter insert mode again and type random stuff in and press <esc> again.

You should see some processes starting to take ~100% of the CPU:

image

Unfortunately I don't know how to debug this further :/.

Settings:

local nvim_lsp = require('lspconfig')
vim.g.coq_settings = { auto_start = 'shut-up' }
local coq = require 'coq'

local servers = { 'jsonnet_ls', 'gopls', 'tsserver', 'eslint', 'terraformls', 'hls' }
for _, lsp in ipairs(servers) do
  nvim_lsp[lsp].setup(coq.lsp_ensure_capabilities({
    flags = {
      debounce_text_changes = 500
    }
  }))
end

weeezes avatar May 23 '22 07:05 weeezes

I was having the same issue, things would just freeze for half a second when i started typing, i switched to nvim-cmp and it's blazing fast now. i recommend doing the same as this issue is 1 year old already

brenoprata10 avatar Jul 01 '22 07:07 brenoprata10

I'm also seeing this issue, having moved to coq from nvim-cmp because it was too slow.

I wonder if it's something to do with the fact that TSServer is quite slow, and so that's leaking into coq itself.

I really want to use this, but it's going to be a deal breaker for me if it keeps locking up my IDE like it does currently.

Some maintainer insight on this issue would be fantastic.

scallaway avatar Sep 12 '22 16:09 scallaway

The original issue was caused by a bad cancellation implementation that I never fixed until recently, and since then I rewrote the entire API client https://github.com/ms-jpq/coq_nvim/pull/520 and adjusted the indexer to perform more incremental indexing as well.

Please re-open if this still persists.

ms-jpq avatar Sep 18 '22 06:09 ms-jpq

Can confirm it's fixed by https://github.com/ms-jpq/coq_nvim/pull/520 , amazing work 🎉 ! Thank you!

weeezes avatar Sep 23 '22 05:09 weeezes

thank you so much @ms-jpq! i had wanted to switch to this from nvim-cmp for several months but this was the only blocker. a lot of small things that bother me in nvim-cmp do not exist with coq_nvim!

azuline avatar Sep 26 '22 23:09 azuline