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

Allow pasting a Java file into the file explorer #3323

Closed
Artur- opened this issue Sep 28, 2023 · 4 comments
Closed

Allow pasting a Java file into the file explorer #3323

Artur- opened this issue Sep 28, 2023 · 4 comments

Comments

@Artur-
Copy link

Artur- commented Sep 28, 2023

A handy way to get a java file from an external source into the project is to copy the source (not the file) and then paste it in the file tree. This has "always" worked in Eclipse and it would be great to have it working also in VS Code.

When pasting into a Java source folder, the file should be placed in the correct package (not the folder it is pasted in) and named according to a public Java class in the snippet.

So pasting e.g. this

package foo.bar.baz;

public class HelloWorld {
}

into src/main/java in a Maven project should create src/main/java/foo/bar/baz/HelloWorld.java

Environment
  • Operating System: mac
  • JDK version: 21
  • Visual Studio Code version: 1.82.2
  • Java extension version: 1.22.1
Steps To Reproduce
  1. Copy
  2. Paste
Current Result

Nothing happens when you paste a Java snippet into the explorer

Expected Result

As described above

@rgrunber
Copy link
Member

Agreed. I really like that feature. Especiall that it creates the folder structure defined by the package ... declaration of the code sample (if present). I don't think we can use VS Code's experimental document paste API. That requires a document to be opened. Maybe we could create some key binding around ctrl+v or ctrl+shift+v and accessing https://code.visualstudio.com/api/references/vscode-api#Clipboard . Once we have the file, the invisible project support should be enough to handle the rest.

@rgrunber rgrunber moved this to 📋 Backlog in IDE Cloudaptors Oct 18, 2023
@hopehadfield hopehadfield moved this from 📋 Backlog to 🏗 In progress in IDE Cloudaptors Nov 8, 2023
@hopehadfield
Copy link
Contributor

This feature is currently in the works. When a java text is pasted in the file explorer using ctrl + shift + v, a file is created containing that text and named using the declared type name. It is also added to the appropriate package based on the package name at the top.

Peek 2023-11-10 14-22

This feature extends to when the language server is not already running, though it works with some delay for the server to get started.

Peek 2023-11-10 14-26

When there is no project currently open, the file is placed in a tmp folder in the user's home directory. The following gif also exemplifies the creation of a folder according to the package name if it does not already exist.

Peek 2023-11-10 14-24

There is still some work to be done, particularly with packages. The search for a matching package name is very minimal right now.

@fbricon
Copy link
Collaborator

fbricon commented Nov 22, 2023

@hopehadfield make sure this feature (including overriding the paste shortcut itself) can be disabled via a setting

@rgrunber
Copy link
Member

Change will end up in the pre-releases. Note that from discussions, we've decided to not enable this feature when no workspace folders are opened. However we could do this if needed.

There's still the case of an invisible project where a file isn't open. Pasting has to wait until the language server is ready. I think we should have a client-side check while the language server is starting to avoid delays.

@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in IDE Cloudaptors Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

4 participants