syntax_suggest
syntax_suggest copied to clipboard
syntax_suggest CLI doesn't work when it is a standard gem
The syntax_suggest CLI that ships in Ruby 3.3.0 and Ruby 3.2.3 fails:
$ /usr/local/bin/syntax_suggest33 -h
/usr/local/lib/ruby/gems/3.3/gems/syntax_suggest-2.0.0/exe/syntax_suggest:3:in `require_relative': cannot load such file -- /usr/local/lib/ruby/gems/3.3/gems/syntax_suggest-2.0.0/lib/syntax_suggest/api (LoadError)
from /usr/local/lib/ruby/gems/3.3/gems/syntax_suggest-2.0.0/exe/syntax_suggest:3:in `<top (required)>'
from /usr/local/bin/syntax_suggest33:25:in `load'
from /usr/local/bin/syntax_suggest33:25:in `<main>'
$ /usr/local/bin/syntax_suggest32 -h
/usr/local/lib/ruby/gems/3.2/gems/syntax_suggest-1.1.0/exe/syntax_suggest:3:in `require_relative': cannot load such file -- /usr/local/lib/ruby/gems/3.2/gems/syntax_suggest-1.1.0/lib/syntax_suggest/api (LoadError)
from /usr/local/lib/ruby/gems/3.2/gems/syntax_suggest-1.1.0/exe/syntax_suggest:3:in `<top (required)>'
from /usr/local/bin/syntax_suggest32:25:in `load'
from /usr/local/bin/syntax_suggest32:25:in `<main>'
To handle this case, I think syntax_suggest should rescue a LoadError failure in the require_relative
call, and try to use a regular require. You can use require File.join(RbConfig::CONFIG['rubylibdir'], 'syntax_suggest', 'api')
if you want to use an absolute path.
@andrykonchin and I noticed the same issue when updating to Ruby 3.2.4.
There is a new executable syntax_suggest
but it doesn't work:
$ chruby 3.2.2
Using ruby-3.2.2: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
$ syntax_suggest
zsh: syntax_suggest: command not found...
$ ruby -v
ruby 3.2.4 (2024-04-23 revision af471c0e01) [x86_64-linux]
$ syntax_suggest
/home/eregon/.rubies/ruby-3.2.4/lib/ruby/gems/3.2.0/gems/syntax_suggest-1.1.0/exe/syntax_suggest:3:in `require_relative': cannot load such file -- /home/eregon/.rubies/ruby-3.2.4/lib/ruby/gems/3.2.0/gems/syntax_suggest-1.1.0/lib/syntax_suggest/api (LoadError)
from /home/eregon/.rubies/ruby-3.2.4/lib/ruby/gems/3.2.0/gems/syntax_suggest-1.1.0/exe/syntax_suggest:3:in `<top (required)>'
from /home/eregon/.rubies/ruby-3.2.4/bin/syntax_suggest:25:in `load'
from /home/eregon/.rubies/ruby-3.2.4/bin/syntax_suggest:25:in `<main>'
It would be good to fix this or to remove this executable if unnecessary.
@schneems @hsbt Could you look at this? It's still broken in 3.3.5:
$ syntax_suggest --help
/home/eregon/.rubies/ruby-3.3.5/lib/ruby/gems/3.3.0/gems/syntax_suggest-2.0.0/exe/syntax_suggest:3:in `require_relative': cannot load such file -- /home/eregon/.rubies/ruby-3.3.5/lib/ruby/gems/3.3.0/gems/syntax_suggest-2.0.0/lib/syntax_suggest/api (LoadError)
from /home/eregon/.rubies/ruby-3.3.5/lib/ruby/gems/3.3.0/gems/syntax_suggest-2.0.0/exe/syntax_suggest:3:in `<top (required)>'
from /home/eregon/.rubies/ruby-3.3.5/bin/syntax_suggest:25:in `load'
from /home/eregon/.rubies/ruby-3.3.5/bin/syntax_suggest:25:in `<main>'
Probably it should be require "syntax_suggest/api"
and not require_relative
for an executable