Effective Smart Completion for JavaScript

Many modern IDEs offer a smart completion feature: when the programmer enters an expression e followed by a dot character, the IDE offers a list of properties available on e to complete the expression. For statically typed languages, this list is easily computed from the type of e and the class hierarchy. In JavaScript, the same problem is much more challenging, since expressions are not statically typed and object properties may change over time. The problem is exacerbated by the common use of complex framework libraries like jQuery and native libraries like the browser DOM.

We present a novel approach to JavaScript smart completion based on combining static and dynamic analysis. Completions are computed using a static pointer analysis enhanced with support for usage-based property inference. Frameworks are handled using a fully automatic dynamic analysis which infers API models based on the framework's test suite. We have implemented our approach in a tool called Pythia and evaluated it on a set of real-world JavaScript programs. On average, Pythia was able to suggest the desired property name 88% of the time, compared to 63% for the best open-source completion engine.

By: Max Schäfer, Manu Sridharan, Julian Dolby, Frank Tip

Published in: RC25359 in 2013

rc25359.pdf

Questions about this service can be mailed to reports@us.ibm.com .