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.
Managed to solve it by modifying the ID_REGEX var in language_tools.js.
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]/;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With