Repository: rsteube/carapace (go)

Issue:
xonsh: no values cause fallback to file completion
readd dummy completion value with current prefix to prevent default file completion fallback if no values are returned


Pull request:
xonsh: prevent file completion fallback
fix #369 

Patch:
diff --git a/internal/xonsh/snippet.go b/internal/xonsh/snippet.go
index f149bde..ba9c471 100644
--- a/internal/xonsh/snippet.go
+++ b/internal/xonsh/snippet.go
@@ -22,9 +22,12 @@ def _%v_completer(context):
         from xonsh.completers.tools import RichCompletion
         output, _ = Popen(['%v', '_carapace', 'xonsh', '_', *[a.value for a in context.args], context.prefix], stdout=PIPE, stderr=PIPE).communicate()
         try:
-            return {RichCompletion(c["Value"], display=c["Display"], description=c["Description"], prefix_len=len(context.raw_prefix)) for c in loads(output)}
+            result = {RichCompletion(c["Value"], display=c["Display"], description=c["Description"], prefix_len=len(context.raw_prefix)) for c in loads(output)}
         except:
-            return
+            result = {}
+        if len(result) == 0:
+            result = {RichCompletion(context.prefix, display=context.prefix, description='', prefix_len=len(context.raw_prefix))}
+        return result
 
 
 from xonsh.completers._aliases import _add_one_completer


Test patch:
diff --git a/example/cmd/_test/xonsh.py b/example/cmd/_test/xonsh.py
index a5371b5..c1d4b8a 100644
--- a/example/cmd/_test/xonsh.py
+++ b/example/cmd/_test/xonsh.py
@@ -9,9 +9,12 @@ def _example_completer(context):
         from xonsh.completers.tools import RichCompletion
         output, _ = Popen(['example', '_carapace', 'xonsh', '_', *[a.value for a in context.args], context.prefix], stdout=PIPE, stderr=PIPE).communicate()
         try:
-            return {RichCompletion(c["Value"], display=c["Display"], description=c["Description"], prefix_len=len(context.raw_prefix)) for c in loads(output)}
+            result = {RichCompletion(c["Value"], display=c["Display"], description=c["Description"], prefix_len=len(context.raw_prefix)) for c in loads(output)}
         except:
-            return
+            result = {}
+        if len(result) == 0:
+            result = {RichCompletion(context.prefix, display=context.prefix, description='', prefix_len=len(context.raw_prefix))}
+        return result
 
 
 from xonsh.completers._aliases import _add_one_completer