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 keyWordCompleter = {
getCompletions: function(session, pos, prefix, callback) {
var keywords = session.$mode.$keywordList || [];
keywords = keywords.filter(function(w) {
return w.lastIndexOf(prefix, 0) == 0;
});
callback(null, keywords.map(function(word) {
return {
name: word,
value: word,
score: 0,
meta: "keyword"
};
}));
getCompletions: function(editor, session, pos, prefix, callback) {
var state = editor.session.getState(pos.row);
var completions = session.$mode.getCompletions(state, session, pos, prefix);
callback(null, completions);
}
};

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++) {
(function(scope) {
@ -356,7 +356,22 @@ var Mode = function() {
return 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);
exports.Mode = Mode;