Stumbling on Autocomplete: only recognizes my local variables and not my keywords.

2,481 views
Skip to first unread message

Zach Mccain

unread,
Aug 12, 2013, 6:37:23 PM8/12/13
to ace-d...@googlegroups.com

Plunker: http://plnkr.co/edit/bEkUM2?p=preview

Few notes on the plunk:

  1. SyntaxHighlighter file: mode-drlfile.js
  2. ACE autocomplete file: ext-language_tools.js
  3. Main Ace file: ace.js
  4. Main script file : script.js
  5. Autocomplete can be triggered by pressing Ctrl-Space.

I am using the Javascript ACE editor to create a syntax highlighter for a language (DRL). I am attempting to use the autocomplete option.

ace.config.loadModule("ace/ext/language_tools", function() {
    editor.setOptions({
        enableSnippets: true,
        enableBasicAutocompletion: true
    });
});

This feature recognizes my local variables but it fails to see my keywords defined in my syntax highlighter. I think I have tracked down the problem and it seems be that the session.$mode.$keywordList referenced in the ext-language_tools.js file (line #41) is empty when the script exectues.

var keyWordCompleter = {
getCompletions: function(editor, session, pos, prefix, callback) {
    console.log(session.$mode.$keywordList);
    var keywords = session.$mode.$keywordList || [];
    keywords = keywords.filter(function(w) {
        return w.lastIndexOf(prefix, 0) == 0;
    });
    callback(null, keywords.map(function(word) {
        return {
            name: word,
            value: word,
            score: 0,
            meta: "keyword"
        };
    }));
}

};

My syntax highlighter includes all keywords as a keyword mapper as follows...

 var keywordMapper = this.createKeywordMapper({
    "keyword" : "lock-on-active|date-effective|date-expires|no-loop|" +
               "auto-focus|activation-group|agenda-group|ruleflow-group|" +
               "entry-point|duration|package|import|dialect|salience|enabled|" +
               "attributes|rule|extend|when|then|template|query|declare|" +
               "function|global|eval|not|in|or|and|exists|forall|accumulate|" +
               "collect|from|action|reverse|result|end|over|init"
  },"identifier");

So, how do I go about having the autocomplete feature in ACE recognize my keywords and not just local variables?

Harutyun Amirjanyan

unread,
Aug 12, 2013, 8:04:42 PM8/12/13
to ace-d...@googlegroups.com
For now you have to do it manually see
https://github.com/ajaxorg/ace/blob/master/lib/ace/mode/javascript.js#L50

Btw. the demo is pretty nice!

Zach Mccain

unread,
Aug 12, 2013, 8:31:17 PM8/12/13
to ace-d...@googlegroups.com
Thank you very much!
Problem solved.

var Mode = function() {
    var highlighter = new drlFileHighlightRules();
    this.foldingRules = new FoldMode();
    this.$tokenizer = new Tokenizer(highlighter.getRules());
    this.$keywordList = highlighter.$keywordList
};
Reply all
Reply to author
Forward
0 new messages