Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting up LSP-Julia on Linux #12

Open
JurajLieskovsky opened this issue Nov 20, 2021 · 14 comments
Open

Setting up LSP-Julia on Linux #12

JurajLieskovsky opened this issue Nov 20, 2021 · 14 comments

Comments

@JurajLieskovsky
Copy link

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".

@JurajLieskovsky JurajLieskovsky changed the title Setting up LSP-Julia Setting up LSP-Julia on Linux Nov 20, 2021
@jwortmann
Copy link
Member

jwortmann commented Nov 20, 2021

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.

@JurajLieskovsky
Copy link
Author

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
Copy link
Member

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?

@JurajLieskovsky
Copy link
Author

JurajLieskovsky commented Nov 20, 2021

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
Copy link
Member

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

returncode = subprocess.call([cls.julia_exe(), "--startup-file=no", "--history-file=no", "--project=\"{}\"".format(serverdir), "--eval", "\"import Pkg; Pkg.instantiate()\""])
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.)

@JurajLieskovsky
Copy link
Author

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/....

@JurajLieskovsky
Copy link
Author

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
Copy link
Member

The "ready" file should not have been created if the returncode was 1:

LSP-julia/plugin.py

Lines 157 to 162 in 91fc2f8

if returncode == 0:
# create a dummy file to indicate that the installation was successful
open(os.path.join(serverdir, "ready"), 'a').close()
else:
error_msg = "An error occured while trying to install the Language Server. Check the console for possible error messages or consider to open an issue in the LSP-julia issue tracker on GitHub."
sublime.error_message(error_msg)


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).

@JurajLieskovsky
Copy link
Author

JurajLieskovsky commented Nov 21, 2021

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.

@JurajLieskovsky
Copy link
Author

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
Copy link
Member

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 julia-vscode/LanguageServer.jl#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).

@JurajLieskovsky
Copy link
Author

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
Copy link
Member

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.

@JurajLieskovsky
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants