nonsequitur / inf-ruby

219 stars 68 forks source link

open repl fails when not in structured ruby project #173

Closed bo-tato closed 1 year ago

bo-tato commented 1 year ago

I mostly use ruby for small single file scripts without any formal project structure. Right now emacs open-repl commands calls inf-ruby-console-auto which errors with "No matching directory found" if it doesn't see a Gemfile or certain other markers of different kinds of ruby projects. Ruby is popular as a language for small scripts, I think it'd be nicer if it doesn't detect any project structure then it falls back to just running inf-ruby in the current directory rather than erroring?

dgutov commented 1 year ago

You can still M-x inf-ruby, right?

So the question is whether to switch over to it silently when the project is not recognized. The downside of such approach would be in users who have somewhat unusual project structures, they will call the first command, see it succeed, and then probably expect that the project REPL is loaded properly. Whereas it really didn't. Is that better?

bo-tato commented 1 year ago

yea, M-x inf-ruby works and you're right if people are expecting to get a project repl and it spawns a non-project repl that could cause more confusion. Maybe just the error message could be a little clearer what is going on, "No matching project directory found, run M-x inf-ruby for a non-project repl"? Or for example robe-start if there is no inf-ruby process will do: (yes-or-no-p "No Ruby console running. Launch automatically?"). Here it could do a y/n prompt "No matching project type or directory found, would you like to start plain inf-ruby in the current directory?"

dgutov commented 1 year ago

How about message like this?

"No known project type found. Try `M-x inf-ruby' instead."

That would leave using the alternative command up to the user, though. Is automatic failover important for your use case?

bo-tato commented 1 year ago

Doesn't really matter for my usecase, it's just for making it less confusing for the next person to come across it. Magic of emacs is it works for any usecase :) For mine I just have on opening a ruby script auto call inf-ruby and robe-start in a side window unfocused as I don't actually type in repl just look at the output there from doing ruby-send-block etc. Just when I first used ruby in emacs a month or so ago the cross-language +eval/open-repl got that error and inf-ruby worked, so I just used inf-ruby. Now I had a little time to investigate my ever growing list of emacs issues I encounter, look at source and realize it's expecting a ruby project and getting an error when it's a standalone script. Your new message sounds good, it says clearly why the command didn't work and suggests an alternative if they're really intending to use outside a project.

dgutov commented 1 year ago

Excellent.

The thing about robe-start, is it calls inf-ruby-console-auto when there is not existing REPL around. And for this scenario it leads to an error (with a better message now), forcing the user to call M-x inf-ruby manually themselves. I think it's fine (explicitness is a plus in unusual situations), so since you also agree, I'll just go ahead and change the error message.

Thanks for the report. :slightly_smiling_face: