You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: generate imports when copying code between files #66236
In eclipse Java editing, copying a code snippet from a class to another also automatically copies the imports required by the copied code.
Would be nice to have this in VS Code for typescript as well. Currently when I copy some code, I have to manually resolve the imports afterwards.
This feature is amazing in Webstorm / IntelliJ. It's one of the biggest things I miss coming from there.
I was actually doing some research into how pasteboard works in macOS at least (and the metadata that can live in it. formatting etc.). It's complicated. I think it might be possible to keep that metadata in vscode though and make the implementation easier to be cross OS usable:
When you do a copy, the string goes into the "ANY_OS" clipboard.
VSCode simultaenteouly stores the AST metadata (or however it works, need to check that part out) about that code in memory in the vscode process along with the associated string.
If you paste that string in vscode, vscode looks to see if it has any metadata for that string stored in it's process. If it does it uses the stored metadata to do any applicable imports.
I might see if I can pull this off as I love the direction of vscode but I sorely need this to reach the productivity I've enjoyed in IntelliJ...
Reacted by Nimo Beeren, Dmytro Antoshkiv and Alexander Nosov
I've been wondering about this every now and then and today finally decided to search for a way to do this on the web. This would really be a cool thing to have. I was actually thinking of simply triggering the import all missing modules code action after paste if that's somehow possible. Otherwise it's just a few more keystrokes but still ^^'
Activity
vscodebot commentedon Jan 8, 2019
(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:
mjbvz commentedon May 22, 2019
Needs api proposed in #30066
johnculviner commentedon May 22, 2019
This feature is amazing in Webstorm / IntelliJ. It's one of the biggest things I miss coming from there.
I was actually doing some research into how pasteboard works in macOS at least (and the metadata that can live in it. formatting etc.). It's complicated. I think it might be possible to keep that metadata in vscode though and make the implementation easier to be cross OS usable:
I might see if I can pull this off as I love the direction of vscode but I sorely need this to reach the productivity I've enjoyed in IntelliJ...
olegKusov commentedon Aug 16, 2021
IgnusG commentedon Jan 8, 2022
I've been wondering about this every now and then and today finally decided to search for a way to do this on the web. This would really be a cool thing to have. I was actually thinking of simply triggering the import all missing modules code action after paste if that's somehow possible. Otherwise it's just a few more keystrokes but still ^^'
Kogs commentedon Apr 7, 2022
dongzhuoyao commentedon Jul 24, 2022
mjbvz commentedon Aug 4, 2022
Opened microsoft/TypeScript#50187 to track this upstream