diff --git a/example/cmd/_test/xonsh.py b/example/cmd/_test/xonsh.py index 141cb339..d2ecf3c9 100644 --- a/example/cmd/_test/xonsh.py +++ b/example/cmd/_test/xonsh.py @@ -15,18 +15,14 @@ def fix_prefix(s): output, _ = sub_proc_get_output( 'example', '_carapace', 'xonsh', *[a.value for a in context.args], fix_prefix(context.prefix) ) - if not output: - return - for c in loads(output): - yield RichCompletion( - c["Value"], - display=c["Display"], - description=c["Description"], - prefix_len=len(context.raw_prefix), - append_closing_quote=False, - style=c["Style"], - ) + try: + result = {RichCompletion(c["Value"], display=c["Display"], description=c["Description"], prefix_len=len(context.raw_prefix), append_closing_quote=False, style=c["Style"]) for c in loads(output)} + except: + result = {} + if len(result) == 0: + result = {RichCompletion(context.prefix, display=context.prefix, description='', prefix_len=len(context.raw_prefix), append_closing_quote=False)} + return result add_one_completer('example', _example_completer, 'start') diff --git a/internal/shell/xonsh/snippet.go b/internal/shell/xonsh/snippet.go index 9c04e69c..e9a467e7 100644 --- a/internal/shell/xonsh/snippet.go +++ b/internal/shell/xonsh/snippet.go @@ -29,18 +29,14 @@ def _%v_completer(context): output, _ = sub_proc_get_output( '%v', '_carapace', 'xonsh', *[a.value for a in context.args], fix_prefix(context.prefix) ) - if not output: - return - for c in loads(output): - yield RichCompletion( - c["Value"], - display=c["Display"], - description=c["Description"], - prefix_len=len(context.raw_prefix), - append_closing_quote=False, - style=c["Style"], - ) + try: + result = {RichCompletion(c["Value"], display=c["Display"], description=c["Description"], prefix_len=len(context.raw_prefix), append_closing_quote=False, style=c["Style"]) for c in loads(output)} + except: + result = {} + if len(result) == 0: + result = {RichCompletion(context.prefix, display=context.prefix, description='', prefix_len=len(context.raw_prefix), append_closing_quote=False)} + return result add_one_completer('%v', _%v_completer, 'start') `, functionName, cmd.Name(), cmd.Name(), uid.Executable(), cmd.Name(), functionName)