Sunday, October 20, 2013

Smarter support for dojo in IntelliJ/WebStorm with Needs More Dojo 0.6

The next version of Needs More Dojo makes many enhancements to IntelliJ IDEA, WebStorm, etc. to provide better integration with Dojo. Personally, I've really enjoyed working on this version and can't wait to get it out the door!

1. this.inherited resolution

If you've ever used Navigate ... Declaration (Ctrl+B) to see the super method of a Dojo module, you would be greeted with this:
Basically: a lot of this.inherited references
It's not really the IDE's fault, as that would require knowledge of Dojo's custom OO model which of course it doesn't have. Luckily, Needs More Dojo does have that knowledge. Now when you use Ctrl+B, Needs More Dojo will navigate the dependency graph in your declare(...) block and search for methods that match. Here's what you get instead:
Much better!
2. Method resolution

After adding support for this.inherited resolution, it was easy to add method resolution as well. IntelliJ does a surprisingly good job of resolving methods in JavaScript, but there are still cases it will miss. For example, if you try to resolve domStyle.set(...) you will get this:

A very incorrect list of set methods
Once again, not really the IDE's fault. With Needs More Dojo, you won't get a list at all. Instead, you will navigate to the set method of dom-style.js.

3. AMD module resolution

This is one of my favorite new features. Let's say you have imported a module and you want to jump to its source file. By default, if you Ctrl+Click on query for example in this block of code: 

define([
    'dojo/query'
], function(query) {
    var results = query('.foo');
});

You will get directed to to the "query" parameter. Not very useful. With Needs More Dojo, it will resolve query.js and send you there. Of course this works for your modules as well, and relative or absolute path syntax.

4. Require blocks and embedded scripts

In this version, you have all AMD management functionality available for require blocks, nested or otherwise. In addition, you have all Needs More Dojo functionality available in embedded scripts in HTML, jsp, php, etc. files. You can configure the list of supported file types in the settings dialog.

Refactoring has been updated to take require blocks into account as well.

5. Quick fixes

Finally, there are several quick-fixes for existing functionality that are now available. For example, if you have an unused import, you get three quick-fixes listed:

As I said, this version has been very exciting to work on. There are some other new changes I didn't add here, but you can see the full list of things that were added on the GitHub issue page. 

I expect to spend a couple of weeks testing this version, so expect it to be released in 2-3 weeks.