Groovy injection into YAMLScalarList

YAML plugin doesn't support injection so I'm implementing custom PsiLanguageInjectionHost for YAMLScalarList.
It is simply a delegate for YAMLScalarList with two additional metods required by injection host - updateText and createLiteralTextEscaper. I've implemented MultiHostInjector using InjectionUtils like in XmlLanguageInjector:

InjectorUtils.registerInjection(GroovyFileType.GROOVY_LANGUAGE, Collections.singletonList(injectionTrinity), context.getContainingFile(), registrar);


Now, intention actions works fine, i.e. variable introduction, but I have problem with editing - when I press Enter, then caret in editor goes to the beginning of injection range or at the end of it. Example:

    script: |<beginning of Groovy injection><caret position after 'enter'>         <caret position before 'enter'>def a = "";<or caret position after 'enter'><end of Groovy injection>

There is no exceptions in IDEA logs.

Could You give me some hints what should I inspect to resolve this problem?

1 comment
Comment actions Permalink

Ok, I've added EnterHandlerDelegate to block DoEnter action for Groovy injection - DoEnter for Yaml is sufficient (it looks like this action is triggered in YAML file and Groovy file which is created for language injection). But intention actions in IDEA 13 does not work properly (for IDEA 12, no problem).
I'm using prefix for language injection, so some intention action which adds text at beggining of document does not work, i.e. replace qualified name with import - stacktrace in introduce_import.txt - it looks like someone add assertions checking prefix and suffix in com.intellij.injected.editor.DocumentWindowImpl#calculateMinEditSequence but forgot about intentions which adds some text at beginning of document, like imports (probably it is a bug in IDEA).
Second problem is with variable introduction action. In IDEA 13 this is done by inplace operation which leads to exceptions (in IDEA 12 by popup - no problems). Inplace variable introduction puts into document placeholders where variable will be introduced and this leads to another exception (see introduce_variable.txt). Maybe this is also a bug in IDEA, but maybe I made some mistakes in my LiteralTextEscaper or in preparing injection host context.
In attachment sources and sample yaml file for testing.
Could someone help me with analysing this problems?

Message was edited by: Marcin Rembała



Attachment(s):
introduce_variable.txt.zip
introduce_import.txt.zip
GroovyInYaml-13.zip
0

Please sign in to leave a comment.