I’m trying to build an autocomplete list for my custom language.
Currently i’m using the following code which triggers autocomplete on any keyup :
editor.on("keyup", function (cm, event) {
if (!cm.state.completionActive && event.keyCode != 13 && event.keyCode != 32) {
cm.showHint({
completeSingle: false
})
}
});
Now i was checking out and really liked some additional features in the tern.js autocomplete demo (like the description on right on select of list element). I was able to figure out most of it however I had few doubts on how it works vs how sql-hint.js (which i’m using currently) works:
-
Currently, my custom mode is just an overlay on x-sql mode :
CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || "text/x-sql"), dimensionOverlay);
I’m curious how does codemirror know that it needs to use sql-hint.js and not some other (like javascript-hint.js). Does it figure this out using the overlay mode name? -
One difference I found in tern.js is that unlike other mode hints like sql-hint.js it defines its own hint function and nowhere does it use registerHelper method :
complete: function(cm) {cm.showHint({hint: this.getHint})}
On the other hand sql-hint.js uses a registerHelper method :
CodeMirror.registerHelper("hint", "sql", function(editor, options)
I don’t completely understand what’s the use for registerHelper? Is it necessary to use registerHelper in custom modes? -
At lot of times in tern.js code an parameter ‘c’ is used. e.g. the getHint function is called as :
this.getHint = function(cm, c) { return hint(self, cm, c); };
What’s the ‘c’ here? I couldn’t find this argument being passed anywhere.
Sorry for the long post. Appreciate any help!