13
votes

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>
1
Alt+Enter, Inject Language, JavaScript?CrazyCoder

1 Answers

13
votes

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:

before

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:

setting

Be sure to choose correct namespace. After this, the same code looks like this (expect some minor delay after opening a file):

after

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 :)