Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add my own completer in ace editor

Tags:

ace-editor

Now i am developing a simple web-based editor for my database backend. I found that ace comes with autocompleter, if I only need to do complete with SQL keywords, how should I add my own rules?

like image 410
Zanecat Avatar asked May 31 '17 05:05

Zanecat


2 Answers

First, Activate the enableLiveAutocompletion as you mentioned, and you also have to ensure enableBasicAutocompletion is defined and set to true (see below).

editor.session.setMode("ace/mode/sql");
editor.setOptions({
    enableBasicAutocompletion: true,
    enableSnippets: true,
    enableLiveAutocompletion: true
});

To add a new completer, do what eemp mentioned on github (here).

let langTools = ace.require('ace/ext/language_tools');

Then use the addCompleter method to add the completions as defined below:

var customCompleter = {
  getCompletions: function(editor, session, pos, prefix, callback) {
       // your code
       /* for example
        * let TODO = ...;
        * callback(null, [{name: TODO, value: TODO, score: 1, meta: TODO}]);
        */
  }

 }
langTools.addCompleter(customCompleter);

You can also go have a look at the following:

Ace docs on Completers.

like image 54
Johann Nel Avatar answered Nov 18 '22 20:11

Johann Nel


Just add:

editor.session.setMode("ace/mode/sql");
editor.setOptions({
    enableBasicAutocompletion: true,
    enableSnippets: true,
    enableLiveAutocompletion: true
});

the enableLiveAutocompletion attribute will allow realtime popup

like image 30
Zanecat Avatar answered Nov 18 '22 21:11

Zanecat