Autocomplete for a single JavaScript object extended across multiple files in Zend Studio (Eclipse PDT)
Asked Answered
W

3

17

My IDE is Zend Studio 8, which features a relatively basic perspective for JavaScript (similar to, if not the same as, the perspective in Eclipse PDT). In the application I'm working on, we extend a base object across multiple files, which has effectively killed the autocomplete functionality. See below for an example scenario...

// global.js
var App = {
    objectA: {
        method1: function() {},
        method2: function() {}
    },
    objectB: {
        method1: function() {},
        method2: function() {}
    }
};

// extend.js
App.Extend = {
    anotherMethod: function() {}
};

In this scenario, typing App. causes autocomplete to appear with objectA and objectB, but not Extend. If I add Extend to the App variable in global.js, it will appear in the autocomplete, but not with anotherMethod. If I were to use var Extend = { /* code */ };, autocomplete would work for the Extend object, so the problem does not seem to be related to the fact that the code is extended across multiple files. Perhaps it is because a single object is being spread across multiple files...or something else.

Anyone have any ideas?

Weinstein answered 9/6, 2011 at 21:41 Comment(3)
Just out of curiosity - What happens if it's App.extend rather than App.Extend?Envelope
At first I thought this might be better filed under auto-complete, but then I though better of it and reverted. Sorry for the edits.Aggiornamento
@Envelope Thanks for the response. The case does not affect the outcome. It could be App.extend, App.EXTEND, App.Extend, etc., and all don't work. I have also tried different terminology, just to test the outcome.Weinstein
C
1

Since Javascript is not a compiled language, the IDE has no idea where your extended classes are. Some advanced IDEs try to workaround this by considering every javascript file to be part of single project and thus, combining them in the background to give you autocomplete.

I've played with a variety of IDEs and the only IDE I've seen it work from is Jetbrain's Webstorm

Canned answered 1/7, 2011 at 22:45 Comment(0)
H
1

VJET JS IDE for Eclipse has a way of extending across multiple files using a vjetdoc syntax. Check it out -- http://www.ebayopensource.org/wiki/display/VJET/JS+code+assist+and+validation+for+two+or+more+js+files

It works with object literal, variables, functions. As soon as you go to class concepts there is typically a wrapper function to define classes. In VJET there is vjo.ctype which allows you to create classes in js. VJET provides correct assist for classes defined with this type construction kit. Here is an example:

Base.js
vjo.ctype("namespace.Base")
.endType();

App.js
vjo.ctype("namespace.App")
.inherits("namespace.Base")
.protos({
   doIt:function(){}
})
.endType()
Housing answered 7/4, 2012 at 18:56 Comment(0)
C
0

Not familiar with Zend Studio, but from what you say it is not clear whether it works on globals only or not. I.e. if I understood you correctly, this works:

// global.js
var App = {
    objectA: {
        method1: function() {},
        method2: function() {}
    },
    objectB: {
        method1: function() {},
        method2: function() {}
    }
};

// extend.js
var Extend = {
    anotherMethod: function() {}
};

However, if you add this, will this work?

// extend.js
...
var More = {
    streetWithNoName: false,
};
More.helloWorld = [1, 2, 3]

If you cannot get auto-complete for helloWorld on More. (and as it works on Extend, you should get the auto-complete for streetWithNoName), then probably Zend is not doing a non-global completion, which I guess is a very hard thing to do anyway. If it can, then you can always do:

var innerAppExtend = App.Extend = { ... };

as a workaround, if that's acceptable to you of course.

Circuity answered 29/6, 2011 at 3:58 Comment(5)
Thanks for the attempt, but this is exactly what I am trying to avoid. The idea is to ensure that these methods are encapsulated within the App object without unnecessarily creating global variables.Weinstein
I also tested the More.helloWorld (both Array and Object types), and the autocomplete worked fine. Both streetWithNoName, and helloWorld showed up in the autocomplete. Another clue!Weinstein
Given what you say, can you try adding var App; or var App = App; at the beginning of extend.js (and do everything as in your original post)?Circuity
Will it auto-complete at all across files? E.g. if in one file you have var A = { a: function() {} } and then in the next file (in order of including) var B = { b: A }, can you auto-complete B.b. and get a? If that works in one file, but doesn't work when split into two files, then I guess no cross-file auto-completes in Zend Studio.Circuity
When A/B are in the same file, it works as expected. When in two separate files, the autocomplete still works for A, but it does not carry over into B.b.Weinstein

© 2022 - 2024 — McMap. All rights reserved.