How to add my own completer in ace editor

若如初见. 提交于 2021-01-03 10:37:11

问题


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?


回答1:


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.




回答2:


Just add:

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

the enableLiveAutocompletion attribute will allow realtime popup



来源:https://stackoverflow.com/questions/44276794/how-to-add-my-own-completer-in-ace-editor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!