Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ACE editor autocompletion remove local variables

I'm using ace editor and I've enabled basicautocompletion and I'm pulling data from another server to get the suggestions. Everything works fine, but I want to remove the local suggestions from the suggestion box.

Here is my relevant code:

var langTools = ace.require("ace/ext/language_tools");
var editor = ace.edit("editor");

editor.setTheme("ace/theme/xcode");
var TextMode = require("ace/mode/text").Mode;
editor.getSession().setUseWrapMode(true);

editor.setOptions({
  enableBasicAutocompletion: true,
});

var qtags = {
getCompletions: function(editor, session, pos, prefix, callback) {
  $.getJSON(jsonURL,
    function(tagList) {
      callback(null, tagList.map(function(qtag) {
        return {name: qtag.name, value: "#"+qtag.name+"() ", meta: "qtag"}
      }));
    })
  }
}
langTools.addCompleter(qtags);

Here is how it looks like:

Example

I've tried this line to remove all completers before adding my qtag completer, but that doesn't remove the local variables

langTools.completers = [];

Any input would be appreciated, I'm trying to avoid having to modify ace/ext/language_tools.js if possible, but at this point I'm open even to that option.

like image 554
Miroslav Saracevic Avatar asked Nov 18 '14 09:11

Miroslav Saracevic


2 Answers

The trick is to call langTools.setCompleters([]) before calling editor.setOptions({enableBasicAutocompletion: true});. May be its a good idea to set this option explicit to false before setting or adding the Completers. There is no need to change the sourcecode of the language_tools.

Example:

var langTools = ace.require("ace/ext/language_tools");
var editor = ace.edit("editor");

editor.setTheme("ace/theme/xcode");
var TextMode = require("ace/mode/text").Mode;
editor.getSession().setUseWrapMode(true);

var qtags = {
  getCompletions: function(editor, session, pos, prefix, callback) {
    $.getJSON(jsonURL,
      function(tagList) {
        callback(null, tagList.map(function(qtag) {
          return {name: qtag.name, value: "#"+qtag.name+"() ", meta: "qtag"}
      }));
    })
  }
}

langTools.setCompleters([qtags]);

editor.setOptions({
  enableBasicAutocompletion: true,
});
like image 96
SuperNova Avatar answered Oct 19 '22 08:10

SuperNova


you can use langTools.setCompleters

langTools = require("ace/ext/language_tools")
langTools.setCompleters([langTools.snippetCompleter, langTools.textCompleter])

or editor.completers = [langTools.snippetCompleter, langTools.textCompleter, qtags]

like image 31
a user Avatar answered Oct 19 '22 08:10

a user