Skip to content

Commit 1400288

Browse files
committed
Add completer and await to cli plugin.
1 parent 5b904c2 commit 1400288

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

source/cli/plugins/cli_repl_plugin/source/cli_core_command.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ const cli_core_command_map = {
2929
regexes: [func], /* Match any function call like: func_abc_3423("asd", 3434, 0.2) */
3030
types: ['METACALL_STRING'],
3131
},
32+
await: {
33+
regexes: [func], /* Match any function call like: func_abc_3423("asd", 3434, 0.2) */
34+
types: ['METACALL_STRING'],
35+
},
3236
clear: {
3337
regexes: [loaders, all_except_whitespaces], /* Match everything except whitespaces, paths with whitespaces are not supported */
3438
types: ['METACALL_STRING', 'METACALL_STRING'],

source/cli/plugins/cli_repl_plugin/source/cli_repl_plugin.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const vm = require('vm');
22
const r = require('repl');
3-
const { command_register, command_register_map, command_parse, command_complete } = require('./parser');
3+
const { command_register, command_register_map, command_parse, command_completer } = require('./parser');
44
const { cli_core_command_map } = require('./cli_core_command');
55

66
/* Register CLI Core command map into the parser */
@@ -38,7 +38,8 @@ const repl = r.start({
3838
useGlobal: false,
3939
ignoreUndefined: true,
4040
preview: true,
41-
eval: evaluator
41+
eval: evaluator,
42+
completer: completer
4243
});
4344

4445
function evaluator(cmd, context, file, cb) {
@@ -62,15 +63,10 @@ function evaluator(cmd, context, file, cb) {
6263
repl_promise.push(new_repl_promise());
6364
}
6465

65-
/* Complete function (hook it in order to allow inline autocompletion) */
66-
const _completer = repl.completer.bind(repl);
67-
repl.completer = function(line, cb) {
68-
/* Hook the completer callback in order to inject our own completion results */
69-
const wrap = (err, result) => {
70-
/* TODO: Generate autocompletion array (command_complete) */
71-
cb(err, [['call'], line]);
72-
};
73-
_completer(line, wrap);
66+
function completer(line) {
67+
const completions = command_completer();
68+
const hits = completions.filter(c => c.startsWith(line));
69+
return [hits.length ? hits : completions, line];
7470
}
7571

7672
/* Clear context and commands */

source/cli/plugins/cli_repl_plugin/source/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@ module.exports = {
9595
command_register_map: (map) => {
9696
Object.keys(map).forEach(key => command_register(key, map[key].regexes, map[key].types));
9797
},
98-
command_complete: () => {},
98+
command_completer: () => Object.keys(command_parser_map),
9999
command_parse,
100100
};

0 commit comments

Comments
 (0)