This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 242344 - Advanced intellisense for JavaScript inheritance and JsDoc-defined types
Summary: Advanced intellisense for JavaScript inheritance and JsDoc-defined types
Status: RESOLVED FIXED
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.0
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on: 242454 251819 251820 251821 251968 251984
Blocks:
  Show dependency tree
 
Reported: 2014-02-26 00:41 UTC by NukemBy
Modified: 2015-04-22 17:03 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Sample JS library for tests (2.91 KB, application/x-javascript)
2014-02-26 00:41 UTC, NukemBy
Details
netbeans-jsdoc-bugs.png (53.80 KB, image/png)
2015-04-13 17:46 UTC, NukemBy
Details

Note You need to log in before you can comment on or make changes to this bug.
Description NukemBy 2014-02-26 00:41:02 UTC
Created attachment 145590 [details]
Sample JS library for tests

I'm developing a JavaScript library and looking for a IDE support for IntelliSense. Sample minimalistic library to outline the wanted coverage is outline. Summary is below ...

To avoid naming clashes with other libraries, only two global names are used - myLib and MyLib. The rest of the implementation is embedded into 'MyLib' namespace. JavaScript does not have own truly-OOP inheritance, but i would refer to the most common workaround to define inheritance in JavaScript - sample on Mozilla site: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype.

MyLib structure in Java-like notation:

  MyLib {

    MyLib.prototype.MyObj = MyObj;

      /** @returns {MyObj} */
      MyLib.prototype.createMyObject = function createMyObject(type) {}

      /** @returns {MyExObj} */
      MyLib.prototype.createMyExObject = function createMyExObject(type) {}

      /** @returns {MyEx2Obj} */
      MyLib.prototype.createMyEx2Object = function createMyEx2Object(type) {}

    class MyObj {
      doMyObjMethod = function MyObj_doMyObjMethod(data)
    }

    function MyExObj_doExMethod(exdata){};

    class MyExObj extends MyObj {
      doExMethod = MyExObj_doExMethod;
    }

    class MyEx2Obj extends MyExObj {
      doEx2MethodFromMyObj = MyObj_doMyObjMethod;
      doEx2MethodFromEx = MyExObj_doExMethod;
      doEx2Method = function(ex2data)
    }
  }

in 'client' code for this excerpt

    var myObj = myLib.createMyObject("asd");
    var myExObj = myLib.createMyExObject("asd");
    var myEx2Obj = myLib.createMyEx2Object("asd");


    /**
     * @returns {MyLib.MyObj}
     */
    function newMyLibObj() {
        return new myLib.MyObj();
    }

    var myObj2 = newMyLibObj();

I expect following methods should be provided by intellisense and I've got following statistics across various IDE's

//                                  7.4         Dev ()      IDEA 13		Eclipse
myObj.doMyObjMethod()               OK          N/A         OK          Fail
myObj2.doMyObjMethod()              N/A         NoArgs      N/A         Fail

myExObj.doMyObjMethod()             N/A         N/A         OK          Fail
myExObj.doExMethod()                NoArgs      NoArgs      OK          Fail

myEx2Obj.doMyObjMethod()            N/A         N/A         OK          Fail
myEx2Obj.doExMethod()               N/A         N/A         OK          Fail
myEx2Obj.doEx2Method()              OK          N/A         OK          Fail
myEx2Obj.doEx2MethodFromMyObj()     NoArgs      N/A         NoArgs      Fail
myEx2Obj.doEx2MethodFromEx()        NoArgs      NoArgs      OK          Fail


Strange results are ...
* I could not find any docs regarding the correct way to document inner/namespaced classes MyLib.MyObj at http://usejsdoc.org, but it seems current NetBeans Dev Version (201402190001) can somehow handle it (though does not show arguments and documentations) ..
* .. but it fails with almost all other cases
* Current NB 7.4 work ok with simple cases, but fails with inheritance
* IntelliJ IDEA Ultimate is able to correctly identify most of the cases.

PS: there are few similar bugs regarding intellisense and JavaScript, not sure if this one is duplicate or not ...

https://netbeans.org/bugzilla/show_bug.cgi?id=214556
https://netbeans.org/bugzilla/show_bug.cgi?id=215398


They at least do not talk about namespaced classes and do not cover some use-cases of member definition. Additionally, I see regression in Intellisense capability in Dev vs. 7.4.
Comment 1 Vladimir Riha 2014-02-26 08:20:51 UTC
Please give it try in Dev build from [1] or (older) 8.0 Beta. The results in 8.0 RC1 are following (assuming NoArgs means "suggested as property not function")


                                  8.0 RC1      
