on Paste code - suggest imports(custom lang implementation)

on Paste code - suggest imports(custom lang implementation)

I was searching for it in code and descriptor, PasteProvider, CopyPasteReferenceProcessor,CopyPastePostProcessor, but still can't figure out which class should I implement and how to make it work.

How to achieve such functionality with dialog?

5 comments
Comment actions Permalink

For Java it's done using custom CopyPastePostProcessor implementation (JavaCopyPasteReferenceProcessor) - an entity which can extract additional data from source on copy and apply them to target on paste.  You can write something similar for your language, potentially extending CopyPasteReferenceProcessor base class, if it will fit your needs.

0
Comment actions Permalink

I seen that class,
how to add implementation for it?

<copyPastePostProcessor?

0
Comment actions Permalink

I found this:

<copyPastePostProcessor
implementation=
"org.jetbrains.plugins.groovy.editor.GroovyReferenceCopyPasteProcessor"
/>


JavaCopyPasteReferenceProcessor extends CopyPasteReferenceProcessor<PsiJavaCodeReferenceElement>
I seen PsiJavaCodeReferenceElementImpl, it looks pretty complicated, despite implementation for language I am working on seems to me pretty straightforward.

So I don't get idea of this class.


I tried before something, but it seems like "addReference" was handled when I used to copy text in IDEA

@Override
protected void restoreReferences(ReferenceData[] referenceData,

PsiJavaCodeReferenceElement[] refs)


I guess this method should be called on paste

0
Comment actions Permalink

Yes, just like any extension is added - see
https://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Plugin+Structure#IntelliJIDEAPluginStructure-PluginExtensions.

You don't need to extend CopyPasteReferenceProcessor, you can write an implementation of CopyPastePostProcessor yourselves.

0
Comment actions Permalink

Thanks, it was tough but I did it.

0

Please sign in to leave a comment.