sublimelsp / LSP-julia

Julia support for Sublime's LSP plugin using LanguageServer.jl
MIT License
20 stars 2 forks source link

Setting up LSP-Julia on Linux #12

Open lieskjur opened 2 years ago

lieskjur commented 2 years ago

Hi, mostly out of interest I wanted to set-up a Julia LS in Sublime-Text version 4.4121-1 running on Manjaro with kernel version 5.14.18-1 and I must say I found the installation guide very lacking.

I had to do a bit of googling to figure out that i first need to run

julia> import Pkg;
julia> Pkg.add("LanguageServer")
julia> Pkg.add("SymbolServer")

as described in LSP docs. And after installing LSP-julia I have to modify the "command" setting in LSP-julia.sublime-settings to

"command": ["bash", "/LANGUAGE_SERVER_PATH/contrib/languageserver.sh"],

Where the path can be found by running

julia> using LanguageServer
julia> pathof(LanguageServer)
"/LANGUAGE_SERVER_PATH/src/LanguageServer.jl"

I suggest that some of these steps should be added to the "README".

jwortmann commented 2 years ago

Hi, the docs link you posted is outdated, the current version for LSP on Sublime Text 4 is https://lsp.sublimetext.io/. But with LSP-julia installed, you don't need to add the LanguageServer/SymbolServer manually, because LSP-julia will automatically do that for you when you open a Julia file for the first time after installing the package (it will create an environment and then use the Julia package manager to download/instantiate the required packages). The main reason for this is because LanguageServer.jl had some breaking changes in the past and they don't publish new version tags often, so it can be quite difficult to ensure a compatible version to this plugin if the server gets installed manually.

I must say that I have only tested the installation on Windows, but I see no reason why it wouldn't work on Linux. So if you install LSP-julia (and of course LSP) via package control, then everything should work automatically. You just need to wait a bit until the package manager has installed the language server, but it should be displayed in the status bar. Feedback if it works for you on Linux would be appreciated.

By the way, the shell script in the "command" for Linux isn't really needed anymore, afaik it was just a workaround for a former bug in the LSP version on Sublime Text 3, which caused server processes not being killed after closing Sublime Text in some cases.

lieskjur commented 2 years ago

Well, that definitely didn't happen for me. Of course I first tried just following the guide here but when it didn't work I started troubleshooting myself.

I'll give it another go tomorrow, on a minimally configured distro that I should have on a thumb-drive somewhere. For all I know, I might have just not waited long enough. But I do remember getting a "julia exited with error code 1" or something like that.

jwortmann commented 2 years ago

Hm, could you look if you have a folder under $Data/Package Storage/LSP-julia? I'm not sure where the Sublime Text Data path ($Data) exactly is under Linux, but you should find it if you run sublime.cache_path() in the ST console, and then go up one directory. In case the folder was created, try to delete it and LSP-julia should create the folder again and try to install the server after the next start.

Also you could see if there are any errors in the ST console?

lieskjur commented 2 years ago

Ok, so following the guide on an almost clean install I get "julia exited with status code 1" pop-up with

julia: ERROR: ArgumentError: Package LanguageServer [2b0e0bc5-e4fd-59b4-8912-456d1b03d8d7] is required but does not seem to be installed:
julia:  - Run `Pkg.instantiate()` to install all recorded dependencies

in "Output: Language servers" and no errors in the ST "Console"

Here is the LSP-julia folder it generates in the process

jwortmann commented 2 years ago

I think the "julia exited with status code 1" pop-up is created by LSP trying to start the server, even though it hasn't been installed correctly.

The folder looks exactly as it is supposed to be, and the "ready" file should only have been created if the installation was successful. After copying the Project.toml/Manifest.toml files, the plugin runs the "Pkg.instantiate()" in https://github.com/sublimelsp/LSP-julia/blob/91fc2f81c57b63431b184bc2d56ceeb6340de703/plugin.py#L156 to download the required Julia packages, and only proceeds if its returncode is 0, i.e. no error. So I'm not sure what is going wrong here.

On Windows, Pyhton's subprocess.call() creates a console window where you can see the detailed output from the Julia package manager during this installation, and it could give a hint about the problem. But I think on Linux and macOS the console window is hidden.

What happens if you manually run the same command in a shell:

julia --startup-file=no --history-file=no --project="full/path/to/Package Storage/LSP-julia/aa8287a" --eval "import Pkg; Pkg.instantiate()"

Maybe I have missed something and the returncode can still be 0, even when there is some kind of error or unexpected result. (After successfully running the command, the language server should start working for you too, but ideally we want to know why it doesn't work from this LSP-julia plugin.)

lieskjur commented 2 years ago

After running the command in a terminal, the language server start without an issue.

Well, the return code was 1 for me... from my experience it could be something as simple as the space in ~/Package Storage/....

lieskjur commented 2 years ago

On a potentially related note, I was expecting I'd see documentation on hover for functions from all packages, not just those in Base..

jwortmann commented 2 years ago

The "ready" file should not have been created if the returncode was 1: https://github.com/sublimelsp/LSP-julia/blob/91fc2f81c57b63431b184bc2d56ceeb6340de703/plugin.py#L157-L162


On a potentially related note, I was expecting I'd see documentation on hover for functions from all packages, not just those in Base..

Documentation on hover for functions from all packages is what is supposed to happen. Make sure that you have chosen the correct Julia environment (displayed in the status bar), and maybe wait a little bit in case the server is still indexing packages (also displayed in the status bar).

lieskjur commented 2 years ago

chosen the correct Julia environment

could you please elaborate?


This is what my status bar displays: image and RigidBodyDynamics is indeed the package whose functions' hovers I would like to see.

lieskjur commented 2 years ago

Is there any way to get more logs? I feel like I am not giving you any relevant information.

Also, the file I am editing is inside of RigidBodyDynamics itself.

jwortmann commented 2 years ago

could you please elaborate?

There is a command in the command palette to change the active Julia environment which is used to get the symbol information, autocomplete, and other features which depend on the environment's packages. LSP-julia should in most cases already determine the correct environment when the server is started, which seems to be the case for you.

Also, the file I am editing is inside of RigidBodyDynamics itself.

Ah, so you're basically developing the RigidBodyDynamics package. There is a known bug/inconvenience that the language server doesn't index the active project, so that's probably why the hover for functions from other files of that package doesn't work for you. It is tracked at https://github.com/julia-vscode/LanguageServer.jl/issues/988. A possible temporary workaround could be to explicitly include("src/RigidBodyDynamics.jl") in your file. But in general, if you're using/import other packages that were added to your environment, things like hover, autocomplete etc. for those packages should work (after indexing).

lieskjur commented 2 years ago

Huh, the interesting thing is that once I changed the LSP-julia environment to "v1.6" I started getting hovers, etc. for all packages including RigidBodyDynamics (previously I didn't get hover info on any other packages except Base. either).

jwortmann commented 2 years ago

Then you have probably added all those packages to your global default environment. I'd recommend reading the section about environments in the Julia docs https://docs.julialang.org/en/v1/manual/code-loading/#Environments and in Pkg.jl https://pkgdocs.julialang.org/v1/environments/ and to create separate project environments for all non-trivial projects to reduce the risk of package version incompatibilities. If you add only the needed packages to an activated project environment with the Julia package manager, it will create an entry for these packages in the Project.toml file of the project, and this is from where the language server knows which packages it should index.

lieskjur commented 2 years ago

Thank you very much for everything. This last piece of information about the environments will certainly come in handy at some point.