How can I view the outline in eclipse when using the revealing module pattern?
Asked Answered
S

4

17

I'm currently refactoring some Javascript code we have and amongst other things I've changed it to make use of the revealing module pattern. The code is looking much tidier and it works fine but I can't see the functions anymore in the outline view. I see the top level namespace var as a var but you can't expand it to see the functions within.

Lets say the code used to look like this:

function myFunc1() {}
function myFunc2() {}

In this case you see both functions in the outline view. But if you change it to this:

var myNamespace = function()
{
  function myFunc1() {}
  function myFunc2() {}

  return {
    name: "myNamespace",
    myFunc1: myFunc1,
    myFunc2: myFunc2
  }
}();

Then the outline view just shows you the myNamespace var. I've tried looking but can't find a view that will actually show me the hierarchy correctly. Does anyone know of a way to view this or is it a case of eclipse not being able to do this?

Strawboard answered 18/4, 2012 at 11:25 Comment(1)
Francois's answer works a treat. It's a bit of a kludge having to rely on a comment but its the only solution I've seen. I noticed that if you type an incorrect @memberof then the Eclipse outline goes with the comment rather than the code so you need to be careful when using this.Strawboard
P
23

Add:

/**
 * @memberOf myNamespace
 */

before each function definition to restore the hierarchy.

You will find more interesting tags to document your code here:
How I Introduced JsDoc into a JavaScript project – and found my Eclipse Outline

Prate answered 16/6, 2012 at 9:17 Comment(5)
Many thanks. Two months later and nobody else even gave a suggestion so it was obviously a tricky one to solve.Strawboard
That is what I am searching from ages :)Lindner
Seems to have no effect (at all) in my PHP Neon with default JS support... Anything else one should know, enable, ...?Mythicize
@BurninLeo: See this question. It's a bug in Neon due to core elements of JSDT being rewritten or switched to more maintainable software components. Part of the functionality has been restored, pretty quickly, which is rare enough to be worth mentioning, but there are still valid JS constructs that do not yield a satisfactory outline.Bantam
Finally, I had installed NetBeans to edit the JS files in my (Eclipse) project. Very nice :)Mythicize
M
5

one way is to call it as below. Define it as it is, but do not self execute it. Ensure the prototype is an empty object and then try calling it. It works the same way, but will restore the outline and you don't need to add comments in front of every function.

var myNamespace = (function()
{
  function myFunc1() {}
  function myFunc2() {}

  return {
    name: "myNamespace",
    myFunc1: myFunc1,
    myFunc2: myFunc2
  }
});
myNamespace.prototype = {};
myNamespace();
Marsipobranch answered 21/8, 2012 at 19:18 Comment(1)
It's a fair answer, it just arrived a bit late. Worth an upvote for a fellow noob though.Strawboard
G
2

Not showing myFunc1() etc. in the outline appears to be a bug which is marked as fixed in 3.2. However it is not fixed in 4.2. It is certainly a huge pain when dealing with very large files of hundreds of functions, and only the var name shows up in the outline. I pray for it being fixed.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=236202

https://bugs.eclipse.org/bugs/show_bug.cgi?id=281374#c1

/** * @memberOf myNamespace */ Did not work for me. When I add this above myFunc1(), it does not show it in the outline, even if I close and open the file.

Interestingly, 4 of my 20 or so functions do show up in the outline, but there is no difference between the ones which work and the ones which do not except the ones which work all have this.xxx in them (but if I add this.dummy; to invisible functions it does not help)

This semi works: myNameSpace.prototype = {}; myNameSpace;

But then you cant call its functions thusly: myNameSpace.myFunc1();

Gynous answered 24/1, 2013 at 22:57 Comment(1)
Yeah, in Eclipse 5.X, or whatever Kepler is, neither suggested method is working for me. JSDoc produces beautiful HTML pages outlining the self-invoked object/namespace, and Eclipse can suggest/autocomplete when you ctrl + space, but it refuses to outline the object! :(Cloddish
L
0

I'm working with eclipse/Kepler. Using the advice from above I managed to get the outline view. But proposals (Ctrl-space) didn't work. Some fn were visible, some not. No pattern to detect.

After reading http://usejsdoc.org/#JSDoc3_Tag_Dictionary I replaced all @memberOf by @memberof and now everything works as expected ('til the next problem arises ...)

Lightheaded answered 5/12, 2013 at 22:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.