December 06, 2005

IntelliJ IDEA 6.0 "Demetra": JavaScript navigation and completion

Unlike all features I described previously, this one has parts of my work in its implementation. Before we committed to improving the UI designer and I was assigned to that project, I spent some time on foundation work for the new JavaScript support. After I switched to UI designer development, the JavaScript plugin was picked up by Maxim Mossienko, and he greatly improved upon my foundation and implemented many new features on top of it.

The key thing that we added in Demetra is cross-file navigation and resolve. The JavaScript plugin builds an index of all functions and variables in the project, and uses it for resolving references. We spent some time discussing the possibility of implementing a type inference algorithm to make the plugin aware of specific object types that can be contained in each variable, but then we decided that a huge amount of work is required to make this feature really useful, and it will not work in all cases anyway, because of the very dynamic nature of the language. Because of this, the current reference resolution algorithm is based only on method names. Also, we have not yet added any scoping rules – we assume that all JavaScript code is visible from anywhere in the project.

The JavaScript symbol index is currently stored only in memory and rebuilt on every project open. Later we plan to provide the possibility to make this index persistent (possibly reusing our existing Java repository) and correctly updatable. Of course, all these facilities will be available to other custom languages as well.

The first feature based on the new index, and the only one I implemented myself, is “Goto Symbol”:

During testing we have found out that different large-scale JavaScript libraries use different styles of assigning functions to object properties, and the plugin should currently be aware of all commonly-used ones.

“Goto Definition” for cross-file references was added by Maxim. The “Show Implementations” feature is based on the same underlying mechanism but is easier to show on a screenshot, so I’ll use that to demonstrate the feature.

The new symbol index is also used for completion:

(Speaking of JavaScript, yesterday we started a Companion Products program, and one of the products offered in it is Inspection-JS by Sixth and Red River Software. Inspection-JS is a plugin for IntelliJ IDEA 5.0 which can detect many common programming errors in JavaScript code, and provides quick fixes for a number of the errors. You can learn more about the Companion Products program from a blog post by Alex Tkachman, the Marketing Director of JetBrains.)

Posted by Dmitry Jemerov at December 6, 2005 09:40 PM
Comments
Post a comment









Remember personal info?