Extending the code completion

JSEclipse comes with code completion for most of the default libraries (document, system, etc). On top of that, as you work on the project, new libraries are built, specific for the current project, with the functions for each file, variable name and so forth.

To make it even more extendable, you can define your own code completion libraries. That is if you use a particular class in more than one project, you can define the code completion library for it. You simply have to create an XML file based on a specific format, and use the Add library dialog to integrate it with JSEclipse

 

The XML file format

To define a new code completion library you must create an XML file to describe the options to suggest and for which element. To explain it better, let's  create the XML file that will add code completion for the class element which has three methods. For the method names let's use some already existing functions: getElementById, getElementsByTagName and innerHTML.

 

 

 

Integrate the custom library in JSEclipse

To make the defined library available from within Eclipse, you should copy it in a folder within the workspace. The other, simpler way is to use the Add library feature added by JSEclipse. To access it, click on the JSEclipse menu > Add library.
 

 

To add a new library, simply click Browse and select it from the file system. Then click OK and the new code completion will be available from eclipse:

 


 

Note: because the element class was defined as extending the class object, the methods of the object class are suggested for completion as well.