VSCode and LangServer don't recognize local package

I am working on a package locally and it seems like VSCode + LangServer don’t recognize the references to the package and it’s exported methods.

For example:

using TestPackage
using CSV
using DataFrames
using BenchmarkTools
using TestPackage.SomeModule: update!

Here TestPackage and all the references would get a not defined error with yellow underscores, in the imports as well as all references in the file. However when executed with the repl within VSCode everything works fine.

I already tried restarting, clearning the cache, dev . and activate .

What is the recommended approach to locally develop a package and make the tools aware of it when within that repo.

I also tried to exclude the package name and do a relative import like so but then not only the language server errors out, so does the repl, with not found:

using ..SomeModule: update!

Sometimes adding a line like:

if false; include("../src/flightpathcontroller.jl"); end

helps…

1 Like

Try this GitHub - PetrKryslUCSD/VSCode_Julia_portable: Portable Julia running in VSCode, perhaps?

1 Like

Another option, let’s say your project structure is something like:

TestPackage/
   src/
      TestPackage.jl
      foobar.jl
   examples/
      basic_example.jl
      another_example.jl

If you want intellisense to work insde examples/ you can create another environment inside that folder and dev’ your package into it.

$ cd TestPackage/examples
$ julia
julia> ]
(@v1.10) pkg> activate .
(examples) pkg> dev ..

After that you should probably add other packages you’re gonna be using:

(examples) pkg> add CSV DataFrames BenchmarkTools

Then, you can change the vscode julia environment to that folder:

Press CTRL + SHIFT + P and search for this command: Julia> Change Current Environment

image

Select (pick a folder).

image

Then pick the folder that you want.

Then, wait for vscode to reindex the packages and now you should have intellisense working for your package.

If intellisense still doesn’t work, restart vscode and make sure you’re in the correct environment.

Of course, the downside of this approach is to have to keep changing/creating environments just to get intellisense to work.

Related topic:

Seems like most solutions revolve around this. I tried that and it doesn’t work for me using TestItemRunner.jl not native tests, which is the required package to run tests in VSCode (althought its broken on its own).

The solution with multiple packages within the package works, but its very very cumbersome to be practical and keep all deps in sync.

I’m quite surprised using the default tools i can’t get the tests to recognize the package they are testing, this has to be a bug ?

There are 51 open bugs on this topic: Issues · julia-vscode/julia-vscode · GitHub

Just run your tests from the package manager using the test command… Don’t rely too much on VSCode…