JS autocomplete not working across files?

Now that I have autocompletion working with JSDoc, I am now trying to get the autocompletion working across files. I can autocomplete within a file, but it doesn't seem to work in other files.

Below is a simple example using two JS files called typeDescribe.js and typeUse.js.

In typeDescribe.js, when I do a Ctrl-Space after varDude I see the Person's variables/functions at the top of the list.

In typeUse.js, when I do a Ctrl-Space after varDude2 I just see the generic list of variables/functions. If I do a Ctrl-Q on varDude2 it knows its a Person, but autocomplete isn't working.

Am I missing something?

Thanks,
dave


typeDescribe.js

dojo.declare("Person", null, {
    constructor: function(name, age, currentResidence) {
        this.currentResidence = currentResidence;
    },
    moveToNewState: function(newState) {
        this.currentResidence = newState;
    }
});

/** @type Person */
var varDude;
varDude.currentResidence; // autocompletes as Person


typeUse.js

/** @type Person*/
var varDude2;

varDude2.currentResidence;   // autocompletes generically

9 comments
Comment actions Permalink

I have the exact same problem. I guess it's a bug (or rather the JsDoc feature being incomplete) in the current EAP.

When I have this code in one file:

oneFile.js

/**
* Description.
*
* @class MyApp.ComponentTest
*/
MyApp.ComponentTest = Base.extend({
     /**
      * Test
      *
      * @param {Object} config
      */
     doSomething: function(config) {}
});



var a = new MyApp.ComponentTest();
a.doSomething(); // Auto-completes fully.


But as soon as I have the code in a separate file:

anotherFile.js

var a = new MyApp.ComponentTest();
a.doSomething(); // Does not auto-complete. Shows a generic list containing possibly all variables/functions in the project.


I have tried making my project a library and use that lib for my project, but that made no difference either.

0
Comment actions Permalink

Kai,
which version of IDE do you use? I tried both the latest PhpStorm/Idea build and quite an old PhpStorm build 102.18.  In both cases I get "doSomething" in completion list without any tricks (see the attached screenshot).



Attachment(s):
completion.png
0
Comment actions Permalink

Thanks for the reply. It seems that I was just confused by the behavior. :)

If you try the same code in a single file, it puts all those methods and properties on the top of the code assistant, but if you put the code in two files, the code assistant puts the properties and methods alphabetically within the big list of ECMAScript and DOM properties and methods. I just did not realize that first and I now understand that when these properties are found in the same file they get more importance thus show up in the top of the code completion window.

0
Comment actions Permalink

kaisellgren wrote:

Thanks for the reply. It seems that I was just confused by the behavior. :)

If you try the same code in a single file, it puts all those methods and properties on the top of the code assistant, but if you put the code in two files, the code assistant puts the properties and methods alphabetically within the big list of ECMAScript and DOM properties and methods. I just did not realize that first and I now understand that when these properties are found in the same file they get more importance thus show up in the top of the code completion window.


I still am not convinced the behavior is correct. I think its possibly inconsistent with the docs and its definitely the wrong behavior from a usability perspective, see thread discussion - http://youtrack.jetbrains.net/issue/WI-4829.

d

0
Comment actions Permalink

Rustam.Vishnyakov wrote:

Kai,
which version of IDE do you use? I tried both the latest PhpStorm/Idea build and quite an old PhpStorm build 102.18.  In both cases I get "doSomething" in completion list without any tricks (see the attached screenshot).


The problem is that doSomething should be at the top of the list (and in green) because the type is known. See issue for (a lot) more discussion.

Thanks,
dave

0
Comment actions Permalink

Ok, thanks. I've got your point.

0
Comment actions Permalink

Hmm... after I read your bug track post I came to rethink that maybe you are right. Maybe I will check out how it works in PHP or Java.

0
Comment actions Permalink

I think part of it may be how someone is using JS, because its such a "flexible" language its used in a few ways.

If you are using just as a non-OO, procedural, scripting language on one or two pages, then you probably are interested in the local methods.

If you are using a module/OO/typed approach (or using a library that does) then typing is king and you want the methods for the type you have.

I would say the type is what drives it. So if you know a type then you should use that, if not then use local methods.

d

Rustam.Vishnyakov wrote:

Ok, thanks. I've got your point.

0

Please sign in to leave a comment.