typescript.nvim
typescript.nvim copied to clipboard
Import type for word under cursor / quick fix?
VSCode has a neat feature which allows importing the specific type for the thing under the cursor via quick fix:
Whilst I notice that whilst this add-on can fix all imports in a file, it doesn't surface quick fixes for each individual missing import.
Is this possible? I wonder if maybe VSCode has some extra magic/private TS LSP APIs available to it which allow it to infer the import path for what looks like an undefined type.
Also, thanks for the amazing work on this!
Thankfully this is standard LSP behavior - you should be able to do this by running :lua vim.lsp.buf.code_action().
There is a code action for that, but in nvim-lsp-ts-utils we had the TSLspImportCurrent command, to import only the package under the cursor. @jose-elias-alvarez will this be available on typescript.nvim?
The equivalent code in nvim-lsp-ts-utils was quite hacky, so there's no clean way to port it over.
Theoretically, what we could do here is filter the returned list of edits before applying them, but the goal of this plugin is to integrate with the language server, not add more off-spec functionality. If you're interested, I think this type of thing would be best implemented upstream.