sublimelsp / LSP-jdtls

Convenience package for the Eclipse JDT language server

Home Page:https://packagecontrol.io/packages/LSP-jdtls

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for SOCKS proxies

RevanProdigalKnight opened this issue · comments

I'm working in a place where in order for certain things to run properly on my system I have set the HTTP_PROXY and HTTPS_PROXY environment variables to point to a proxy, but the LSP-jdtls extension fails to start with the following message:

image

The stack trace in the console:

Unable to start subprocess for jdtls
Traceback (most recent call last):
  File "C:\Users\user\AppData\Roaming\Sublime Text 3\Installed Packages\LSP.sublime-package\plugin/core/windows.py", line 245, in start_async
    plugin_class.install_or_update()
  File "C:\Users\user\AppData\Roaming\Sublime Text 3\Installed Packages\LSP-jdtls.sublime-package\modules/jdtls.py", line 66, in install_or_update
    installer.install_or_update()
  File "C:\Users\user\AppData\Roaming\Sublime Text 3\Installed Packages\LSP-jdtls.sublime-package\modules/installer.py", line 137, in install_or_update
    extract_tar(JDTLS_URL.format(version=version), jdtls_path())
  File "C:\Users\user\AppData\Roaming\Sublime Text 3\Installed Packages\LSP-jdtls.sublime-package\modules/installer.py", line 69, in extract_tar
    _extract_file(url, path, lambda x: tarfile.open(x, "r:gz"))
  File "C:\Users\user\AppData\Roaming\Sublime Text 3\Installed Packages\LSP-jdtls.sublime-package\modules/installer.py", line 48, in _extract_file
    download_file(url, compressed_file)
  File "C:\Users\user\AppData\Roaming\Sublime Text 3\Installed Packages\LSP-jdtls.sublime-package\modules/installer.py", line 35, in download_file
    with urlopen(url) as response, open(file_name, "wb") as out_file:
  File "./python3.3/urllib/request.py", line 156, in urlopen
  File "./python3.3/urllib/request.py", line 469, in open
  File "./python3.3/urllib/request.py", line 487, in _open
  File "./python3.3/urllib/request.py", line 447, in _call_chain
  File "./python3.3/urllib/request.py", line 785, in <lambda>
  File "./python3.3/urllib/request.py", line 813, in proxy_open
  File "./python3.3/urllib/request.py", line 469, in open
  File "./python3.3/urllib/request.py", line 492, in _open
  File "./python3.3/urllib/request.py", line 447, in _call_chain
  File "./python3.3/urllib/request.py", line 1316, in unknown_open
urllib.error.URLError: <urlopen error unknown url type: socks5>

I have attempted to circumvent the issue by using ProjectEnvironment, but it does not appear to work correctly with other plugins.

Not exactly sure what is the issue here. Do other LSPs work?

According to https://bugs.python.org/issue34038 it may help to enter these commands into the sublime console (in 3.3 mode!) before starting LSP-jdtls:

import socket
import socks

socks.set_default_proxy(socks.SOCKS5, "localhost",port=8888)  # also try your actual proxy
socket.socket = socks.socksocket

If that works, you can put these commands into a custom sublime plugin that executes these commands when ST starts.

Other LSPs work, but they aren't attempting to perform HTTP(S) operations to non-localhost destinations immediately upon startup like the jdtls plugin does. Some of the other LSPs I have installed are performing requests against the internet at large, but it looks like they aren't using urllib.

I'm having some trouble running the code you offered in the console because I can't find any documentation on how to switch to 3.3 mode, could you point me somewhere to help with that?

You can right-click the console input to switch to 3.3 mode

Thanks, now I'm getting ImportError: No module named 'socks'. I'm guessing at this point that I need to find some other way around the problem.

I guess you would have to vendor pysocks for this to work. At this point, I don't think it can or at least should be fixed within LSP-jdtls.

Alright. Thanks for your help.