Autocomplete delimiters used for Multihost Injection with JSInjectionBracesUtil

Answered

I've successfully injected JS into an HTML like language using the MultihostInjector and the following code.

if (context instanceof XmlTextImpl || context instanceof XmlAttributeValueImpl) {
JSInjectionBracesUtil.injectInXmlTextByDelimiters(registrar, context, JavascriptLanguage.INSTANCE, "${", "}");
}

I would also like to auto complete the } character when you type ${ inside my html like file. I haven't written a custom language I'm simply extending XmlLikeFileType and using super(HTMLLanguage.INSTANCE) in the contructor.

I'm a bit unsure of where to start looking in order to accomplish this. Any help would be greatly appreciated.

Thanks!

Charlie

0
4 comments
Official comment

com.intellij.codeInsight.editorActions.TypedHandlerDelegate#charTyped allows you to modify/insert anything after specific char was inserted. see MavenTypedHandlerDelegate as sample for your use case.

Thanks Yann! This is almost exactly what I needed. Modifying it a bit to look at my language type did the trick. I did however discover an issue with the JS injection util. I'm wondering if it's something I'm doing wrong or if it's a bug with the Brace Util itself.

 

JSInjectionBracesUtil.injectInXmlTextByDelimiters(registrar, context, JavascriptLanguage.INSTANCE, "${", "}");

If I type the following I get an error in my Javascript because my empty object can never be completed. Same happens with a function definition etc... that uses braces.

${var test = {}}

You can see the full code snippet here.

https://github.com/nek4life/sfcc-studio/blob/develop/src/main/java/com/binarysushi/studio/language/isml/ISMLScriptInjector.java

If I should create a new topic or file a bug, please let me know.

 

 

0

it seems this might be a bug indeed, could you please file an issue https://youtrack.jetbrains.com/issues/WEB Thanks!

0

Thanks! I've filed the issue.

0

Please sign in to leave a comment.