2

I am trying to implement custom and basic auto-completion in the ace editor at the same time, I am following the stack overflow article ACE Editor Autocomplete - custom strings. But when I try to press some character, then I am getting the below Error

ERROR TypeError: Cannot read property 'map' of undefined. The code that I am using is

    var staticWordCompleter={
     getCompletions: function(editor, session, pos, prefix, callback) {
        if (prefix.length === 0) {
            callback(null, []);
            return
        }
        var wordList = ["foo", "bar", "baz"];
        callback(null, [...wordList.map(function(word) {
                return {
                    caption: word,
                    value: word,
                    meta: "static"
                };
            }),
            ...session.$mode.$highlightRules.$keywordList.map(function(word) {
                return {
                    caption: word,
                    value: word,
                    meta: 'keyword',
                };
            })
        ]);
}

when I remove the above code then basic auto-completion working pretty fine as usual. And when I remove the following code from the above code:

...session.$mode.$highlightRules.$keywordList.map(function(word) {
                return {
                    caption: word,
                    value: word,
                    meta: 'keyword',
                };
            })

then it only gives auto-suggestion of custom auto-completion code. Please help me how to implement both at a time.

Johnny Willemsen
  • 2,942
  • 1
  • 14
  • 16
  • 1
    A very very good question! I am working on something similar in there's a dearth of examples from ace! – Raaka Aug 11 '22 at 14:33

1 Answers1

1

 var staticWordCompleter = {
      getCompletions: function(editor, session, pos, prefix, callback) {
          var wordList = ["foo", "bar", "baz"];
          callback(null, wordList.map(function(word) {
              return {
                  caption: word,
                  value: word,
                  meta: "static"
              };
          }));

      }
  }
 langTools.addCompleter(staticWordCompleter);
Huy Nguyen
  • 43
  • 7
  • Very to the point answer, I could get it to work for Typescript too (had to add `:any` to all params in the function though. – Raaka Aug 11 '22 at 14:33