typescript.nvim icon indicating copy to clipboard operation
typescript.nvim copied to clipboard

Import type for word under cursor / quick fix?

Open lougreenwood opened this issue 2 years ago • 3 comments

VSCode has a neat feature which allows importing the specific type for the thing under the cursor via quick fix:

Screenshot 2023-02-02 at 07 37 21

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!

lougreenwood avatar Feb 02 '23 07:02 lougreenwood

Thankfully this is standard LSP behavior - you should be able to do this by running :lua vim.lsp.buf.code_action().

jose-elias-alvarez avatar Feb 03 '23 04:02 jose-elias-alvarez

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?

marcelarie avatar Feb 14 '23 20:02 marcelarie

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.

jose-elias-alvarez avatar Feb 15 '23 00:02 jose-elias-alvarez