Ace Editor using period(.) for autocomplete

1,150 views
Skip to first unread message

zbm

unread,
May 25, 2016, 12:32:34 PM5/25/16
to Ajax.org Cloud9 Editor (Ace)
   
The below is working example for ace editor which shows autocomplete options using json file.

    var langTools = ace.require("ace/ext/language_tools");
    var editor = ace.edit("content");
    editor.setOptions({enableBasicAutocompletion: true, enableLiveAutocompletion: true, tabSize: 2});
    editor.getSession().setMode("ace/mode/yaml");
    jsonURL = "func.json"; //JSON file
    var rhymeCompleter = {
        getCompletions: function(editor, session, pos, prefix, callback) {
            if (prefix.length === 0) { callback(null, []); return }
            $.getJSON(
                jsonURL,
                function(wordList) {
                    callback(null, wordList.map(function(ea) {
                        return {name: ea.word, value: ea.word, meta: "artemis"}
                    }));
                })
        }
    }
    langTools.addCompleter(rhymeCompleter);

Json file

[ {"word":"iter"},
  {"word":"arr"},
  {"word":"s_time"},
  {"word":"arr.name"},
  {"word":"arr.id"}
]

I am trying to work on the feature of autocomplete by period.. for eg if user type "arr." we should give options id and name as autocomplete.

Please help in resolving the issue.

zbm

unread,
May 26, 2016, 5:40:47 PM5/26/16
to Ajax.org Cloud9 Editor (Ace)

The period can be matched by auto complete if we modify the ext_language_too.js regex at ace.define("ace/autocomplete/util....

to var r = /[a-zA-Z_0-9\$-\.\u00A2-\uFFFF]/;

With the above change the period is included in autocomplete match and we can see autocomplete for name and id if we type arr.
Reply all
Reply to author
Forward
0 new messages