zbirenbaum / copilot.lua

Fully featured & enhanced replacement for copilot.vim complete with API for interacting with Github Copilot
MIT License
2.64k stars 75 forks source link

Auth signin behind corporate http proxy #145

Closed raulcesar closed 1 year ago

raulcesar commented 1 year ago

First of all, let me just say that this is an Awesome plugin!! Works great at home! At work, I am behind an HTTP proxy, so.... headache!!!!

I tried to configure proxy, setting vim.g.copilot_proxy, but it didn't work.

I keep getting a timeout on auth signin.

RPC[Error] code_name = InternalError, message = "Request signInInitiate failed with message: connect ETIMEDOUT 20.201 .28.151:443"

I tried setting vim.g.copilot_proxy_strict_ssl=false just to see if this had any effect, but still get the same error.

Just as a side note, codepilot is working on vsCode (behind the proxy).

I use a localhost proxy (port 3128) with no authentication necessary.

Any ideas?

Also, sorry for the stupid question, but is the "copilot/dist" folder available in non minified form?

MunifTanjim commented 1 year ago

Does it work with with official plugin? https://github.com/github/copilot.vim If the official plugin doesn't support proxy, this plugin can't do it either.

Also, sorry for the stupid question, but is the "copilot/dist" folder available in non minified form?

Nope, it's copied directly from https://github.com/github/copilot.vim/tree/release/copilot/dist

raulcesar commented 1 year ago

Thanks for reply. I'll try it with the official plugin and see what happens. Corporate proxies can be a real pain!

zbirenbaum commented 1 year ago

I tried to configure proxy, setting vim.g.copilot_proxy, but it didn't work.

If this is a setting in the official copilot.vim, then this will be easy to implement because we can just copy how they do it. I'll check now.

Edit: copilot.vim does have this option, and it appears that config params are set inside the message sent with setEditorInfo.

We have it as well according to api.lua. I'll create a snippet for you to try

Also, sorry for the stupid question, but is the "copilot/dist" folder available in non minified form?

I've asked multiple times on the discussions if they have any plans to make an api or do this, but they ignore it or shut it down pretty fast. I get it, no dev wants to be the one who says something management won't approve of, but it is quite frustrating.

Best I can do is give you a file formatted with prettier that's a bit easier to read and debug. I recommend opening/editing it with treesitter and lsp disabled.

https://gist.githubusercontent.com/zbirenbaum/4036ba80e1260a17167aa3347e2acbe3/raw/3f5327b80fa1ffedeed86737222924967dc92116/formatted.js

raulcesar commented 1 year ago

Awesome! Thanks for the effort! I'll mess around with the formatted file this weekend to see if I can find out why the proxy isn't working. I did a quick test with the vim plugin, and that didn't work either... in fact, It's actually worse, because when I did a "copilot: setup" on the "official" one, it actually blocked the whole NEOVIM editor, whereas this plugin just runs the co-routine in the background and after a while prints the timeout error message.

I did a little digging around the official sites (both the vim plugin and the copilot "documentation"), and I got the feeling that they don't seem that eager to support third party efforts.

zbirenbaum commented 1 year ago

Awesome! Thanks for the effort! I'll mess around with the formatted file this weekend to see if I can find out why the proxy isn't working. I did a quick test with the vim plugin, and that didn't work either... in fact, It's actually worse, because when I did a "copilot: setup" on the "official" one, it actually blocked the whole NEOVIM editor, whereas this plugin just runs the co-routine in the background and after a while prints the timeout error message.

I did a little digging around the official sites (both the vim plugin and the copilot "documentation"), and I got the feeling that they don't seem that eager to support third party efforts.

No worries, I'm away from my laptop atm but I'll try to provide that snippet once I'm back.

Could you expand on what you mean by blocking the whole editor? Like it freezes?

raulcesar commented 1 year ago

Exactly. It freezes the editor. Again, to clarify this FREEZING behavior does NOT happen on copilot.lua. It only happens on copilot.vim (this "oficial" plugin) when I call the command "Copilot Setup".

In copilot.lua (when i call "Copilot auth"), it just runs in the background, but is unable to communicate with the server and eventually spits out the timeout message.

zbirenbaum commented 1 year ago

Exactly. It freezes the editor. Again, to clarify this FREEZING behavior does NOT happen on copilot.lua. It only happens on copilot.vim (this "oficial" plugin) when I call the command "Copilot Setup".

In copilot.lua (when i call "Copilot auth"), it just runs in the background, but is unable to communicate with the server and eventually spits out the timeout message.

If you write some log statements inside the formatted file I sent using console.error (this will print the message to :LspLog) you might be able to get more info on why it is failing.

You can use the file by just changing index.js inside dist to call it instead of the existing agent, or renaming it and overwriting the existing one.

If even official solutions are failing it sounds like this will be pretty hard to debug without a replicable environment, especially judging by how many reports of similar issues the discussion forums seem to have.

One unorthodox solution you might not have tried yet is this: https://github.com/community/community/discussions/13113#discussioncomment-3018572

vim.g.coplot_proxy and vim.g.copilot_proxy_strict_ssl are read inside util.get_network_proxy, so if you already tried those and the official implementation isn't working I'm not sure I know how to help without more info

PapyKahan commented 1 year ago

FIY copilot.vim is working behind a corporate proxy, but their url parsing is faulty. I've done a fix on my own fork. Now it works as expected. So official implementation is working.

MunifTanjim commented 1 year ago

@PapyKahan this plugin actually parses the proxy url differently: https://github.com/zbirenbaum/copilot.lua/blob/a4a37dda9e48986e5d2a90d6a3cbc88fca241dbb/lua/copilot/util.lua#L245-L299

And it produces the same result as the fix on your fork. 🤔

PapyKahan commented 1 year ago

@PapyKahan this plugin actually parses the proxy url differently:

https://github.com/zbirenbaum/copilot.lua/blob/a4a37dda9e48986e5d2a90d6a3cbc88fca241dbb/lua/copilot/util.lua#L245-L299

And it produces the same result as the fix on your fork. 🤔

What do you mean by same result ? Whit my fix on my fork of Copilot.vim I'm able to connect through my corporate proxy with Copilot.vim. With the right configuration of my proxy settings I've never managed to connect through my corporate proxy with copilot.lua even though copilot.lua proxy url parsing is working correctly and gives the right parameters.