From 9cd2558d96c9c69cb444a87cea8e99ab7ceb0dd5 Mon Sep 17 00:00:00 2001 From: rsteube Date: Mon, 8 Jul 2024 10:43:32 +0200 Subject: [PATCH] xonsh: fix empty result --- example/cmd/_test/xonsh.py | 18 +++++++----------- internal/shell/xonsh/snippet.go | 18 +++++++----------- 2 files changed, 14 insertions(+), 22 deletions(-) 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)