Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

Import type for word under cursor / quick fix? #60

Open
lougreenwood opened this issue Feb 2, 2023 · 3 comments
Open

Import type for word under cursor / quick fix? #60

lougreenwood opened this issue Feb 2, 2023 · 3 comments

Comments

@lougreenwood
Copy link

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!

@jose-elias-alvarez
Copy link
Owner

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

@marcelarie
Copy link

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?

@jose-elias-alvarez
Copy link
Owner

jose-elias-alvarez commented Feb 15, 2023

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants