pmizio / typescript-tools.nvim

⚡ TypeScript integration NeoVim deserves ⚡
MIT License
1.45k stars 40 forks source link

Restarting tsserver breaks "TSToolsRemoveUnusedImports" #268

Closed redsuperbat closed 3 months ago

redsuperbat commented 4 months ago

I use this autocmd which works really well. However when I restart the tsserver and then save the file the autocmd breaks.

This is the autocmd:

-- Remove unused import on save
vim.api.nvim_create_autocmd("BufWritePre", {
  pattern = "*.ts*",
  command = ":TSToolsRemoveUnusedImports sync",
})

This is the error:

Error detected while processing BufWritePre Autocommands for "*.ts*":
Error executing Lua callback: .../lazy/typescript-tools.nvim/lua/typescript-tools/api.lua:60: attempt to index local 'res' (a nil value)
stack traceback:
        .../lazy/typescript-tools.nvim/lua/typescript-tools/api.lua:60: in function 'organize_imports_mode'
        .../lazy/typescript-tools.nvim/lua/typescript-tools/api.lua:78: in function 'remove_unused_imports'
        ...script-tools.nvim/lua/typescript-tools/user_commands.lua:36: in function 'fn'

Restarting neovim fixes this issue, but it would be nice not to have to restart neovim every time I want to restart the lsp.

KostkaBrukowa commented 3 months ago

Hmm... is this still an issue? I've tried this with my config and nothig breaks. And how do you restart tsserver? With :LspRestart?

KostkaBrukowa commented 3 months ago

Or if you are using nightly this might help: https://github.com/pmizio/typescript-tools.nvim/pull/275

redsuperbat commented 3 months ago

Hi! Thanks for looking into it, yes I was using nightly. However I switched from it since it was messing up my workflow :) Seems like you found the issue, great! 🚀