Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring along imports when copy and pasting code across files #5119

Open
patrick91 opened this issue Nov 15, 2023 · 3 comments
Open

Bring along imports when copy and pasting code across files #5119

patrick91 opened this issue Nov 15, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@patrick91
Copy link

Example:

import datetime
import json

def get_current_datetime_info() -> str:
    now = datetime.datetime.now()

    data = {
        "date": now.strftime("%Y-%m-%d"),
        "time": now.strftime("%H:%M:%S"),
        "message": "Hello, world!"
    }

    return json.dumps(data, indent=4)

if I copy this snippet or any line code that uses one some of the imports it would be nice to get the imports where we paste those lines.

There's the same request for TS here: microsoft/TypeScript#50187

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Nov 15, 2023
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Nov 15, 2023
@debonte
Copy link
Contributor

debonte commented Nov 15, 2023

Is this something that we could solve by implementing format on paste? #4342

@patrick91
Copy link
Author

Is this something that we could solve by implementing format on paste? #4342

by finding the required imports? or by remembering the imports? the first one might be trickier since there might be multiple module exporting the same "name"

@bschnurr bschnurr added the enhancement New feature or request label Dec 8, 2023
@bschnurr bschnurr removed their assignment Jan 4, 2024
@debonte debonte removed the needs repro Issue has not been reproduced yet label Mar 1, 2024
@mjbvz
Copy link

mjbvz commented Dec 12, 2024

We just shipped this for JavaScript and TypeScript so I'd love to help get Python support too!

The VS Code API for this is still proposed but I'm tentatively planning to finalize it in January. It's also been relatively stable recently so you should be able to prototype using it.

One potential limitation is that this API is currently only implemented in VS Code and not in the LSP. I have a LSP proposal for this and have also implemented the feature in the markdown language server using custom requests

Let me know if you have any questions about trying the API. Would be really helpful to hear feedback on the API and VS Code UX too


Here are some relevant code references to get started:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants