user1663023
user1663023

Reputation:

Ace editor auto completion

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:

  1. I hope the sql key words suggested are all in upper case. They are all in lower case by default;
  2. 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.

Upvotes: 5

Views: 7233

Answers (1)

a user
a user

Reputation: 24104

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

Upvotes: 3

Related Questions