如何在ace编辑器中添加我自己的完成器 [英] How to add my own completer in ace editor

查看:28
本文介绍了如何在ace编辑器中添加我自己的完成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在为我的数据库后端开发一个简单的基于 Web 的编辑器.我发现ace自带自动补全,如果我只需要用SQL关键字完成,我应该如何添加我自己的规则?

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?

推荐答案

首先,激活您提到的 enableLiveAutocompletion,并且您还必须确保定义了 enableBasicAutocompletion 并且设置为 true(见下文).

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
});

要添加新的完成者,请执行 eemp 在 github 上提到的操作(这里).

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

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

然后使用 addCompleter 方法添加如下定义的补全:

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:

关于 Completers 的 Ace 文档.

这篇关于如何在ace编辑器中添加我自己的完成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