Language server - "Missing references" in files included in an examples folder

Hi, I am developing a package to which I have added an example folder including some additional dependencies in a separate Project.toml file. The overall structure looks more or less like

├── examples
│   ├── first_example.jl
│   ├── Manifest.toml
│   └── Project.toml
├── Manifest.toml
├── Project.toml
├── README.md
└── src
    └── MyPackage.jl

For editing I use helix with the following language server configuration

[language-server.julia]
command = "julia"
args = [
 "--startup-file=no",
 "--history-file=no",
 "-e",
 """
 using Pkg;
 using LanguageServer;
 runserver()
 """,
 ]

While in MyPackage.jl the LS works as I would expect, in first_example.jl I keep getting Missing reference: ... warnings. If I activate the environment in my examples folder I can run first_example.jl without any issues so there must be something wrong with my LS configuration.

Interestingly enough, the LSP starts correctly in the examples folder and I do get [ Info: Package MyPackage (<UUID>) is cached along with all other dependencies at the start and [ Info: Loaded all packages into cache in 0.84s at the very end, so I have no idea what might be the problem.

This kind of workflow should be supported by LS, so there must indeed be something wrong with the way you set things up.

You didn’t provide much details about the way you created the environment in examples. Did you use something like Pkg.develop(path="..")?

Also, I’m not familiar with helix at all, but do you know in which directory it starts the language server? This is important because the language server current working directory will be used to determine the environment in which the language server operates.

It may not have anything to do with your issue, but seeing how short you LS invocation is, I can’t help wondering how it works. In which environment is LanguageServer installed?

Yes. I created an empty Project.toml file, started julia in the examples folder, activated the environment using ] activate ., added all other dependencies except MyPackage using ] add and then ran ] develop ..

It does seem to start in the current directory as there is a difference in the packages being loaded depending on if I start helix in MyPackage or MyPackage/examples.

LanguageServer should be installed in the main environment of the “user”. It is certainly not installed in MyPackage nor MyPackage/examples and to install it globally I expect sudo privileges would be required.

If there is a different invocation you’d recommend I can try it.

OK, this is what I do too; it should work.

If by “current directory” you mean the directory in which helix is started, this might be (part of) the problem. AFAIK LanguageServer.runserver() will try to determine the current project by

  1. looking in ARGS[1] (but here you don’t provide any command-line argument)
  2. working its way up from pwd() until it finds a Project.toml.

So you’d need to either ensure that LS is started in the directory of the file you’re editing. Or you could perhaps give an additional command-line arg to tell LS where to find the relevant Project.toml.

This might require some support from helix. For example, for emacs in eglot-jl all this logic is done in the emacs side of things: we try to determine which project the file currently being edited belongs to, and provide this to the LanguageServer.

This should be fine. But other ways are possible. For example, again in eglot-jl we have LanguageServer and SymbolServer installed in a small, dedicated environment. This makes it less likely that globally installed packages interfere with LS.