Skip to content

Commit

Permalink
Merge pull request #1024 from carapace-sh/xonsh-fix-empty-result
Browse files Browse the repository at this point in the history
xonsh: fix empty result
  • Loading branch information
rsteube authored Jul 8, 2024
2 parents 74167cb + 9cd2558 commit 3a4e1c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
18 changes: 7 additions & 11 deletions example/cmd/_test/xonsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

18 changes: 7 additions & 11 deletions internal/shell/xonsh/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3a4e1c3

Please sign in to comment.