Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom autocompleter and periods (.)

Tags:

ace-editor

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.

like image 642
orom Avatar asked Mar 07 '15 22:03

orom


2 Answers

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

like image 84
orom Avatar answered Sep 20 '22 21:09

orom


Modifying the language_tools.js file is not a good solution, you can adjust the regex pattern by calling the method getCompletionRegex:

editor.getCompletionRegex = () => /[a-zA-Z_0-9.\$\-\u00A2-\uFFFF]/;
like image 30
Saad Hasan Avatar answered Sep 21 '22 21:09

Saad Hasan