myObj.doMyObjMethod()               OK       
myObj2.doMyObjMethod()              N/A      

myExObj.doMyObjMethod()             OK       
myExObj.doExMethod()                NoArgs   

myEx2Obj.doMyObjMethod()            OK       
myEx2Obj.doExMethod()               NoArgs   
myEx2Obj.doEx2Method()              OK       
myEx2Obj.doEx2MethodFromMyObj()     NoArgs   
myEx2Obj.doEx2MethodFromEx()        NoArgs   



Simple case to reproduce the "suggested as property not function" is following:

function test(){
    window.console.log(1);
}

var foo = {};
foo.bar = test;
foo.bar();


=>foo.bar is considered to be property not function in code completion and Navigator.



[1] bits.netbeans.org/netbeans/trunk/nightly/latest/



Product Version: NetBeans IDE 8.0 RC1 (Build 201402242200)
Java: 1.8.0; Java HotSpot(TM) Client VM 25.0-b69
Runtime: Java(TM) SE Runtime Environment 1.8.0-b129
System: Linux version 3.2.0-48-generic-pae running on i386; UTF-8; en_US (nb)
Comment 2 NukemBy 2014-02-26 10:38:44 UTC
Got the same result on older version of 8.0 - NetBeans IDE 8.0 Beta (Build 201401141042),  this means that there is regression in Javascript Intellisense of 'Development' version.

