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

Automatically trigger auto-import on paste #1075

Closed
fbricon opened this issue Sep 23, 2019 · 4 comments
Closed

Automatically trigger auto-import on paste #1075

fbricon opened this issue Sep 23, 2019 · 4 comments
Assignees

Comments

@fbricon
Copy link
Collaborator

fbricon commented Sep 23, 2019

When pasting some code snippets into an empty class file, it'd be nice if auto-import was triggered automatically. I'm not sure vscode exposes APIs to hook into the paste action. It looks like other extensions do it in a very hacky way (hijack the general paste command).
Anyways, I thought it could be an interesting feature.
@snjeza could please look into it and report about potential implementations?

@fbricon fbricon changed the title Automatically trigger auto-import of paste Automatically trigger auto-import on paste Sep 23, 2019
@snjeza snjeza assigned NikolasKomonen and unassigned snjeza Sep 23, 2019
@NikolasKomonen
Copy link
Contributor

Somewhat related issue: microsoft/vscode#66236

@fbricon fbricon added this to the Mid October 2019 milestone Oct 3, 2019
NikolasKomonen added a commit to NikolasKomonen/vscode-java that referenced this issue Oct 11, 2019
Issue redhat-developer#1075

New preference: java.paste.organizeImportsOnPaste

Signed-off-by: Nikolas Komonen <[email protected]>
fbricon pushed a commit that referenced this issue Oct 14, 2019
Issue #1075

New preference: java.paste.organizeImportsOnPaste

Signed-off-by: Nikolas Komonen <[email protected]>
@fbricon fbricon closed this as completed Oct 14, 2019
@fbricon
Copy link
Collaborator Author

fbricon commented Oct 14, 2019

The new feature is enabled via the java.actionsOnPaste.organizeImports preference in vscode preferences. If true (the default value), triggers "Organize imports" when java code is pasted into an empty file.

@Palidino
Copy link

Sorry for asking here, but is there a way to enable this just from typing in general? I added a field and got a cannot be resolved error. Normally I would hover and do quick-fix, but I noticed selecting the line, and then copying and pasting the line over itself imports the missing class.

@fbricon
Copy link
Collaborator Author

fbricon commented Oct 21, 2019

@Palidino you can either press Alt+Shift+o to trigger the "organize imports" command, or set "java.saveActions.organizeImports": true in your preferences and then save your java file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants