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

Add import on file drag/drop #50170

Open
mjbvz opened this issue Aug 3, 2022 · 4 comments
Open

Add import on file drag/drop #50170

mjbvz opened this issue Aug 3, 2022 · 4 comments
Assignees
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Aug 3, 2022

Suggestion

From microsoft/vscode#5240

🔍 Search Terms

  • drop
  • dnd
  • import
  • require

⭐ Suggestion

When I drag and drop a file from VS Code's explorer into the top of my TypeScript code, it should insert an import statement

For example if I have the workspace:

index.ts
sub/
    other.ts

And I drop other.ts into index.ts, it should insert:

import $1 from './sub/other'; // here $1 is where the cursor should be after the drop

Other cases

  • I should be able to drag and drop multiple files to create multiple imports

  • Possible: If I drop the file into somewhere else in the file, we should instead insert an import expression

  • The added import path should take into account TypeScript's path resolution logic

  • This also should apply when copy and pasting a file into the editor

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Experience Enhancement Noncontroversial enhancements labels Aug 3, 2022
@mjbvz mjbvz changed the title Add import on file drop Add import on file drop / file copy paste Aug 4, 2022
@DanielRosenwasser
Copy link
Member

Related is #50187, but I guess is not the same. I suppose this needs a custom TSServer command?

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Aug 22, 2024

Some things to discuss/test for:

  • What happens if the module exports just a default? (I'd argue the import style changes)
  • What if the module exports just a default but also some types? (harder, should discuss)
  • What if the import already exists in the file?
  • What happens if the drop location is not suitable for a top-level import? (do we generate a dynamic import()?)
  • What happens if the drop location is in a comment or string-like node?

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Aug 28, 2024

  • Do we do something different if the source file is a .d.ts file?
  • Do we do something different if the target file is a .d.ts file?
  • Do we do something different if the source file is global vs. a module?
  • Do we do something different if the target file is global vs. a module?

@DanielRosenwasser DanielRosenwasser changed the title Add import on file drop / file copy paste Add import on file drag/drop Aug 28, 2024
@mjbvz
Copy link
Contributor Author

mjbvz commented Sep 18, 2024

Followups from today's sync:

  • Experiment with adding imports at the drop location vs adding it to top of the file

  • See if VS Code needs any UI tweaks to support adding imports at a non-cursor location (such as at the top of the file)

  • TS Server can have a single command that VS Code uses to implement both dnd and copy paste of files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants