Process hangs while running ruby formatter(stree) as external tool

There is a new ruby formatter in town called syntax_tree. I'm attempting to use its write cli : https://github.com/ruby-syntax-tree/syntax_tree#write

It works fine in my shell:
```
❯ bundle exec stree write ./spec/features/foo.rb
./spec/features/foo.rb 2ms

❯ stree write ./spec/features/foo.rb
./spec/features/foo.rb 2ms

❯ which stree
/Users/me/.rbenv/shims/stree
```

There isn't a plugin, so I'm attempting to hook it up as an external tool:

 

When I run the tool though, it just opens a run tab, shows `/Users/me/.rbenv/shims/stree write /Users/me/foos/spec/foo.rb`, then just hangs and I have to ctrl+C to kill it. Nothing gets formatted. Is there something I'm missing? If I replace stree with echo under program, things work fine and it doesn't hang.

0

Hello,

Just to be sure, does the command work if you run it the way it's run by IDE?

0

I'm not sure if this is what you mean, but if I copy the same command from the run tab and paste it inside of a Terminal in RubyMine to run it, it works fine.

0

This may be caused by running rbenv ruby without specifying the version. Could you please try changing the command so that 

env RBENV_VERSION=2.7.2

is passed before the command? In addition, please try running the same command from the Run tab but in

/bin/bash -c 'command'

format.

0

Good thought, but still no luck. External tool hangs, but works fine in a run tab:

Shell script run configuration: 

run tab:
❯ /bin/zsh -c " export RBENV_VERSION=3.1.2 && /Users/me/.rbenv/shims/stree write /Users/me/foo.rb "
/Users/me/foo.rb 18ms

 

External tool:

/bin/zsh -c " export RBENV_VERSION=3.1.2 && /Users/me/.rbenv/shims/stree write /Users/me/foo.rb "

# hangs
0

Thank you for trying it. Could you please specify your IDE's version, is it on the latest one?

0

RubyMine 2022.1.2

Build #RM-221.5787.34, built on June 1, 2022

0

I've tried to reproduce it in RubyMine 2022.3 EAP with the following configuration but didn't manage to (meaning, it works fine). Could you please try configuring it the same way?

0

Updated RubyMine and used the same settings. Still hangs. I'm on MacOS v12.4.

Replacing /usr/bin/env with `cat` works as expected. Not sure whats going on. Are there any logs I can look at?

0

Just to be sure, did you update to 2022.3 EAP? Could you please attach a screenshot of your External tool as it looks now?

In addition, please try running that command and piping the output to the file like

command ... > result.txt

and attach the content of that file. 

0

Looks like I'm on 2022.2.3, not .3... Is .3 a development build? Check for updates says I'm on latest.

 

Redirecting to a file doesn't appear to be creating the file at all. I also tried the following, and I got an empty file for stree2.out, but no stree3.out(same with &>): 

0

Can you please try redirecting it not via External tool, but via Terminal?

0

Yep that worked

❯ /bin/zsh -c " export RBENV_VERSION=3.1.2 && /Users/gm/.rbenv/shims/stree write /Users/gm/foo.rb  > /tmp/stree2.out" > /tmp/stree3.out

❯ cat /tmp/stree2.out
/Users/gm/foo.rb 1ms

0

Thank you for trying. Could you please check also the following command in the Terminal (that should be closer to conditions of External tool):

/bin/zsh -c " export RBENV_VERSION=3.1.2 && /Users/gm/.rbenv/shims/stree write /Users/gm/foo.rb" >output.txt 2>error.txt </dev/null
0

Good suggestion. It appears that passing an input seems to be breaking things. It doesn't hang, but it no longer works either. Looks like when you pass it in an input, it tries to format the input rather than the files listed after write. I'll keep playing and see if I can come up with a command which doesn't let the input pass through to stree...

0

I struggled a bit trying to get redirection or piping to work, but I eventually got something to going by using a custom script and writing to a tmp file. Not ideal, but its fast enough and gets the job done.

❯ cat /usr/local/bin/fstree
export RBENV_VERSION=3.1.2

/bin/zsh -c "/Users/gm/.rbenv/shims/stree format <$1  &> /tmp/formatted.txt"
mv /tmp/formatted.txt $1

0

Sounds like the root cause here was a broken version of syntax tree: https://github.com/ruby-syntax-tree/syntax_tree/issues/159. 

0

请先登录再写评论。