# LSP "Missing reference" woes

**URL:** <https://discourse.julialang.org/t/lsp-missing-reference-woes/98231>\
**Category:** General Usage\
**Created:** [May 3, 2023, 4:03am UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231 "2023-05-03T04:03:40Z")\
**Posts on this page:** 20\
**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:** [May 3, 2023, 4:03am UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/1 "2023-05-03T04:03:40Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/5/b/5bf3d13f2f326cbf530abd42112e51920e8290c8.png)

Notice `two2 = too` (which is not defined).  
I do have the “missing references” enabled:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/c/4c9f9f128d0df1e4de9e71d0e96e6914bd22e321.png)

Any idea what is wrong? Sublime Text (4). On windows.

---

<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:** [May 3, 2023, 4:19am UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/2 "2023-05-03T04:19:33Z")

</div>

It shows up in vsc:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/e/3e1e22134dc9dc75ea2f8adf0dcaa22ca60b0869.png)

But so does a gazillion bogus missing refs. Obviously, if I have `using PGFPlotsX` at the top,  
`@pgf` should not be a missing ref.

---

<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:** [May 3, 2023, 6:02am UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/3 "2023-05-03T06:02:30Z")

</div>

I can’t replicate the missing refs issue in Vim (or VSCode), so probably a configuration issue where the server doesn’t pick up your settings, ignores them, or sets its own defaults.

Regarding the bogus missing refs, I can’t replicate that either. Are you sure you have PGFPlotsX in the active project? (Having it in the default environment is not enough.)

---

<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:** [May 3, 2023, 1:50pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/4 "2023-05-03T13:50:55Z")

</div>

You are right, PGFPlotsX was not a good example. But even after I make sure to initialize the project, I get incorrect missing refs:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/d/bd362e5457b1107562aeef09e25a5dd3b610dabb.png)  
And lots of such are reported (922).

---

<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:** [May 3, 2023, 2:08pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/5 "2023-05-03T14:08:08Z")

</div>

BTW: 553 of those missing refs are from Manifest.toml. Is that normal?  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/7/47585f7a1856866d01953ae4cc6a54ac17208fae.png)

---

<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:** [May 3, 2023, 9:09pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/6 "2023-05-03T21:09:56Z")

</div>

Julia LSP should only be fed Julia files, so that seems oike another configuration issue in the Sublime LSP integration perhaps.

---

<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:** [May 3, 2023, 9:56pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/7 "2023-05-03T21:56:43Z")

</div>

No, sorry, this is VS Code. And I don’t see any option for selecting which files should be seen by LSP.  
All of today’s examples are from VS Code.

---

<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:** [May 4, 2023, 1:07am UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/8 "2023-05-04T01:07:20Z")

</div>

I think I solved the puzzle why things in Manifest.toml were being reported as “Missing References” in VS Code: There are two values that turn that reporting on, `all` and `symbols`.

