Need help to create a Tern plugin


#1

Hello,

I am trying to implement a module to make autocompletion working for
abitbol classes, but it does not work and I cannot figure out
why…

If I write a json definition file, it work as expected, but when I write
a plugin, it does not. Here are The working json example and the non-working
Javascript one. What am I doing wrong?

JSON “libs” definition

Files:

- test.js
- defs/abitbol.json
- .tern-project

.tern-project:

{
  "libs": ["defs/abitbol"],
  "ecmaVersion": 5,
  "plugins": {
    "node": {}
  }
}

def/abitbol.json:

{
  "!name": "abitbol",
  "!define": {
    "!known_modules": {
      "abitbol": {
        "!type": "Class"
      }
    },
    "Class": {
      "!type": "fn(?) -> +Class",
      "TEST_FROM_JSON_DEF": {
        "!type": "fn()"
      },
      "prototype": {}
    }
  }
}

test.js (auto completion works as expected):

Javascript Tern Plugin

Files:

- .tern-project
- abitbol.js
- test.js

.tern-project:

{
  "libs": [],
  "ecmaVersion": 5,
  "plugins": {
    "node": {},
    "abitbol": {}
  }
}

abitbol.js:

"use strict";

var tern = require("tern/lib/tern");
var infer = require("tern/lib/infer");

tern.registerPlugin("abitbol", function(server, options) {
    server.addDefs(defs);
});

var defs = {
    "!name": "abitbol",
    "!define": {
        "!known_modules": {
            "abitbol": {
                "!type": "Class"
            }
        },
        "Class": {
            "!type": "fn(?) -> +Class",
            "prototype": {},
            "TEST_FROM_PLUGIN": {
                "!type": "fn()"
            }
        }
    }
};

test.js (completion do not work, there is just fiew static method discovered by
the node module):


#2

I finally done it:

Regards, :smile: