carapace-sh / carapace

command argument completion generator for spf13/cobra
https://carapace.sh
Apache License 2.0
435 stars 11 forks source link

xonsh hangs when running carapace _carapace #1013

Open bestlem opened 7 months ago

bestlem commented 7 months ago

Current Behavior

Any command beginning carapace _carapace hangs - xonsh is taking up 180% CPU

Expected Behavior

I assume just runs to an end

Steps To Reproduce

Just run carapace _carapace xonsh or replace xonsh by any other file name.

Version

1.0.1

OS

Shell

Anything else?

The command does run in fish

It is also unclear what should be set in xonsh.

the test https://github.com/carapace-sh/carapace/blob/db7e596f45c5491e96964658de49ca0e1242086d/example/_test/invoke_xonsh#L7 sets no environment.

https://github.com/carapace-sh/carapace-bin says

# xonsh (~/.config/xonsh/rc.xsh)
COMPLETIONS_CONFIRM=True
exec($(carapace _carapace))

But the first line is not setting an environment variable so I think makes no effect. (It needs a $ to begin with) Also the command show elsewhere is carapace _carapace xonsh (or any other shell name)

This documentation issue means that I am uncertain how to start carapace.

rsteube commented 7 months ago

Cannot reproduce this issue so I need a bit more information. Maybe logs give some insight? https://carapace-sh.github.io/carapace-bin/setup/environment.html#carapace_log

$CARAPACE_LOG=1
exec($(carapace _carapace))
bestlem commented 7 months ago

Tried logging but there is nothing in /tmp and in $TMPDIR/carapace just a zero byte file.

Even carapace --help hangs (but only sometimes)

However doing an xonsh --no-rc and then calling carapace in another shell works.

It seems only to happen when xonsh is called directly from iTerm or terminal. Even in that case if I then run zsh from that shell and then xonsh it works.

ie steps to reproduce Open Terminal.app Choose Run Command In that do xonsh --no-rc Then run /carapace _carapace

I have tries with xonsh from macports (both 0.15.1 and 0.16.0) and nix but carapace only in nix as it is not in macports

rsteube commented 7 months ago

So I tried the macports version of xonsh but still no luck. Only issue I can see so far is that the shell detection doesn't work since neither in brew or macports the parent process is named xonsh (just Python).

bestlem commented 7 months ago

I don't think the issue is which version of xonsh is used. I got the issue with both macports and nix, and different versions.

The difference seems to be is xonsh launched from another shell or not.

Did you run from Terminal.app without going through another shell? Unfortunately I don't think this is testable automatically as most test environments set up a shell.

I would note that carapace _carapace fish (or bash or zsh or rubbish) also hangs for me under a bare xonsh so it might not be the shell detection. Looking at https://github.com/carapace-sh/carapace/blob/master/internal/shell/shell.go I think that if I do pass in a shell name then the shell detection should not be called. They all work if I call xonsh from another shell first. (carapace _carapace rubbish gives the list of supported shells)

From xonsh the current process name is python3.11 in nix. This is true if run from inside another shell.

EricDepagne commented 2 months ago

I had the same issue. I use xonsh within tmux. And the faulty part of my configuration was this line, in my xonshrc file: # $SHELL = $(which xonsh) # so tmux will stop loading bash Once commented out, xonsh started fine and carapace did not gulp all my CPU.

bestlem commented 2 months ago

I suspect https://github.com/xonsh/xonsh/issues/5244 might be a related issue