4

I just installed the recently released Intellij IDEA 12, which is GREAT for Play Framework 2.

However, I'm having the following issue: in an HTML Scala template, any JavaScript code enclosed in a <script> tag within the body of the template is not recognised as JavaScript by IDEA, thus not offering code completion and incorrectly showing errors where they aren't. I suspect it is interpreting the code as Scala code, ergo offering incorrect code completion and making it quite painful to write JS in a template.

This issue was not present in IDEA 11.

Any ideas?

Update

I have the JavaScript Support plugin enabled. Simple code completion works fine. However, if I type function (){} to code an anonymous function and hit Enter with the caret between the curly brackets, IDEA does the following:

enter image description here

If I manually fix the incorrectly added }, and write code for the anonymous function, it offers correct variable suggestion for the console.log although it is stil showing errors:

enter image description here

monsieurBelbo
  • 727
  • 1
  • 8
  • 16

2 Answers2

2

I can't confirm that, I can see that both, Scala and JavaScript completion works properly.

Go to Settings > Plugins and make sure that you have JavaScript Support enabled. After that close and reopen all your views to let the Idea analize syntax once again.

enter image description here

biesior
  • 55,576
  • 10
  • 125
  • 182
  • I have the `JavaScript Support` plugin enabled, and your example works fine. However, try to code an anonymous function, or any code that has `{}` and unexpected errors will be marked. Check out the update to the question. – monsieurBelbo Dec 10 '12 at 14:05
  • It seems that your anonymous function declaration is invalid :) http://stackoverflow.com/q/1634268/1066240 – biesior Dec 10 '12 at 14:28
  • I've tried all the possible ways of declaring an anonymous function stated on that question. However, the errors ("Missing }", "Wrong top statement declaration") persist. I strongly suspect it has to do with the curly brackets and most probably some configuration issue. – monsieurBelbo Dec 10 '12 at 14:46
  • 1
    Actually, I copied some advanced JS from *.js file into template and indeed I can confirm problems with validation. Usually I'm trying to keep JS in own files, so maybe it will help you as well. – biesior Dec 10 '12 at 15:05
1

It appears that your function statement is invalid because you did not name your function. The details of what is going on here are answered in this post. I'm not sure of the details of your particular needs, but you might try this syntax instead:

<script>
    (function() {

    })();
</script>
Community
  • 1
  • 1
ngreen
  • 1,559
  • 13
  • 22