![image](https://global.discourse-cdn.com/julialang/original/3X/d/5/d5c62554ff88b1d8c09e980fc13ba0797d7c08e3.png)

It needs to be set to `symbols` so that only Julia file are taken into consideration.

That leaves the question why so many objects are being reported as “Missing References”  
when clearly they should be known. Example:

![image](https://global.discourse-cdn.com/julialang/original/3X/e/0/e0719a87090b19dd030eda11236d5a4de8c726bc.png)

ACol is the current environment, so why the missing references on line 4?  
I wonder if it has anything in common with the apparent problem VS Code has with  
suggesting completions from the current package?

---

<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:** [May 4, 2023, 1:15pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/9 "2023-05-04T13:15:37Z")

</div>

Known issue: [LanguageServer does not index active project/package · Issue #988 · julia-vscode/LanguageServer.jl · GitHub](https://github.com/julia-vscode/LanguageServer.jl/issues/988)  
Filed it myself ☹  
Note to self: eat more wallnuts (for better memory…).

---

<div class="post-metadata">

**Author:** ![jwortmann](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@jwortmann](https://discourse.julialang.org/u/jwortmann)\
**Post date:** [May 4, 2023, 2:19pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/10 "2023-05-04T14:19:45Z")

</div>

For Sublime LSP, you need to put your server configuration options into a `"settings"` object, like this:

```plaintext
{
    "settings": {
        "julia.lint.missingrefs": "all",
    },
}

```

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [May 4, 2023, 2:37pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/11 "2023-05-04T14:37:31Z")

</div>

> [@PetrKryslUCSD](#):
>
> apparent problem VS Code has with  
> suggesting completions from the current package?

AFAICT, VS Code (or the Language Server, more precisely) has trouble with source code that _uses_ the current package but is not part of it. Such as scripts, that are typically placed outside the `src` subdir (which seems to be the case of your `acousticcolorplot.jl` file above).

I know of 2 (rather hacky) ways to work around this problem:

1. put the bulk of the script code in a function inside the sources of the package (`ACol` in your case). Then your script becomes mostly empty: it reduces to something like

2. trick the Language Server into thinking that your script is actually part of the package sources (but in a separate Module so that it sees the same exported names as an independent piece of code). It seems that this can be achieved by putting something like this in `ACol.jl`:

---

<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:** [May 4, 2023, 3:01pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/13 "2023-05-04T15:01:15Z")

</div>

Oh, I see! Sorry, I missed this point. Many thanks, missing references are shown in the diagnostics panel.

But, now there are too many. Example:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/0/7092c9cb0c9ab9c044a09e711a6299d68615d801.png)

Obviously, I do have those packages in the environment!

---

<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:** [May 4, 2023, 3:05pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/14 "2023-05-04T15:05:37Z")

</div>

> [@ffevotte](#):
>
> AFAICT, VS Code (or the Language Server, more precisely) has trouble with source code that _uses_ the current package but is not part of it.

This is the best explanation of the problem I have heard so far.

---

<div class="post-metadata">

**Author:** ![dmolina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmolina/32/5246_2.png) [@dmolina](https://discourse.julialang.org/u/dmolina)\
**Post date:** [May 11, 2023, 3:32pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/15 "2023-05-11T15:32:34Z")

</div>

Thank you a lot, @ffevotte. Yes, I have passed a lot of time this morning asking me why when I work in the package everything is working nicely, but when I use the main program that use my package, it did not find it, even when in the directory of the script there is the same Project.toml.

I have the following schema:

pract.jl: script to use the package to solve the problem.  
Project.toml: dependencies.  
src/… implementation of the package.  
test/… tests.

When I work in src/ it is working nicely, but when I use pract.jl is not working at all.

I tried the first option, and it is working. However, I am not sure about the second one, because it is not working in my case, could you give a better idea?  
However, thanks a lot.

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [May 11, 2023, 5:00pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/16 "2023-05-11T17:00:44Z")

</div>

First, be aware it’s very hacky and messes up a bit with inline evaluation (which I don’t use much because I actually use Emacs for my day-to-day work). But let me try and give a step-by-step procedure that demonstrates this trick on a simple package like `Example.jl`. You should be able to reproduce this on your system.

First, `git clone https://github.com/JuliaLang/Example.jl`, open the project in VSCode and add a `script.jl` file at its root. It should look like this:

```plaintext
Example.jl
├── Project.toml
├── script.jl # <-- newly added file
└── src
    └── Example.jl

```

```julia
# script.jl
using Example

println(hello("World"))

```

At first, LanguageServer is not happy with the reference to `Example.hello`: for example, neither the inline doc nor the “Go to definition” command work.

Now, if you edit `src/Example.jl` to read:

```julia
module Example
export hello, domath

# [...]
# I'm skipping the definitions of `hello` and `domath`

# Add this part to "trick" LSP into thinking that `../script.jl`
# is actually part of the sources
@static if false
    include("../script.jl")
end

end

```

Now VSCode / LSP should be more happy and find what `hello` refers to in `script.jl`. Does that work for you?

---

<div class="post-metadata">

**Author:** ![g-gundam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/g-gundam/32/47593_2.png) [@g-gundam](https://discourse.julialang.org/u/g-gundam)\
**Post date:** [September 24, 2023, 8:03pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/17 "2023-09-24T20:03:27Z")

</div>

@ffevotte - That `@static if false` trick worked for me in Emacs, and I wanted to thank you for sharing that. However, I wish there were a better way that didn’t involve tricking the LSP server. For example, I wish I could tell the LSP server that all Julia files in the `bin/` directory are part of the project and should be able to see the current package.

---

<div class="post-metadata">

**Author:** ![dylanxyz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanxyz/32/36646_2.png) [@dylanxyz](https://discourse.julialang.org/u/dylanxyz)\
**Post date:** [September 24, 2023, 11:59pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/18 "2023-09-24T23:59:03Z")

</div>

Another way of tricking vs-code to get intellisense: define a macro like this:

```julia
# inside your package entry point
macro ignore(args...) end

# then, "include" the julia files you want intellisense to work
@ignore include("../examples/example.jl")
@ignore include("../examples/script.jl")

```

---

<div class="post-metadata">

**Author:** ![harijaya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/harijaya/32/209615_2.png) [@harijaya](https://discourse.julialang.org/u/harijaya)\
**Post date:** [May 30, 2024, 8:03pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/19 "2024-05-30T20:03:56Z")

</div>

This worked for me on (neo)vim! This has been driving me crazy for weeks. Thank you.

But why does this work exactly?

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [May 30, 2024, 9:02pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/20 "2024-05-30T21:02:06Z")

</div>

As far as I understand, LSP only has limited knowledge about the semantics of Julia. It understands the meaning of `include` but not `@static if false`. So after analyzing these lines, LSP believes `script.jl` to be part of the project sources. And code references always work more reliably when editing source code that is “inside” the project.

---

<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:** [May 30, 2024, 11:26pm UTC](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/21 "2024-05-30T23:26:06Z")

</div>

But beware: [Switching to an environment works differently in different situations · Issue #3591 · julia-vscode/julia-vscode · GitHub](https://github.com/julia-vscode/julia-vscode/issues/3591#issuecomment-2118861669)

[Next page](https://discourse.julialang.org/t/lsp-missing-reference-woes/98231.md?page=2)
