myTarget.jl should be in a properly constructed project (âworkspaceâ in VSC terminology IIRC) with PackageA and PackageB listed in its Project.toml and manifest. (Maybe you know this, but you didnât list TOML files above.) Are references not reliably resolved for you in this situation?
I think you have to restart the language server if you add new objects to PackageA or B (or to files includeâd by myTarget.jl) during a session.
Iâm probably not doing most of these things correctly. Some specific questions:
What defines a workspace in this context and how/where should I put myTarget.jl?
PackageA and PackageB are not in Project.toml.
In addition to this I suspect that I have not created Project.toml correctly. What should I do to create it? (Assume I either start again or delete it.)
I tried to find information about these things before creating this test project, but I was trying to piece together bits of information I found in different places.
Itâs probably safer just to assume I have no idea what I am doing in this particular case.
First make sure your library packages have their own Project.toml files. These normally come from using the generate package REPL command or by using PkgTemplates.jl for bigger efforts.
Now if you put your script in a directory, say example-project, parallel to your example-repo above, then from a Julia REPL running in that directory, enter the Package mode with â]â and run the commands
Well, usually you should keep each package in separate repository, create new julia environment for the target project, and add those packages to the environment via add or develop command in pkg mode, but itâs not what you doing as far as I understand. In you case, you probably should do something like this:
include("PackageA/src/PackageA.jl")
include("PackageB/src/PackageB.jl")
using .PackageA
using .PackageB
The develop and add commands get the references into the manifest, which is how the language server resolves namespaces. As detailed in the other thread, automatic lookup in subdirectories is not currently available.
Pedroâs approach will also work, but those are really just submodules and it seems confusing to lay them out as if they were packages.
One thing which I have tried doing, which does not appear to work, has been to add a path to JULIA_LOAD_PATH. That path being the root of this repository.
That works when Julia runs, one can do
using PackageA
using PackageB
and Julia will be able to find those packages because of the additional path in JULIA_LOAD_PATH.
However, VS Code (Julia Extension) does not appear to understand this. Maybe it doesnât read the LOAD_PATH?
The key to making LSP work is to point its âproject directoryâ to a folder containing a fully instantiated (!) environment with your package and any other package that the LSP should know about, e.g., test dependencies. Personally, I use a test/Project.toml file for test/docs dependencies (instead of the older [extras] in the main Project.toml file, make sure thatâs always instantiated (via a Makefile), and point LSP to that.
To be fair, I always found the LSP to be tricky in VS Code. It only really started to work reliably once I set it up in Neovim. But that may also be because I havenât invested that much time into VS Code and never figured out the way to penetrate that âblack boxâ.
add a path to JULIA_LOAD_PATH
Probably, VS Code controls the environment for the julia subprocess. Depending on where you set that environment variable, it was probably not forwarded.
But based on this and a number of your other recent posts: you seem to be a bit enamored with JULIA_LOAD_PATH. Modifying JULIA_LOAD_PATH is basically never the right answer. To first order, you should forget that it exists.