Javascript code not recognised in Intellij IDEA 12 in scala template for Play 2 - intellij-idea

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

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.

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>

Related

Codeception ->see("String") fails but ->seeInSource("String") succeeds

Something is wrong with the AcceptanceTester->see() method for me. It can't see things that are plainly there in the source, as shown by the AcceptanceTester->seeInSource() method.
Here's my test, which runs in PHPBrowser within the WP-Browser implementation of Codeception:
public function testAfricaIsVisible(AcceptanceTester $I) {
$I->amOnPage('/');
$I->seeResponseCodeIs(200);
$I->seeInSource('Africa');
$I->see('Africa');
}
Here's the result I get:
As you can see, ->SeeInSource("Africa") works, but ->see("Africa") fails.
I understand that ->SeeInSource() sometimes "sees" things that ->see() doesn't, but in this case, the word "Africa" is link text that should be clearly visible with or without strip_tags() applied.
In this case, when I open up the Html link the word "Africa" is clearly visible:
Anyone have any idea why Codeception doesn't ->see() this text?
I figured it out. For anyone with a similar problem, the underlying issue was malformed HTML that was glossed over by Chrome/Firefox but screwed up the site as seen by Phpbrowser. I bet if I was using the WebDriver module instead, it would work.
The solution: Use an HTML validation tool and fix the reported syntax errors.
In this case it was a title tag with a single-quote in it, e.g. title='doesn't'

PyCharm: Python template language is stuck on jinja2

The PyCharm parses is complaining about all the colons in my Django template:
The error message it gives is "Expected }}".
This started happening after I created a separate project that has jinja2 templates. That is, it was working fine before, but is now complaining about those colons. So, it is probably something I did to the settings.
I do have the Python Template Language set to Django:
I don't know what else to check.
I just noticed, that the icon next to testfile.html is "J2". This should be HTML. I think the problem is that changing the template language back to Django is not doing anything. PyCharm still thinks it is a jinja2 template. Any help?

This JSFiddle is not loading p5.js correctly

This code I have written in my JSFiddle works well in my computer, and it creates a button and loads a sketch each time I press the button. I "loaded" p5.js, p5.dom.js via CDNJS cause p5.js is not available in the javascript frameworks and extensions options. But the behaviour is not being reproduced correctly. What is wrong with it?
Link: https://jsfiddle.net/truxx/uf7y9meq/5/
I tried:
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.11/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.11/addons/p5.dom.js"></script>
You've got a few things going on here. First of all you should really fix your HTML. You've got mismatched and illegal tags all over the place. Please try to fix all of these problems, and properly format your HTML while you're at it.
It also seems pretty strange that you're trying to mix instance and global mode. Why do you have a setup() and mousePressed() function outside of the sketch function, and another setup() function inside the sketch function? What do you expect that to do?
To fix those problems, you need to choose either instance or global mode. This might require you to rewrite some of your code, but your goal should be to make everything consistent instead of using two different modes in one sketch.

geb jquery.mouseover() not working

The geb documentation shows that it has built in jQuery support. Im interested in one particular method called mouseover. However when I try to use the mouseover function I get a warning saying, "Cannot resolve symbol 'mouseover'". This happens even when I'm using the code in their example. What am I missing?
This might not directly answer your question. But if you are trying to mimic mouse over action in Geb, you could also use
interact {
moveToElement(element)
}
http://www.gebish.org/manual/current/#interact-closures

switching between languages in same file

I recently attended a user group meeting where the IntelliJ representative was demonstrating version 13.
He demonstrated how to switch the code completion view of a file. I do not exactly remember what the file extension of this particular file was, probably java.
The concept was that if the file is html with embedded javascript he could then switch the code completion between html and javascript with a shortcut. If he says treat the file as html then all code in file was treated for code completion purposes as html, and vice versa for javascript.
Does anybody know what shortcut he might have been using to enable the language switch?
Sounds like you may be referring to the IntelliLang feature. IntelliJ IDEA can be aware of other languages embedded within a file.
A simple example is in an HTML file that has CSS and JavaScript.
Notice when I am inside the HTML markup:
or inside an HTML element:
The code complete shows HTML completion options. However, when I am inside the style attribute, I get CSS code completion:
I also get CSS code completion if I am inside a <style> element. So even though I am in an HTML file, I see CSS code completion because of my location.
Same case with JavaScript. When I invoke code completion inside a <script> element, I get JavaScript completion, even though I am in an HTML file.
Anytime IntelliJ IDEA can determine that another embedded language is present, it provides, via IntelliLang, the appropriate syntax highlighting, error highlighting, and code completion. The same holds true for Java. Notice here that IDEA knows the method I am competing takes an SQL statement and therefore highlights the String value using SQL highlighting, and provides SQL code completion:
So even though I am in a .java file, I get SQL code completion. The reason is that IntelliLang comes pre-configured knowing the embedded language of some methods. You modify them, or add more, in File > Settings > [Project Settings] > Language Injections.
In addition, you can use an annotation to tell IntelliJ IDEA (as well as developers looking at the code) that a String must be valid in a particular language. For example, I can annotate a String field, variable, or parameter, to indicate it must be valid HTML:
Notice I get HTML syntax highlighting, HTML code completions, and the CSS color shows in the left gutter. If I annotate a method parameter, then any time I call the method, I get the appropriate syntax highlighting, code completion, and error/warning highlighting:
The #Language annotation is inside the annotations.jar that is contained in the redist directory inside the IntelliJ IDEA installation directory. It is also available in maven central, or IDEA will offer to attach it as a Library if you use the annotation without it being attached.
IntelliLang and the #Language annotation supports a large number of languages. Just use code Completion inside the quotes after typing #Language("") to see a list. (Inline search works in the list as well.) One of the most useful is Regexp. For example, if you have a method that expects the string passed in to be a valid Regular Expression, annotating it as such will give anyone that calls it Regex code completion and error highlighting if they are passing in an invalid Regex pattern. Even for developers using other IDEs it is useful as a form of documentation.
As for a shortcut to change the the language on the fly for code completion, the only thing I can think that you might be referring to is the "Inject Language" intention. If I am entering a String value, and I bring up the quick-fix/intention menu via Alt+Enter, I am given an option to inject a language:
If I select that, IntelliJ IDEA will ask me what language I want to use:
After making my selection, IntelliJ IDEA will give me temporary language injection (including code completion) for the selected language.
It also gives me an option to add the #Language annotation for permanent injection.
To the best of my knowledge (as a 10 year IntelliJ IDEA user) that is the only way to switch code completion language types. So hopefully that is what you are looking for. To me, IntelliLang is one of the coolest features in IntelliJ. (It actually started as a third party plug-in and JetBrains then absorbed it into the product.)