# Problem with Language Server Protocol in VS Code and Sublime Text

**URL:** https://discourse.julialang.org/t/problem-with-language-server-protocol-in-vs-code-and-sublime-text/109264
**Category:** Tooling
**Created:** [January 25, 2024, 4:32pm UTC](https://discourse.julialang.org/t/problem-with-language-server-protocol-in-vs-code-and-sublime-text/109264 "2024-01-25T16:32:11Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [January 25, 2024, 4:32pm UTC](https://discourse.julialang.org/t/problem-with-language-server-protocol-in-vs-code-and-sublime-text/109264/1 "2024-01-25T16:32:11Z")

</div>

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](https://github.com/sublimelsp/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:

> <https://github.com/julia-vscode/julia-vscode/issues/2719>
>
> Issue is as stated above. When hovering over my functions which are imported thr…ough my module the hover help doesn't show and I can't fast click towards the function itself in my module file. But when I do the same in the module file it works fine. 
> 
> So for example:
> 
> 
> \_using TestModule\_
> 
> \_a = TestFunction(3) # Hovering over TestFunction doesn't do anything and I can't fastclick\_
> 
> 
> \*\*but\*\*
> 
> 
> \_module TestModule\_
> 
> \_export TestFunction # Hovering over TestFunction shows function details and I can fastclick\_
> 
> 
> 
> \_function TestFunction(var)\_
> \_return var\_
> \_end\_
> 
> 
> 
> end
> 
> 
> 
> How could this be resolved? 
> 
> I am using v1.5.10 of Julia for vscode
> v1.6.5 of the Julia programming language

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

```julia
# 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?

---

<div class="post-metadata">

### Author: ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)
#### Post date: [January 25, 2024, 5:48pm UTC](https://discourse.julialang.org/t/problem-with-language-server-protocol-in-vs-code-and-sublime-text/109264/2 "2024-01-25T17:48:22Z")

</div>

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:

 ![Screenshot 2024-01-25 094110](https://global.discourse-cdn.com/julialang/original/3X/9/9/99726eb61febdae5487c0d8403c692281d24a35e.png)  
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.

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [January 25, 2024, 5:49pm UTC](https://discourse.julialang.org/t/problem-with-language-server-protocol-in-vs-code-and-sublime-text/109264/3 "2024-01-25T17:49:26Z")

</div>

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

Edit: Interesting. `dev`ing 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…

---

<div class="post-metadata">

### Author: ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)
#### Post date: [January 25, 2024, 6:06pm UTC](https://discourse.julialang.org/t/problem-with-language-server-protocol-in-vs-code-and-sublime-text/109264/4 "2024-01-25T18:06:29Z")

</div>

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

![Screenshot 2024-01-25 095617](https://global.discourse-cdn.com/julialang/original/3X/b/7/b7327e86589aa1c0b89dacb5fd585acb9ed1c99a.png)

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.

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [January 25, 2024, 6:29pm UTC](https://discourse.julialang.org/t/problem-with-language-server-protocol-in-vs-code-and-sublime-text/109264/5 "2024-01-25T18:29:38Z")

</div>

Puzzled here: I cannot reproduce this behavior.

However, having just the basic environment  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/7/971d7e1320f1ffeac5e344f2a2d36c98e9fc6f6d.png)  
and `dev`ing FinEtools, and then opening one of the test files, works reliably.

---

<div class="post-metadata">

### Author: ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)
#### Post date: [January 25, 2024, 6:38pm UTC](https://discourse.julialang.org/t/problem-with-language-server-protocol-in-vs-code-and-sublime-text/109264/6 "2024-01-25T18:38:11Z")

</div>

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

```julia
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.

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [January 25, 2024, 6:43pm UTC](https://discourse.julialang.org/t/problem-with-language-server-protocol-in-vs-code-and-sublime-text/109264/7 "2024-01-25T18:43:47Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [January 25, 2024, 7:04pm UTC](https://discourse.julialang.org/t/problem-with-language-server-protocol-in-vs-code-and-sublime-text/109264/8 "2024-01-25T19:04:28Z")

</div>

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](https://github.com/julia-vscode/LanguageServer.jl/issues/988).

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [January 25, 2024, 8:27pm UTC](https://discourse.julialang.org/t/problem-with-language-server-protocol-in-vs-code-and-sublime-text/109264/9 "2024-01-25T20:27:58Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [January 25, 2024, 8:43pm UTC](https://discourse.julialang.org/t/problem-with-language-server-protocol-in-vs-code-and-sublime-text/109264/10 "2024-01-25T20:43:12Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [January 25, 2024, 9:07pm UTC](https://discourse.julialang.org/t/problem-with-language-server-protocol-in-vs-code-and-sublime-text/109264/11 "2024-01-25T21:07:36Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [January 26, 2024, 12:11am UTC](https://discourse.julialang.org/t/problem-with-language-server-protocol-in-vs-code-and-sublime-text/109264/12 "2024-01-26T00:11:08Z")

</div>

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](https://github.com/jorge-brito) : The entry point of a package includes a suitable file. For tests to be visible, do

```julia
# 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](https://github.com/PetrKryslUCSD/FinEtools.jl.git)).

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](https://github.com/PetrKryslUCSD/FinEtoolsFlexStructures.jl/blob/main/examples/src/examples.jl).

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