Search code examples
ace-editor

Custom autocompleter and periods (.)


I can't seem to make getCompletions function to trigger in my custom completer when using custom prefix extraction regex identifierRegexps

Basically I am trying to create an autocompleter which will trigger on periods (.) preceded by letters. E.g. In "foo." when the period is typed I would like to present my custom suggestions.

var lang = ace.require("ace/ext/language_tools");
var editor = ace.edit("editor");
editor.getSession().setMode("ace/mode/javascript");
editor.setOptions({
  enableBasicAutocompletion: true,
  enableSnippets: true,
  enableLiveAutocompletion: true
});

var compl = {
  identifierRegexps: [/[a-zA-Z_0-9\.\$\-\u00A2-\uFFFF]/],
  getCompletions: function (editor, session, pos, prefix, callback) {
    alert(prefix);

    callback(null, []);
    return;
  }
}
lang.addCompleter(compl);

With the above snippet, suggestions popup appears when typing a dot but getCompletions doesn't trigger. However, it does trigger on any other character.

UPDATE:

Removing default completers prior to adding the custom one with

lang.setCompleters();

makes the getCompletion function to trigger. However prefix argument is empty in that case.


Solution

  • Managed to solve it by modifying the ID_REGEX var in language_tools.js.