user6468132
user6468132

Reputation: 403

Dynamically autocomplete in ace editor

I want to update autocomplete suggestions according to the string.

  aceeditorObj.completers.push({
        getCompletions: function(editor, session, pos, prefix, callback) {
            obj = editor.getSession().getTokenAt(pos.row, pos.column-count);
            if(obj.value === "student"){
                var wordList = ["name", "age" , "surname"];
                callback(null, wordList.map(function(word) {
                    return {
                        caption: word,
                        value: word,
                        meta: "static"
                    };
                }));

            }

        }
    });

Name, age and surname is added to the auto suggestion list. But the old ones are still there. How can I show only the new world list in the list of auto completion?

Upvotes: 2

Views: 1827

Answers (1)

Harsha pps
Harsha pps

Reputation: 2198

Try setting the language tools to blank after you call your completers function:

    var langTools = ace.require("ace/ext/language_tools");

    aceeditorObj.completers.push({
        getCompletions: function(editor, session, pos, prefix, callback) {
            obj = editor.getSession().getTokenAt(pos.row, pos.column-count);
            if(obj.value === "student"){
                var wordList = ["name", "age" , "surname"];
                callback(null, wordList.map(function(word) {
                    return {
                        caption: word,
                        value: word,
                        meta: "static"
                    };
                }));
            }
        }
    });

    langTools.setCompleters([]); // This function should clear them

Upvotes: 1

Related Questions