5

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?

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm not entirely sure where the "Project Facets" page is, but when I go into Project > Properties, I see both JavaScript and JS Code Formatter, both with about ten thousand options in them....
If you have both WTP and Aptana installed you may see more then one JavaScript editor and multiple setting pages. I'd recommend to try with a clean Eclipse installation, e.g. download Eclipse IDE for JavaScript Web developers. eclipse.org/downloads/packages/…
3

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/)

7 Comments

Found that a while ago, thanks. It's annoying to have to add @memberOf to every method to get it to show up, but it's better than nothing, I suppose.
Yeah, I haven't yet found any better method though. :/
(FWIW, I haven't been bothering with @type and the @constructor piece.)
I guess you could just force everything to be a member of something or another, but what I kinda like on the approache above is that it also gives you the outline for the private properties of your module, i.e. fields and private methods.
Mine gives the outline, as well -- I apply the @memberOf to every method that I want to show up. It just doesn't distinguish between public and private. In general, I'm using the module pattern anyway, and try to only have one module per file, so I don't usually need much more structure than that. I'll look into it, though.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.