Skip to content

Feature Request: generate imports when copying code between files #66236

Closed

Description

@Rhobal

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.

Activity

  1. vscodebot commented on Jan 8, 2019

    @vscodebot

    (Experimental duplicate detection)
    Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

  2. mjbvz commented on May 22, 2019

    @mjbvz
    Contributor

    Needs api proposed in #30066

  3. johnculviner commented on May 22, 2019

    @johnculviner

    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...

  4. added this to the Backlog milestone on Oct 21, 2019
  5. olegKusov commented on Aug 16, 2021

    @olegKusov
  6. IgnusG commented on Jan 8, 2022

    @IgnusG

    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 ^^'

  7. Kogs commented on Apr 7, 2022

    @Kogs
  8. dongzhuoyao commented on Jul 24, 2022

    @dongzhuoyao
  9. mjbvz commented on Aug 4, 2022

    @mjbvz
    Contributor

    Opened microsoft/TypeScript#50187 to track this upstream

  10. locked and limited conversation to collaborators on Sep 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requestRequest for new features or functionalityjavascriptJavaScript support issuestypescriptTypescript support issuesupstream-issue-linkedThis is an upstream issue that has been reported upstream

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions