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

On paste: Add required imports #4

Open
pocmo opened this issue Sep 15, 2020 · 3 comments
Open

On paste: Add required imports #4

pocmo opened this issue Sep 15, 2020 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed plugin Issues about the IntelliJ IDEA / Android Studio plugin.

Comments

@pocmo
Copy link
Owner

pocmo commented Sep 15, 2020

Currently when pasting with the plugin we only add the code. But we can also add the required imports to the list of import statements (e.g. import androidx.compose.foundation.Text).

From reading the code of the Kotlin language plugin, I was expecting something like this to work:

val import = KtPsiFactory(project, true).createImportDirective(
    ImportPath(FqName("androidx.compose.foundation.Text"), false)
)

val target = PsiDocumentManager.getInstance(project).getPsiFile(editor.document) as KtFile
target.importList!!.imports.add(import)

But I end up with the following error:

e: recompose/recompose-idea/src/main/kotlin/recompose/plugin/copypaste/RecomposeCopyPasteProcessor.kt: (101, 16): Cannot access 'com.intellij.psi.PsiClassOwner' which is a supertype of 'org.jetbrains.kotlin.psi.KtFile'. Check your module classpath for missing or conflicting dependencies
e: recompose/recompose-idea/src/main/kotlin/recompose/plugin/copypaste/RecomposeCopyPasteProcessor.kt: (101, 16): Cannot access 'com.intellij.psi.PsiModifiableCodeBlock' which is a supertype of 'org.jetbrains.kotlin.psi.KtFile'. Check your module classpath for missing or conflicting dependencies

I am not sure how to get access to those super types?

@pocmo pocmo added enhancement New feature or request plugin Issues about the IntelliJ IDEA / Android Studio plugin. labels Sep 15, 2020
@pocmo pocmo added the help wanted Extra attention is needed label Sep 23, 2020
@pocmo pocmo added this to the Shipping plugin milestone Oct 2, 2020
@t-regbs
Copy link
Contributor

t-regbs commented Oct 14, 2020

Hi, did you try adding java plugin to recompose-idea?

@t-regbs
Copy link
Contributor

t-regbs commented Oct 14, 2020

I just tried it and adding java plugin gets access to the super types.
How do you suggest adding the imports be implemented? I'd like to work on that.

@pocmo
Copy link
Owner Author

pocmo commented Oct 19, 2020

@t-regbs Oh cool! Can you share a PR that adds the java plugin? If you (only locally) hack the lines above into the plugin, do the imports get added?

nordfalk added a commit to nordfalk/recompose that referenced this issue May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed plugin Issues about the IntelliJ IDEA / Android Studio plugin.
Projects
None yet
Development

No branches or pull requests

2 participants