}
}
- // Filter, sort (within each group), uniq and merge the completion groups.
- if (completionGroups.length && filter) {
- var newCompletionGroups = [];
- for (i = 0; i < completionGroups.length; i++) {
- group = completionGroups[i].filter(function(elem) {
- return elem.indexOf(filter) == 0;
- });
- if (group.length) {
- newCompletionGroups.push(group);
+ // Will be called when all completionGroups are in place
+ // Useful for async autocompletion
+ function completionGroupsLoaded(err) {
+ if (err) throw err;
+
+ // Filter, sort (within each group), uniq and merge the completion groups.
+ if (completionGroups.length && filter) {
+ var newCompletionGroups = [];
+ for (i = 0; i < completionGroups.length; i++) {
+ group = completionGroups[i].filter(function(elem) {
+ return elem.indexOf(filter) == 0;
+ });
+ if (group.length) {
+ newCompletionGroups.push(group);
+ }
}
+ completionGroups = newCompletionGroups;
}
- completionGroups = newCompletionGroups;
- }
- if (completionGroups.length) {
- var uniq = {}; // unique completions across all groups
- completions = [];
- // Completion group 0 is the "closest" (least far up the inheritance chain)
- // so we put its completions last: to be closest in the REPL.
- for (i = completionGroups.length - 1; i >= 0; i--) {
- group = completionGroups[i];
- group.sort();
- for (var j = 0; j < group.length; j++) {
- c = group[j];
- if (!hasOwnProperty(uniq, c)) {
- completions.push(c);
- uniq[c] = true;
+ if (completionGroups.length) {
+ var uniq = {}; // unique completions across all groups
+ completions = [];
+ // Completion group 0 is the "closest"
+ // (least far up the inheritance chain)
+ // so we put its completions last: to be closest in the REPL.
+ for (i = completionGroups.length - 1; i >= 0; i--) {
+ group = completionGroups[i];
+ group.sort();
+ for (var j = 0; j < group.length; j++) {
+ c = group[j];
- if (!uniq.hasOwnProperty(c)) {
++ if (!hasOwnProperty(c)) {
+ completions.push(c);
+ uniq[c] = true;
+ }
}
+ completions.push(''); // separator btwn groups
+ }
+ while (completions.length && completions[completions.length - 1] === '') {
+ completions.pop();
}
- completions.push(''); // separator btwn groups
- }
- while (completions.length && completions[completions.length - 1] === '') {
- completions.pop();
}
- }
- return [completions || [], completeOn];
+ callback(null, [completions || [], completeOn]);
+ }
};