Hello!
I’m trying to use the Helix editor with the Julia LanguageServer. The call to the language server looks like:
julia --startup-file=yes --history-file=no --quiet -e using LanguageServer; runserver()
Now, the language server seems to work fine for definitions within the file I’m working on, but how do I get it to include all definitions in the current project, ie also from other .jl files? The project is in Julia standard format with its own environment.
Do you have roots = ["Project.toml", "Manifest.toml"] set in your ~/.config/helix/languages.toml? The default config doesn’t have that set. If you set that, the LS should be able to find everything, as that is used to detect a workspace (and set it from helix’ side during initialization).
Thank you for taking the time to point clearly to the solution for Neovim. I have tried similar things but not this exact one. I might try to steal parts of it even though I’m not sure if it should be needed for Helix.
You’re right, i forgot about roots. Without roots it should work if you open helix at the root of your project, but i guess with roots defined you can open at any directory.
I think the only problem for you is that you need to pass the --project argument when running the language server.
I also won’t recommend using --startup-file=yes, because loading the startup.jl file may increase the time for the language server to start.
That’s weird. Maybe looking at the helix.log file may tell us what’s wrong.
Remove the ~/.cache/helix/helix.log file, then open helix within your Julia project, wait for the language server to start and then run the command :log-open. With the log file open, see if the language server is actually loading the dependencies of your project or if any errors occurred.
That’s because stdout is used to exchange the JSON data between the editor and the language server, so all logging is done to stderr.
So, if the server loads your project dependencies correctly, then you should get intellisense and autocompletion working for symbols defined in those packages. Do you get missing references when trying to use functions defined in other packages (that are installed in your environment)? Or do you only get missing references when trying to use a function that you defined in another file?
If I have explicitly imported the module in the file it is used in with using module_x, then it works! So the only problem seems to be if the using is in another file or if the definition itself is in another file in the project.
The language server analyzes the using/import statements to load the symbols for packages that you use, and include to load symbols defined in other files.
You shouldn’t use expressions inside include, because the language server can’t execute the code inside include to figure out what file to load. You don’t actually need to use projectdir here either, just using include("src/path/to/file.jl") should work.
There we have the solution, probably! Of course I added that stuff not for fun but because it helped in some situations regarding how I use the code. But I might have to consider changing that then!
Thank you so much! I’m very impressed with the level of help I received!
I would recomend installing LanguageServer.jl to it’s own project (e.g. ~/.julia/environments/nvim-lspconfig/ in my case). Then you can also use this Makefile to build a custom sysimage for the server to give instant startup. This might require passing the project environment explicitly though, since your server runs in another one.