syntax_suggest icon indicating copy to clipboard operation
syntax_suggest copied to clipboard

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

Open jeremyevans opened this issue 6 months ago • 0 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.

jeremyevans avatar Jan 18 '24 19:01 jeremyevans