May I ask some follow-on questions? I’m having similar problems moving to VSCode from Juno.
Do you keep your package source code in ~/.julia/dev? (Correct me if I’m wrong, but this seems to be the default location for PkgTemplates, and is required for introspection by the VSCode language server.)
If not, how do you synchronize your package source code with .julia/dev? (I’ve read most of the Pkg documentation, but must have missed this part.)
More generally, would you mind sketching out your package development workflow?
Let me know if I ought to be starting a different topic. Thank you very much.
This also isn’t true. You just need to point VSCode to the correct environment via the env selector in the lower left (modulo some bugs in our env handling that should be fixed in the next minor release).
I’m unable to get autocompletion to work in VSCode for user-defined modules except for those present in .julia/dev as packages. Is this user-error, or one of the bugs to which you alluded?
Well, for me it works if I have one file in which I define a module, lets call it Utils.jl
module Utils
export my_test
function my_test()
println("my_test")
end
end
and a main program that includes this module in the same directory:
include("./Utils.jl")
using .Utils
my_test()
If I now right click on my_test() I can select “Go to Definition” and it works.
The main program and the module(s) that you include do not have to be in the same directory,
but if they are not you have to adapt the relative path in the include statement.
Typing: my<TAB> should result in auto completion to my_test.
Why not? If you’re using LOAD_PATH, it’s because you want to load a package somewhere. Instead just put that relationship into a Manifest and you’re good to go, no?
Could you say more about this workflow or post a link that explains it? I have a Project.toml and Manifest.toml that contain external libraries, which were auto-generated via Pkg.add, how do I add my own files to it?
If you’re using LOAD_PATH , it’s because you want to load a package somewhere.
I was using LOAD_PATH in the past not to load a package, but a module, usually in a file in the same directory.
A local environment does only help if you are a package developer. But many people just write projects, not packages. In that case my work around helps.
I created a package, which I named Experiments and I dump all my scripts in src. I also set up a startup.jl file inside .doc/config/ with something like
cd("path/to/experiments/") # set up path to package
import Pkg
Pkg.activate(".")
This is an all-purpose environment. I don’t have to have a push command or similar. This seems okay for short scripts and quick debugging of loops. Once in a while I delete everything below the # This file is machine-generated - editing it directly is not advised header in the Manifest.toml file and re-install packages as I need them.
Sorry to dig this up again but I cannot get user defined modules to work with code completion. Reading through these post it seems if you have generated a package and added it to dev it should work.
I have custom modules I want to use, so I set julia.environmentPath in vscode, but this flag does not seem to be doing anything at all. I have also tried:
using Pkg and Pkg.activate(/path/to/whatever) in the julia file but this is an aweful solution polluting the julia file. On top of that, it does not seem to be loading modules from the environment of my choosing and seems to load modules from ~/.julia even when environment is selected differently.
using somePackage
pathof(somePackage)
This always returns ~/.julia/path/to/some/package
The only way I have found it working was when I export JULIA_DEPOT_PATH and JULIA_PROJECT and run julia from the terminal.
I can’t seem to set the custom julia environment (without polluting julia sorce file) and get packages from that environment correctly in vscode. I’d appreciate it if anyone could share how to get these two environment variables to work in vscode so that the julia environment is consistent with packages defined in that environment.
I have tried adding these environment variables in launch.json file, but vscode does not seem to care
I am not using the work around I suggested earlier in this thread any longer, because it makes pre-compilation impossible.
It is pretty clear that the current vscode for Julia team will not fix https://github.com/julia-vscode/julia-vscode/issues/307 . So the only way to go forward is to create a fork, implement a good linter and fix this issue. A first step could be to define the requirements and interface of a language server/ linter, that finds modules in the load path.
I have followed Julia community for 2 months. There are so many people smart at compilers, but making unbelievable common sense decisions. I notice you said the code was very hard to read. what would it take to just read JULIA_LOAD_PATH one time on startup?
This solved it for me. Now VScode can Go to Definition of the symbols in my user-defined packages.
For clarity.
I am using DrWatson. I create a new environment by using: DrWatson.initialize_project("Foo")
Once in the new environment (which looks pretty much like a package!) I move in the src folder and create a new package with ]generate myFooPackage.
At this point I activate the environment (with shell in: /projects/Foo/).
]activate .
]dev ./src/myFooPackage
Now to have the symbols in myFooPackage available I have to go to Code options (Maiusc-Command-P) and click on Julia: Change Current Environment. There I select Foo and it works.