Ace 编辑器自动完成 [英] Ace editor auto completion
问题描述
我正在 sql 模式下使用 ace 编辑器.我按照此链接启用自动完成:https://github.com/ajaxorg/ace/blob/master/demo/autocompletion.html.它通常运作良好.但是,我想进一步调整自动完成功能以满足我的进一步要求.这是愿望清单:
- 我希望建议的 sql 关键字都是大写的.默认情况下它们都是小写的;
- 我发现当我输入一些单词时,我以前输入的单词会添加到建议词典中,这很好.我可以在编辑器中输入任何内容之前以编程方式在建议词典中添加更多单词吗?我需要这个的原因是我想将一些表名和字段名预加载到字典中.
我是这个很棒的编辑器的新手.我希望得到一些关于如何调整自动完成功能的指导.谢谢.
有一个 pull request 为 sql server 模式添加更好的补全 https://github.com/ajaxorg/ace/pull/2460,sql模式也可以处理.
要添加更多单词,您需要实现自定义完成器,这很简单:
<头><script src="http://ajaxorg.github.io/ace-builds/src/ace.js"><script src="http://ajaxorg.github.io/ace-builds/src/ext-language_tools.js"><风格>#editor { 位置:绝对;顶部:0;左:0;右:0;底部:0;}</风格>头部><身体><div id="编辑器">按 ctrl+space
<脚本>editor = ace.edit("editor")editor.setOptions({//模式: "ace/mode/javascript",enableBasicAutocompletion: 真});editor.completers.push({getCompletions:函数(编辑器,会话,位置,前缀,回调){回调(空,[{value: "foo", score: 1000, meta: "custom"},{值:条",分数:1000,元:自定义"}]);}})</html>
另见 https://github.com/ajaxorg/ace/wiki/How-to-enable-Autocomplete-in-the-Ace-editor
I am working with ace editor in sql mode. I followed this link to enable auto completion: https://github.com/ajaxorg/ace/blob/master/demo/autocompletion.html. It generally works well. However, I want to tweak the auto completion a bit more in order to fulfill my further requirements. Here's wish list:
- I hope the sql key words suggested are all in upper case. They are all in lower case by default;
- I found as I type in some words, my previously input words are added to the suggestion dictionary, which is good. Can I programmatically add more words in the suggestion dictionary even before anything is typed in the editor. The reason I need this is that I want to preload some table names and field names into the dictionary.
I am new to this awesome editor. I hope to get some direction on how to tweak the auto completion feature. Thanks.
There is a pull request to add better completion for sql server mode https://github.com/ajaxorg/ace/pull/2460, sql mode could be handled same way.
to add more words you need to implement a custom completer, which is simple:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajaxorg.github.io/ace-builds/src/ace.js">
</script>
<script src="http://ajaxorg.github.io/ace-builds/src/ext-language_tools.js">
</script>
<style>
#editor { position: absolute; top: 0; left: 0; right: 0; bottom: 0;}
</style>
</head>
<body>
<div id="editor">
press ctrl+space</div>
</body>
<script>
editor = ace.edit("editor")
editor.setOptions({
// mode: "ace/mode/javascript",
enableBasicAutocompletion: true
});
editor.completers.push({
getCompletions: function(editor, session, pos, prefix, callback) {
callback(null, [
{value: "foo", score: 1000, meta: "custom"},
{value: "bar", score: 1000, meta: "custom"}
]);
}
})
</script>
</html>
see also https://github.com/ajaxorg/ace/wiki/How-to-enable-Autocomplete-in-the-Ace-editor
这篇关于Ace 编辑器自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!