sublimelsp / LSP-julia

Julia support for Sublime's LSP plugin using LanguageServer.jl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to start julia LSP server with juliaup

dfarmer opened this issue · comments

I'm on Windows 11 and use juliaup to manage my julia installations. It seems that juliaup creates (the windows equivalent of) a symlink to the currently selected julia environment in {USER}\AppData\Local\Microsoft\WindowsApps\julia.exe -- that directory is on my path but even when I explicitly set the path for LSP-Julia I get the error that the file is not found.

In Sublime's console I was able to confirm that Sublime's python env can see the executable and run it successfully.

>>> 'julia.exe' in os.listdir(os.environ['PATH'].split(';')[-1])
True
>>> os.system('julia.exe --version')
0

If I manually set LSP-Julia's path to one of the julia environments in {user}\.julia\.juliaup (i.e., resolve the symlink for it) then the LSP server works fine (but I'd like it to be able to use the link so I don't have to continually update the config as I update julia).

Just trying to work through it a little bit I see in plugin.py that is is failing the shutil.which check that gives that error message, but when I just try to run the equivalent commands in the console it works fine...

>>> shutil.which('julia')
'C:\\Users\\dan_f\\AppData\\Local\\Microsoft\\WindowsApps\\julia.EXE'

>>> subprocess.check_output([shutil.which('julia'), '--version'])
b'julia version 1.8.5\n'

>>> subprocess.check_output(['julia', '--version'])
b'julia version 1.8.5\n'

So it seems like everything should just work with the way you have it. 🤔 I don't know if it's something about how Sublime runs it?

I've tested with juliaup and can confirm the issue.

It seems that shutil.which works with the symlink only on Python 3.8, but not on Python 3.3 (the console runs on 3.8 by default, but it can be changed via right click). LSP runs on Python 3.3.

I wonder whether there is an alternative to shutil.which, that also works with symlinks on Python 3.3.

Digging into the implementation for shutil.which, it turns out that os.path.exists returns True for the symlink on Python 3.8, but False on Python 3.3. There seems to be a way to check the symlink on Python 3.3 by using os.access and setting follow_symlinks to False, but that argument isn't passed from shutil.which or os.path.exists, and I don't want backport/reimplement all of that for Python 3.3.

I've disabled that check for now in ed87d97, so that it should work when using juliaup. I will make a new release for Package Control soon.