Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make eclipse work better with javascript

I'm working in a java/eclipse shop writing javascript, coming from a php/netbeans background. So far, I hate eclipse, but I don't want to shift away from the general tool set. (Because of issues with our build system, we're currently on the galileo release.)

The syntax coloring is just fine, and I'm learning to live with the cockpit-like interface, but eclipse's outliner doesn't properly recognize things like the module pattern at all. Nor does it do much auto-completion on my methods. Can I do anything about that?

I tried installing Aptana, but so far, I haven't noticed any real improvements in basic editing. I see the WTP, which I may or may not have installed. (How do I find out? :) Would that help?

While I'm asking, eclipse does a lousy job with indentation, which I'm constantly having to fix, since I care about such things. Anything to be done about that?

like image 502
sprugman Avatar asked Oct 21 '10 17:10

sprugman


2 Answers

Make sure you have installed JavaScript developer tools. See Help / About Eclipse / WTP (one of the icons at the bottom of dialog) / JavaScript Developer Tools feature

Then on your web project Project / Properties / Project Facets page and make sure JavaScript Toolkit facet is selected. After that you should see JavaScript / Code Style / Formatter page as well as other advanced pages, such as, Libraries, Validation, etc.

like image 191
Eugene Kuleshov Avatar answered Nov 15 '22 08:11

Eugene Kuleshov


Use JSdoc. It will give you back outline and autocomplete! Saved my life the other day...

/**
 * @type MyModule
 * @memberOf __MyModule
 */
var MyModule = (/** @constructor */ function () {
  function innerFunc() {
    // blub
  }

  /**
   * @memberOf MyModule
   */
  api.publicFunc = function() {
    // gak
  };
})();
  • @type MyModule is mandatory and should be the same as your real module name.
  • @memberOf MyModule and /** @constructor */ at closure function is used to display inner functions and variables inside module closure (i.e. innerFunc()). If you use the same 'type' here as in the @type definition the public functions will be listed in the same outline in Eclipse. Alternatively we can use some other name (here __MyModule and get a separate 'outline tree' for the public methods.
  • @memberOf module binds the API's methods to your module/type and will make them appear in the outline as well as the auto-complete context-menu (after typing MyModule.| for example).

(Original Idea from http://www.eclipse.org/forums/index.php/m/665434/)

like image 35
fgysin Avatar answered Nov 15 '22 06:11

fgysin