dense-analysis / neural

AI Vim/Neovim code generation plugin (OpenAI, ChatGPT, and more)
MIT License
426 stars 19 forks source link

Run Neural to ask a specific question about part of a code sample #49

Open edi9999 opened 3 weeks ago

edi9999 commented 3 weeks ago

Right now, I was using Neural (successfully) to do some changes in my code :

def my_health(host)
  url = URI.parse("#{host}/health")

  req = Net::HTTP::Post.new(url.path)
  req.body_stream = StringIO.new(query)
  req.content_length = query.bytesize
  req.set_content_type("multipart/form-data", { "boundary" => BOUNDARY })

  Net::HTTP.start(url.host, url.port) {|http|
    begin
      response = http.request(req)
      if response.code != '200'
        raise "Error from server #{response.code}"
      end
      return response.body
    rescue => e
      raise e
    end
  }
end

This code was pasted from somewhere else in my application, and is for a POST request.

I just wanted to ask Chatgpt to change the code in order to do a GET Request.

What I did :

Select the content of the function using vim

Copy it to the main register

Run ":Neural Rewrite the following code to do a GET request : <hit Ctrl-R+" to paste the code>"

What I would have liked: (to avoid copy-pasting)

What I would have liked would be to ask a question to Neural and provide the context as a visual selection.

`:'<,'>Neural 'Please rewrite the code below to use a GET request on the /health route'

This would make life easier to be able to do that without any registers.

w0rp commented 1 week ago

@edi9999 Look at the documentation and look into the existing NeuralExplain command for a range. I recommend playing around with the code and creating pull requests tomake improvements to it.