I was thinking that development version will turn into IDE 8.0 final soon. Where did you get 8.0 RC1? I see only 8.0 Beta on download page (https://netbeans.org/downloads/), which is the one I have already.
Comment 3 Vladimir Riha 2014-02-26 11:47:24 UTC
RC1 is not yet released, but it should be in couple of days
Comment 4 Petr Pisl 2014-02-26 15:52:39 UTC
I have tested the library file in different situation (in anonymous function, in global scope etc. and my results corresponds to the Vlada's result.

I don't see here any regression. I can be wrong.

The problem with the function treated as property - I don't know, whether I can fix it in NB 8.0 do to the complex fix. I'm going to look at this more.
Comment 5 NukemBy 2014-02-26 20:47:23 UTC
I just rechecked and it appears that either I was testing 'dev' version in a some wrong way or there was something wrong with my installation. Currently I've got intellisense in 'dev' working indeed the same way as in 8.0 Beta and described by Vladimir Riha.


Meanwhile I've noticed more use-cases where intellisense does not work
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function ThisLib() {
    /** @constructor */
    function MyObj() {
        this.doMyObj = function(arg) {}
    }
    
    this.MyObj = MyObj;
    
    /**
     * @returns {ThisLib.MyObj}
     */
    this.getMyObj = function getMyObj() { return new MyObj(); }
};
var thisLib = new ThisLib();

// (2.1) !!!! no intellisense after thisLib. here !!!!!
var myObj = new thisLib.MyObj();

// (2.2) OK
var myGetObj = thisLib.getMyObj();

// (2.3) OK
myGetObj.doMyObj();


var protoLib = new ProtoLib();

function ProtoLib() {
    /** @constructor */
    function MyPObj() {}
    
    MyPObj.prototype.doMyPObjMethod = function (arg) {}
    
    ProtoLib.prototype.MyPObj = MyPObj;
    
    /**
     * @returns {MyPObj}
     */
    ProtoLib.prototype.getMyPObj = new function () { return new MyPObj(); };
};

// (2.4) OK - In this case intellisense knowns about MyPObj
var myNewPObj = new protoLib.MyPObj();

// (2.5) !!!! no intellisense after myNewPObj. here !!!!!
myNewPObj.doMyPObjMethod();

var myGetPObj = protoLib.getMyPObj();

// (2.6) OK
myGetPObj.doMyPObjMethod();
Comment 6 NukemBy 2014-02-26 20:56:48 UTC
ProtoLib.prototype.getMyPObj = new function () { return new MyPObj(); };
should be changed to
ProtoLib.prototype.getMyPObj = function () { return new MyPObj(); };
Comment 7 Petr Pisl 2014-02-27 10:43:15 UTC
I have separated the Vlada's simple case to the issue #242408. This issue is more complex.
Comment 8 NukemBy 2014-02-28 13:03:08 UTC
As the current status from 'clients' - the most annoying bugs to me are buggy cases (1) and (3) below. It would be nice if the can be fixed sooner than later.
The strange thing is - I've tested against Dev (Build 201402280001) and case (3) is still reproducible, where as it looks to be the some one as in already fixed https://netbeans.org/bugzilla/show_bug.cgi?id=242408 "Function is treated as property".

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


var myLib = new function MyLib() {
    /**
     * @constructor
     * @returns {MyLib.MyObj}
     */
    this.MyObj = function() {
        /** @member {string} My Description */
        this.member = "value";
    };
    
    /**
     * @returns {MyLib.MyObj}
     */
    this.newMyObj = function MyLib_newMyObj() { 
        return new this.MyObj();
    };
    
    /**
     * ShareableFunc
     * @param {string} arg description
     */
    function PublicAndPrivateUsageFunc(arg) {}
    
    this.publicInnerFunc = PublicAndPrivateUsageFunc;
    
    /**
     * My Description
     * @param {string} arg My Argument
     */
    this.publicFunc = function MyLib_publicFunc(arg) { }
};

// (1) Intellisense does NOT work on myObj.member - not good
var myObj = new myLib.MyObj();
myObj.member;

// (2) Intellisense DOES work on myNewObj.member - good.
var myNewObj = myLib.newMyObj();
myNewObj.member;

// (3) Intelisense DOES NOT recognize it as refernce on
//     function "PublicAndPrivateUsageFunc()" within MyLib
//     Note: this is similar case to (FIXED)
//           https://netbeans.org/bugzilla/show_bug.cgi?id=242408
//           but is still reproducible
myLib.publicInnerFunc();

// (4) Intellisense works correctly here 
//     and case #3 is expected to work the same way 
myLib.publicFunc();
Comment 9 Petr Pisl 2014-02-28 14:10:56 UTC
Thanks for your cooperation. It's always good to have the test cases :).

I have separated the case 3 to the issue #242454. It's different from issue #242408, which solves basically only functions not "methods".
Comment 10 NukemBy 2015-04-13 17:46:12 UTC
Not sure what has changed in JS support in Netbeans during last year, but ... use-case #2 (myNewObj.member;) does not work anymore.

Additionally, trying to make a stubbed version of my js lib cross-usable between Netbeans and WebStorm i see there are problems in both, but NetBeans fails in more simple/standard cases.

Here is one more use-case - intellisense partially does not work for properties in 'b1' object(the last line). See screenshot for more details.

- - - - - - - - - - - - 

/** Implementation of the MyLib Library */
var MyLib = new function MyLib() {};

/** @constructor
 *  @returns {MyLib.ObjA} description */
MyLib.ObjA = function (arg) {
    /** JsDoc for MyLib.ObjA.aproperty
     * @type {number|string} */
    this.aproperty = this.aproperty;
};

/**
 * Constructs MyLib.ObjA
 * @returns {MyLib.ObjA}
 */
MyLib.objA = function () {
};

/** @constructor
 *  @returns {MyLib.ObjB} description */
MyLib.ObjB = function (arg) {
    /** JsDoc for MyLib.ObjB.aproperty
     * @type {number|boolean} */
    this.aproperty = this.aproperty;
};

/** Constructs MyLib.ObjB
 *  @return {MyLib.ObjB} */
MyLib.objB = function () {
    return new MyLib.ObjB();
};

var a2 = new MyLib.ObjA();
var res = a2.aproperty;

/** @type MyLib.ObjA */
var a1 = MyLib.objA();
var res = a1.aproperty;

var b2 = new MyLib.ObjB();
var res = b2.aproperty;

var b1 = MyLib.objB();
var res = b1.aproperty;
Comment 11 NukemBy 2015-04-13 17:46:49 UTC
Created attachment 153166 [details]
netbeans-jsdoc-bugs.png
Comment 12 Petr Pisl 2015-04-14 11:45:03 UTC
This issue contains more issues and starts to be chaotic. We need to separate every case into the different issue. It's better then to treat it. 

I have split the previous comment into issue #251819, issue #251820 and issue 251821. If I miss something, please create new issue for it. 

Also if something missing from the previous case. I would like close this issue and solve the cases separately. Thanks.
Comment 13 NukemBy 2015-04-14 11:54:21 UTC
Re: This issue contains more issues and starts to be chaotic. We need to separate every case into the different issue. It's better then to treat it. 

'chaotic' - yes, too much in on place, though it is hard from my perspective to 'correctly' create sub-issues as I do not have internal knowledge about Netbeans' implementation. For me it looks to be more or less the same :)


Re: I would like close this issue and solve the cases separately.

I'm OK with that, hoping that things will work correctly in general.
Comment 14 Petr Pisl 2015-04-22 17:03:10 UTC
Thanks, I close this issue as fixed, even if there are probably cases that still doesn't work. But the bulk of these are already fixed. 

If you run in a case, which doesn't work, please enter separate issue for it. It's much better to treat separate cases and more cases in one issue. Thanks.