how to use tern in codemirror to add my special text for every word in my editor?


Hello , I want to use tern (to add type for every word in my own language ) so I add to my html page this :

   <link rel="stylesheet" href="plugin/codemirror/addon/tern/tern.css">
     <link rel="stylesheet" href="plugin/codemirror/addon/dialog/dialog.css">
<script src="plugin/codemirror/addon/tern/tern.js"></script>
<script src="plugin/codemirror/addon/dialog/dialog.js"></script> 

I try to type :

"Ctrl-I": function(cm) { CodeMirror.tern.getServer(cm).showType(cm); }, but not work

and I try to write like demo:

  function getURL(url, c) {
    var xhr = new XMLHttpRequest();"get", url, true);
    xhr.onreadystatechange = function() {
      if (xhr.readyState != 4) return;
      if (xhr.status < 400) return c(null, xhr.responseText);
      var e = new Error(xhr.responseText || "No response");
      e.status = xhr.status;

  var server;
  getURL("//", function(err, code) {
    if (err) throw new Error("Request for ecma5.json: " + err);
    server = new CodeMirror.TernServer({defs: [JSON.parse(code)]});
    editor.setOption("extraKeys", {
      "Ctrl-Space": function(cm) { server.complete(cm); },
      "Ctrl-I": function(cm) { server.showType(cm); },
      "Ctrl-O": function(cm) { server.showDocs(cm); },
      "Alt-.": function(cm) { server.jumpToDef(cm); },
      "Alt-,": function(cm) { server.jumpBack(cm); },
      "Ctrl-Q": function(cm) { server.rename(cm); },
      "Ctrl-.": function(cm) { server.selectName(cm); }
    editor.on("cursorActivity", function(cm) { server.updateArgHints(cm); });

  var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "javascript"

But nothing work

so can any body help me what functions I must to call to add my own tern to my own words ???


Tern does type inference for JavaScript. If you’re working with your own language, it is not going to be useful.


can I make type inference for my own language ?? or I can not … if I cant not what I can I do to show to me tooltip I defined in codemirror ?? @marijn


You might be able to write something like Tern for your language, but it’ll probably not be easy. CodeMirror doesn’t have prebuilt tooltip functionality, but you can use the coordsAtCursor method and and absolutely positioned element to build your own.