My company uses custom tags in our JSPs to wrap JavaScript. I cannot get IntelliJ to treat the content of these tags as JavaScript. Here is a simple example of what our tag looks like.
<ui:script>
//Include javascript here...
alert('Any code in here is treated as JavaScript');
</ui:script>
Any suggestions? I've tried using Language Injections, but I cannot find the right settings.
I just noticed that the problem is more linked to using JSP-specific language within the <ui:script>
tag. A nastier example (notice the ${selectedReportID} tag that's breaking everything):
<ui:script>
new Kamino.DependencyLoader({
source: [
'/static/js/modules/folders/Report.js'
],
onSuccess: function () {
new Kamino.Report({
id: '${selectedReportID}',
element: 'content-reporting-report-list'
});
}
}).load();
</ui:script>
You can configure language injection rules on the Editor | Language Injections page of the IDE settings Ctrl+Alt+S .
Press Ctrl+Alt+S to open the IDE settings and select Editor | Natural Languages. in the list of languages and select your language.
Though designed primarily for Java development, IntelliJ IDEA understands many other programming languages, including Groovy, Kotlin, Scala, JavaScript, TypeScript, and SQL, and it provides smart coding assistance for each of them.
This is what worked for me in IntelliJ IDEA 12.
Here is the JSP snippet with custom tag (aui:script
) that renders some javascript code:
As you can see, it is plain text, i.e. alt+enter gives no suggestions etc.
Here is the XML Tag Injection I added in Language Injection settings:
Be sure to choose correct namespace. After this, the same code looks like this (expect some minor delay after opening a file):
It is colored differently and, as you can see, the code between aui:script
tags is aware of javascript context, suggestions are available etc.
Please try if this works for you, I haven't use this as much as I would like :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With