add .getCompletions method to text mode

This commit is contained in:
DanyaPostfactum 2013-07-01 01:42:40 +10:00
commit a5f4ecf597
2 changed files with 21 additions and 15 deletions

View file

@ -37,19 +37,10 @@ var config = require("../config");
var textCompleter = require("../autocomplete/text_completer"); var textCompleter = require("../autocomplete/text_completer");
var keyWordCompleter = { var keyWordCompleter = {
getCompletions: function(session, pos, prefix, callback) { getCompletions: function(editor, session, pos, prefix, callback) {
var keywords = session.$mode.$keywordList || []; var state = editor.session.getState(pos.row);
keywords = keywords.filter(function(w) { var completions = session.$mode.getCompletions(state, session, pos, prefix);
return w.lastIndexOf(prefix, 0) == 0; callback(null, completions);
});
callback(null, keywords.map(function(word) {
return {
name: word,
value: word,
score: 0,
meta: "keyword"
};
}));
} }
}; };

View file

@ -281,7 +281,7 @@ var Mode = function() {
} }
} }
var delegations = ['toggleCommentLines', 'getNextLineIndent', 'checkOutdent', 'autoOutdent', 'transformAction']; var delegations = ['toggleCommentLines', 'getNextLineIndent', 'checkOutdent', 'autoOutdent', 'transformAction', 'getCompletions'];
for (var i = 0; i < delegations.length; i++) { for (var i = 0; i < delegations.length; i++) {
(function(scope) { (function(scope) {
@ -357,6 +357,21 @@ var Mode = function() {
return completionKeywords.concat(this.$keywordList || []); return completionKeywords.concat(this.$keywordList || []);
}; };
this.getCompletions = function(state, session, pos, prefix) {
var keywords = this.$keywordList || [];
keywords = keywords.filter(function(w) {
return w.lastIndexOf(prefix, 0) == 0;
});
return keywords.map(function(word) {
return {
name: word,
value: word,
score: 0,
meta: "keyword"
};
});
};
}).call(Mode.prototype); }).call(Mode.prototype);
exports.Mode = Mode; exports.Mode = Mode;