# LanguageServer.jl does not find my own modules

**URL:** https://discourse.julialang.org/t/languageserver-jl-does-not-find-my-own-modules/73683
**Category:** General Usage
**Created:** [December 27, 2021, 4:40pm UTC](https://discourse.julialang.org/t/languageserver-jl-does-not-find-my-own-modules/73683 "2021-12-27T16:40:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jlbosse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlbosse/32/11274_2.png) [@jlbosse](https://discourse.julialang.org/u/jlbosse)
#### Post date: [December 27, 2021, 4:40pm UTC](https://discourse.julialang.org/t/languageserver-jl-does-not-find-my-own-modules/73683/1 "2021-12-27T16:40:52Z")

</div>

I got the `LanguageServer.jl` mostly working in neovim with `neovim/nvim-lspconfig`. The only thing that is not working, is that I get a “Missing reference” for all my own modules (i.e. those not in packages installed via Pkg).

My exact setup is as follows:

```julia
# MyModule.jl
module MyModule
export foo
foo() = println("bar")
end # module

# MyScript.jl
push!(LOAD_PATH, pwd())
using LinearAlgebra # this works fine and I get autocompletions / docstrings for it
using MyModule # this gets marked with a "missing reference"

foo() # this also gets a "missing reference"
...

```

I assume this is, because the LanguageServer does not know about the `MyModule.jl` file and it all seems related to the following issue [https://github.com/julia-vscode/julia-vscode/issues/307](https://github.com/julia-vscode/julia-vscode/issues/307).

What is the recommended / simplest way to get the LanguageServer to pick up on my own modules. Ideally, I would also like to avoid creating a package for MyModule, because I have quite a few such modules that are all sufficiently small (just one file) that they don’t deserve to be a package.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [December 27, 2021, 11:54pm UTC](https://discourse.julialang.org/t/languageserver-jl-does-not-find-my-own-modules/73683/2 "2021-12-27T23:54:41Z")

</div>

Help to fork the Julia plugin for vscode and help to implement this feature. Its open source! 😃

---

<div class="post-metadata">

### Author: ![jlbosse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlbosse/32/11274_2.png) [@jlbosse](https://discourse.julialang.org/u/jlbosse)
#### Post date: [July 4, 2022, 9:06pm UTC](https://discourse.julialang.org/t/languageserver-jl-does-not-find-my-own-modules/73683/3 "2022-07-04T21:06:28Z")

</div>

I finally found a solution that works good enough for me. I still had to create a separate package for each module, but could at least have them all in the same git repo. Here is how I did it:

Create an empty git repo inside a new folder (this is assuming your `MyPackages` folder isn’t already a git repo):

```bash
mkdir MyPackages
cd MyPackages
git init

```

and then inside this folder create your packages:

```julia
julia> using PkgTemplates
julia> Template(interactive=true)("PackageA.jl")
# now customise the `dir` to "." to create the repo inside "MyPackages"
julia> exit()

```

now you can delete the git repo that `PkgTemplates` created for you and only  
keep the rest of the stuff:

```bash
rm -rf PackageA/.git
rm -rf PackageA/.github

```

and lets also edit the contents of `PackageA/src/PackageA.jl` to contain something, i.e.

```julia
module TestA

export testa

testa() = println("Hello to Package A")

end # module

```

Now we can tell julia about the existence of your great new `PackageA` by doing  
the following:

```julia
pkg> dev ~/MyPackages/PackageA
julia> using PackageA
julia> testa()
# should output "Hello to Package A"

```

To add more packages to `MyPackages` just repeat everything after the second  
step with the new package names.

And finally, make sure that the neovim LSP uses the global project instead  
of any silly local stuff. For this, edit the file  
`~/.config/nvim/plugged/nvim-lspconfig/lua/lspconfig/server_configurations/julials.lua`  
(or wherever else neovims language server config for julia is stored)  
to define the project path as follows (with the 2nd option importantly commented out!)

```julia
    project_path = let
        dirname(something(
            ## 1. Finds an explicitly set project (JULIA_PROJECT)
            Base.load_path_expand((
                p = get(ENV, "JULIA_PROJECT", nothing);
                p === nothing ? nothing : isempty(p) ? nothing : p
            )),
            ## 2. Look for a Project.toml file in the current working directory,
            ## or parent directories, with $HOME as an upper boundary
            # Base.current_project(), # deleted this myself. Might be the thing!
            ## 3. First entry in the load path
            get(Base.load_path(), 1, nothing),
            ## 4. Fallback to default global environment,
            ## this is more or less unreachable
            Base.load_path_expand("@v#.#"),
        ))
    end

```

I am sure for the last part one could also edit ones `.vimrc` instead of `julials.lua`, but that is beyond my (neo)vim expertise.
