Getting Started with Julia in VS Code
This project was just first attempt creating a Julia Project using VS Code. Workflow is super important to me so I generally try to understand that first when learning a new language. I found the video by David Anthoff and decided to follow along and take notes along the way. This repository is the result. If you watch the video, he assumes you already have some familiarity with VS Code and glosses over certain keyboard shortcuts. I try my best to explicitly explain the steps below.
That being said, I assume you have already installed julia and the VS Code julia language extension. I also noticed that not all of the features worked for me as I followed along. I can only assume that there were some breaking changes in either the language, extension, or VS Code.
Creating an New Project
- Within VS Code, pressing
shift+cmd+p
(control+shift+p
on Windows) will open the command palette; after which typeJulia: Start REPL
to start a julia terminal - Within the REPL type
]
to enter package mode, andactivate .
to activate a new environment - Type
add DataFrames Query VegaLite VegaDatasets
to add the desired project libraries- Notice there are now a Project.toml and Manifest.toml files in your directory which describe your requirements and dependencies respectively for this project
- If you are working in a previously created project, you can call
instantiate
(which will use the existing Project.toml and Manifest.toml files) instead ofadd DataFrames ...
.
- Now click on the
Julia env: v1.x
button in the status bar and select this directory as the environment. Your environment should update your directory’s name:Julia env: <your_dir_name>
. - To get back to the Julia REPL, press
backspace
or^C
Things to Know
- To executed code interactively from the file into the terminal, use
control+enter
. This is different than in Python where users pressshift+enter
. - To restart the terminal, you can close the existing terminal by selecting the trash can or by
shift+cmd+p
and typingJulia: Stop REPL
before creating a new one byshift+cmd+p
and typingJulia: Start REPL
. I did not find an easy way to restart the session. - Devcontainers are a great way to create an isolated environment. All you need is a
.devcontainer
folder with adevcontainer.json
file. In this case we had the following simple code to direct the creation of a dev docker container:
{
"image": "julia",
"extensions": ["julialang.language-julia"]
}
This tells VS Code to build a container and install using the julia image with the julialang VS Code extension. After the docker container is built, a user can activate .
and instatiate
to start working in the clean environment.