i meant this one
https://github.com/ajaxorg/ace/blob/master/lib/ace/mode/xquery.js
the huge ones in lib\ace\mode\xquery folder are the equivalent of datebase
here is a very simple and dirty code doing something similar to what you want
showing which parts of ace you need to modify
var Tokenizer = require("ace/tokenizer").Tokenizer;
// words in datebase
var goodWords = Object.create(null)
// words checked to not be in datebase
// this can be omitted
// if it is ok to check for same words several times
var words = Object.create(null)
// cache for words pending resolution
var pending = []
var tokenizer = new Tokenizer({
"start": [
{token : function(val){
if (goodWords[val])
return "keyword"
if (words[val])
return "just-a-word"
if (pending.indexOf(val) == -1)
pending.push(val)
return "unknown"
}, regex : "\\w+"},
{token : "text", regex : "[^\\w]+"}
]
});
var queryTimeout = null
dirtySessions = []
attachToSession = function(session) {
var self = session.bgTokenizer
self.rehighlight = function() {
var states = this.states
var lines = this.lines
for (var i = states.length; i--;){
if (states[i] || !lines[i])
continue
states[i] = "start"
lines[i].forEach(function(t){
if (goodWords[t.value])
t.type = "keyword"
else if (words[t.value])
t.type = "just-a-word"
})
}
// this can be smarter and update only changed lines
this.fireUpdateEvent(0, states.length)
}
self.$tokenizeRow = function(row) {
// tokenize
var line = this.doc.getLine(row);
var data = this.tokenizer.getLineTokens(line, "start").tokens;
// if we found new words schedule server query
if (pending.length && !queryTimeout)
queryTimeout = setTimeout(queryServer, 700)
if (dirtySessions.indexOf(this) == -1)
dirtySessions.push(this)
// set state to null to indicate that it needs updating
this.states[row] = null
return this.lines[row] = data;
}
self.setTokenizer(tokenizer)
}
queryServer = function() {
fetchData(pending, function(serverWords){
// update goodWords and words based on serverWords
//...
// then
dirtySessions.forEach(function(x){
x.rehighlight()
})
dirtySessions = []
// some code to reset queryTimeout
// shedule again if there are more words in pending
// etc...
pending = []
})
}
/// use this instead of setMode
attachToSession(ace.session)