Navigation between tests & src/

This is a pretty minor thing, but I figured I’d ask about it anyway.

In VS Code, when working on code in a package, I can command-click on a function call and be taken to its definition (although if there are multiple methods with the same name, it can’t figure out which one is being called, but in practice it works decently well).

However, if I’m working on that package’s unit tests, navigation to a package function is unavailable, so I generally need to go use the text search to locate methods. Is there some way to get this navigation working in this common use case?

1 Like

Yes, there are two options:

  1. you have a Project.toml in the tests folder. Then you can navigate there, activate it and apply the develop command to your main package
  2. you add one or more lines like this to runtests.jl or to the sub-test script included by runtests.jl:
if false include("../src/<YourPackage>.jl") end
1 Like

Interesting! I do already have a Project.toml in my tests folder, but I think I’ll use option 2, because that seems like it will “just work” for new developers, but option 1 would need them all to dev the project individually (unless I check in the Manifest.toml, which I think I don’t want to do), right?

A better option is probably to put

[sources]
PackageName = {path = ".."}

in test/Project.toml, where PackageName is the name of your package. This works in Julia >= 1.11, which is probably what new developers would be using.

5 Likes

Ah! That would indeed be better, and a good reason to bump us up to 1.11. I’ve been sitting on 1.10 for a while by pure inertia.

Unfortunately, none of the solutions that involve putting the package in test/Project.toml seem to work for me, I’m getting variations on the can not merge projects error (see "cannot merge projects" error · Issue #1585 · JuliaLang/Pkg.jl · GitHub) when I try.

Even if you delete the Manifest?

Oh indeed, that seems to be working - “delete the Manifest.toml” isn’t normally in my repertoire, I think I was trying to use resolve and/or instantiate within the REPL, I don’t remember exactly how, but clearly it wasn’t working.

1 Like

Yes, it is somewhat annoying that sometimes you have to delete the manifest file manually, and that Julia (or Pkg?) cannot figure out that this might be needed itself. At least Julia or Pkg should give a hint in such a situation that this might be needed.

1 Like