JSON type definition and its relationship to autocompletes


#1

Hello,

I’m trying to get a grip on how exactly this whole thing fits together with editors and autocompleters and not understanding part of the system. I’m fairly new to jsdoc, tern, etc so please let me know if there’s some docs somewhere I’ve missed that would be relevant

Here’s the basic thing I’m trying to understand: is the json type definition for a function supposed to fill in the type from jsdoc for parameters? Specifically, when I edit bin/condense and set the strong: true flag on the doc_comment plugin (I don’t think it sets it by default and wasn’t sure that --plugin doc_comment={"strong":true} was working…) I don’t see a type on a simple function argument:

Here’s the a sample of the code I’m trying to test this against


/**
 * @class Character
 * @param {Object} data - arguments.
 * @param {Race} data.race   - This chracters race
 * @param {string} data.name - This characters name
 */
var Character = function(data) {
};

/** * @param {Race} r - The race.  */
Character.prototype.setRace = function(r) {
};

Basically, I’m trying to describe the types of the object passed into the Character constructor and the function setRace. The confusion I have is that in all the editors I’ve been using (atom, vim) tern can find these definitions and jump to them but seems to not be providing types to the autocompleters. When I run bin/condense (modified to try and use strong doc_comment types) I get output like this:

$ ~/.vim/bundle/tern_for_vim/node_modules/tern/bin/condense src/Character.js
{
  "!name": "src/Character.js",
  "Character": {
    "prototype": {
      "setRace": {
        "!type": "fn(r: ?)",
        "!span": "263[10:20]-270[10:27]",
        "!doc": "@param {Race} r - The race."
      }
    },
    "!type": "fn(data: ?)",
    "!span": "172[6:4]-181[6:13]",
    "!doc": "@class Character\n@param {Object} data - arguments.\n@param {Race} data.race   - This chracters race\n@param {string} data.name - This characters name"
  }
}

In the output it seems like it doesn’t know what type “data” or “r” should be, even though they have param definitions. This is consistent with what I see in editors where the autocomplete tends to suggest “?”.

Again, I suspect I am missing something crucial but not sure which part of the tool chain I’m missing it in. Would love any hints where I might search next or thoughts on information I could provide to help make my search clearer.

Thanks,
Eugene


#2

Tern only understands @param declarations referring directly to a parameter name, not a property of a parameter.