LanguageServer.jl does not find my own modules

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:

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

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.

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

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):

mkdir MyPackages
cd MyPackages
git init

and then inside this folder create your packages:

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:

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

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

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:

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!)

    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.