Problem with Language Server Protocol in VS Code and Sublime Text

First off: I am impressed with the LSP in VS Code, and I think the maintainers of the Julia integration with LSP are doing a great job. Thank you!

Also, the maintainers of LSP-julia who are integrating Julia with the LSP are hereby heartily thanked.

However, using Julia with the LSP has a serious problem, both in VS Code and Sublime Text. The issue has been described here for VS Code:

It can be summarized in the following way: I want to develop something in the package FinEtools, so I clone it and open it in the editor. Now I want to write tests, so I open for instance the file test_basics.jl (which is included from test/runtests.jl), but the functionality of the FinEtools package is not visible inside test_basics.jl. No hover help, no go-to-definition, …

In order to get this functionality to work I have to do the following. In the entry point of the package, src/FinEtools.jl I have to put this line

# Enable LSP look up in test modules
if false include("../test/runtests.jl") end

Then the lookup enabled by LSP starts working in test_basics.jl.

If this was a problem for the tests only, a solution like this would be just a minor annoyance. However, I also have dozens of example files in my packages. If I start doing this for all the example files, I will get a lot of headaches.

Note that the issue mentioned above, opened two years ago, has still not been addressed. I think what is needed is a clever way of dealing with this problem. Could we put our heads together to come up with a solution?

1 Like

I either am not experiencing or don’t understand the problem. After dev FinEtools in Pkg mode, then opening C:\Users\peter.julia\dev\FinEtools in VSCode, I edit the file test_basics.jl and hover the cursor over startassembly! on line 39 with the following result:


Is this what you get? If so, did you expect something different?

P.S. I searched for and did not find the include statement you said was necessary to activate this functionality.

Try cloning and opening the repo please. I don’t do dev. I would be curious to see what the difference is.

Edit: Interesting. deving does not lead to the same problems. May be all I have to do is to change how I work with repos. But: what I do seems a perfectly natural process…

OK, after cloning the repo and opening its main directory in VSCode, the following dialog pops up:

Screenshot 2024-01-25 095617

If I simply close the dialog without clicking the blue button, everything works correctly, as when I dev’ed the package. However, if I start over, and this time click on the blue “Change Julia environment” button, selecting the same repo directory that I had just opened in VSCode, then intellisense does not work!

If I now click on the “Choose Julia environment” button at the bottom of the VSCode frame, and reset the environment back to “Julia 1.10”, intellisense begins working again. I can turn on and off intellisense functionality at will by selecting “Julia 1.10” or “d:\peter\Documents\julia\examples\FinEtools.jl”, respectively.

Puzzled here: I cannot reproduce this behavior.

However, having just the basic environment
image
and deving FinEtools, and then opening one of the test files, works reliably.

In case it helps here is my version info for VSCode:

Version: 1.85.2 (system setup)
Commit: 8b3775030ed1a69b13e4f4c628c612102e30a681
Date: 2024-01-18T06:40:10.514Z
Electron: 25.9.7
ElectronBuildId: 26354273
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.22621

and my VSCode Julia extension version number is v1.66.2

Happy to share any other info if you think it useful.

Many thanks! I have precisely the same versions.

This thing seems to be extraordinarily fragile. While I could get it to work with FinEtools, it would not work again with a related package, FinEtoolsFlexStructures.
Same procedure: dev FinEtoolsFlexStructures, open its folder, open one of the test files. FinEtools is visible, but FinEtoolsFlexStructures symbols are not visible.

This is a (well known) issue with LanguageServer.jl, see e.g. LanguageServer does not index active project/package · Issue #988 · julia-vscode/LanguageServer.jl · GitHub.

1 Like

I wonder if there are variations to this issue? As described here, both Peter and Petr got FinEtools LSP popups working. For the src files and for the test files too! Which seems to be at difference to the issue described.

@fredrikekre : Would it be easy to summarize where the sources for LSP to consider come from? The trick with the “useless” includes for the tests works fine to enable hover help for test files of the current-environment package.

I think it is just variations of the same issue.

LanguageServer.jl looks only in the active project which is why it works if the package is dev’d in some activated environment as noted above. If you are working in the repo directly, with the packages environment activated, it does work while inside the package module, but not outside (like in test/ or bin/ etc). This is why bringing in the test file into the module itself works around it.

1 Like

For those who are unhappy with the current state of affairs with LSP in VS Code:

I decided that fiddling with the environments was too fragile.

Hence, I will go with the trick of jorge-brito (Jorge Brito) · GitHub : The entry point of a package includes a suitable file. For tests to be visible, do

# Enable LSP look up in test modules
if false include("../test/runtests.jl") end

in the package entry point (src/FinEtools.jl for GitHub - PetrKryslUCSD/FinEtools.jl: Finite Element tools in Julia).

I use a similar mechanism for examples. For instance FinEtoolsFlexStructures has a separate environment for its examples. Then I do a similar “fake” include for one of the example files in FinEtoolsFlexStructures.jl/examples/src/examples.jl at main · PetrKryslUCSD/FinEtoolsFlexStructures.jl · GitHub.

This makes LSP work fine in all my tests and examples.