Language injection not working

Answered

I added an optional dependency for my plugin, e.g.:

<depends optional="true" config-file="myPluginId-withComFooBar.xml">com.foo.bar</depends>

in the config file I defined the language injection contributor which inject a language defined in other plugin if presen, e.g.:

<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<languageInjectionContributor language="XML" implementationClass="com.foo.bar.MyInjectionContributor" />
</extensions>
</idea-plugin>

I implemented the contributor as described here: https://plugins.jetbrains.com/docs/intellij/language-injection.html#languageinjectioncontributor-and-languageinjectionperformer and I set up a breakpoint to ensure that the instance of the SimpleInjection is returned - and it is returned.

@Override
public @Nullable Injection getInjection(@NotNull PsiElement context) {
if (context instanceof XmlTag) {
XmlTag contextTag = (XmlTag) context;
if ("comfoobar".equals(contextTag.getLocalName())) {
Language myLanguage = Language.findLanguageByID("ComFooBar");
if (myLanguage != null) {
return new SimpleInjection(myLanguage, "", "", null);
}
}
}
return null;
}

The problem is though, that nothing happens in the code, i.e. no highlighting, no formatting, etc. If I right-click and inject language manually via the menu option (I suppose it uses the IntelliLang plugin), I do see the code formatting and highlighting. So what else is missing in my injection contributor?

 

4 comments
Comment actions Permalink

Does the target XML Tag have Language==XML? Can't you use recommended "simple" setup via IntelliLang in your case?

0
Comment actions Permalink

Yes, the target XML tag has language XML, I verified that. 

I tried something else - I implemented a MultiHostInjector and now I do see the code highlighting, but the formatting still does not work - I suspect it's because instead of a single .addPlace I called .addPlace for all children of my XmlText. 

I'll try a "simple" setup too, maybe you are right, it is a better way.

0
Comment actions Permalink

I tried the IntelliLang approach but it cannot find my injections config file. In my plugin.xml it looks like this:

<extensions defaultExtensionNs="org.intellij.intelliLang">
<injectionConfig config="foobarInjections.xml"/>
</extensions>

and I placed the file in the same place as the plugin.xml, i.e. in resources/META-INF. 

0
Comment actions Permalink

nm, I realized my path was wrong, everything looks good now, thank you!

 

0

Please sign in to leave a comment.