11const vm = require ( 'vm' ) ;
22const 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' ) ;
44const { 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
4445function 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 */
0 commit comments