Sunday, September 6, 2015

How to customise code Autocompletion in ace editor.

It is easy to customize the code completion in the ace editor,
The following code will do the autosuggestion in the editor.

 editor = ace.edit("editor")
    // mode: "ace/mode/javascript",
    enableBasicAutocompletion: true
    getCompletions: function(editor, session, pos, prefix, callback) {
      callback(null, [
        {value: "foo", score: 1000, meta: "custom"},
        {value: "bar", score: 1000, meta: "custom"}
But the above code will do autosuggestion with the completion we have provided with the words available in the editor, 
This code is done in the ace/ext/language_tools.js

You can customize the TextCompleter in the file language_tools.js 
In line no 70 if you remove the textCompletor, you can complete control according to your recommendation.
 var completers = [snippetCompleter,  keyWordCompleter];//textCompleter

No comments: