neovim / neovim-ruby

Ruby support for Neovim
MIT License
340 stars 17 forks source link

ArgumentError because of a seemingly unrelated line #59

Closed mhinz closed 5 years ago

mhinz commented 5 years ago

Hi,

Today I started playing around with a Ruby rplugin and I'm not really sure if this is a bug or just PEBKAC. Here's a bit of code:

require 'net/http'
require 'uri'
require 'json'

class Travis
  def request(options)
    uri = URI('https://api.travis-ci.com/user')

    req = Net::HTTP::Get.new(uri)
    req['Travis-API-Version'] = 3
    req['User-Agent']         = 'testing a script'
    req['Authorization']      = "token #{ENV['TRAVIS_TOKEN']}"

    response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http|
      http.request(req)
    }

    if response.is_a?(Net::HTTPForbidden)
      "Access denied. Typo in $TRAVIS_TOKEN?"
    elsif not response.is_a?(Net::HTTPSuccess)
      response.body
    else
      JSON.pretty_generate(JSON.parse(response.body))
    end
  end
end

Neovim.plugin do |plug|
  plug.command(:Travis, nargs: 0) do |nvim|
    travis = Travis.new()
    # response = travis.request()
    nvim.command("echomsg 'blah'")
  end
end

When I use :Travis, I get the expected "blah". But when I uncomment that one line, I get:

Exception handling /Users/mhi/.vim/bundle/nvim-travis/rplugin/ruby/travis.rb:command:Tra
vis: (ArgumentError) wrong number of arguments (given 0, expected 1)

Huh? :) I think Travis#request is not even run, it fails earlier.

Do you happen to know what's wrong with it?

alexgenco commented 5 years ago

I think it's because you are calling request with no arguments but it takes a single options argument.

mhinz commented 5 years ago

Yes, I'm an idiot. I somehow thought it was coming from this plugin...

Sorry for the noise and thanks for the plugin!


... that said, I actually have another question. I could open another issue for it, but I guess it's not really worth it:

How does a Ruby user usually setup their repos for development? E.g. in Python I do pip3 install -e . in a package and it gets registered as "edit mode" (opposed to something installed remotely via pip3 install). Every Python code that now does import mypackage automatically uses my local master branch.

How do you do that in Ruby? How can I get Nvim to use my local copy of this plugin instead of what got installed via gem install neovim?

The best I found so far was somehow using bundler install --binstubs, but it feels like your system quickly gets clobbered with lots of stub files that do all kinds of magic with redirecting paths and it's weird if you switch between repos etc.

Sorry if the answer is obvious to a regular Ruby user!

alexgenco commented 5 years ago

If you run bundle exec rake install in your local repo, it will install the package locally as is. But you have to run that after every change I think.