jose-elias-alvarez / nvim-lsp-ts-utils

Utilities to improve the TypeScript development experience for Neovim's built-in LSP client.
The Unlicense
438 stars 18 forks source link

feat: support source actions #116

Closed jose-elias-alvarez closed 2 years ago

jose-elias-alvarez commented 2 years ago

Will close #100.

I dug through the typescript-language-server code and figured out how to get these to work in Neovim. This is just a preliminary POC. since I want to implement a few more things (commands, sync actions) before merging.

It should be safe to replace the existing organizeImports command with this one, and removeUnused and fixAll are nice additions. The question is what to do with addMissingImports. Our implementation has some nice improvements like priority, but it's quite brittle compared to simply requesting and applying results from a language server. The new one should emulate VS Code behavior, which I think is good enough.

Generally, removing bespoke functionality and shifting it over to the server is a good idea. This may pave the way for a version 2 of this plugin that focuses on easily setting up typescript-language-server and adding commands for convenience.

jose-elias-alvarez commented 2 years ago

Since this technically already works, I'm going to go ahead and merge it as-is. I don't want to add more commands, since there's a lot of overlap between these new source actions and existing commands. Anyone interested can set up their own commands by importing the relevant method from require("nvim-lsp-ts-utils.source_actions").

If you only need the functionality from these actions (which covers a lot of what VS Code can do, interestingly) and want things to work out-of-the-box, you can try typescript.nvim, a new project I'm working on.