ruby / syntax_suggest

Searching for unexpected `end` syntax errors takes a lot of time. Let this gem do it for you!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

syntax_suggest CLI doesn't work when it is a standard gem

jeremyevans opened this issue · comments

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.