Skip to content

Commit a10db86

Browse files
committed
Done the vscode basics?
1 parent b433a01 commit a10db86

File tree

7 files changed

+75
-105
lines changed

7 files changed

+75
-105
lines changed
66.6 KB
Loading
67.8 KB
Loading
15 KB
Loading
190 KB
Loading
58 KB
Loading
15.4 KB
Loading

lectures/software_engineering/tools_editors.md

Lines changed: 75 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,25 @@ While not required for these lectures, consider installing the following extensi
5454
- Install a recent version of miktex or texlive for your platform
5555
- Install [LaTeX Workshop](https://marketplace.visualstudio.com/items?itemName=James-Yu.latex-workshop)
5656
- Optionally install [Code Spell Checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) for spell checking
57-
- See [documentation](https://github.com/James-Yu/LaTeX-Workshop#manual). The easiest use is to put the magic comment `!TEX program = pdflatex` at the top of a `.tex` file.
58-
-
57+
- See [documentation](https://github.com/James-Yu/LaTeX-Workshop#manual). The easiest use is to put the magic comment `!TEX program = pdflatex` at the top of a `.tex` file and then `F5`.
5958

6059

61-
See the [VS Code documentation](https://code.visualstudio.com/docs/getstarted/userinterface) for an introduction.
60+
See the [VS Code documentation](https://code.visualstudio.com/docs/getstarted/userinterface) for an introduction.
61+
62+
### Command Palette
6263

6364
A key feature is the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette), which can be accessed with `<Ctrl+Shift+P>`.
6465

65-
```{figure} [/_static/figures/juno-standard-layout.png](https://code.visualstudio.com/assets/docs/getstarted/userinterface/commands.png)
66+
```{figure} https://code.visualstudio.com/assets/docs/getstarted/userinterface/commands.png
6667
:width: 50%
6768
```
6869

6970
With this, you can type partial strings for different commands and it helps you to find features of vscode and its extensions. This is so common that in these notes we
7071
denote opening the command palette and searching for a command with things like `> Julia: Start REPL` , etc. You will only need to type part of the string, and the command palette remembers
71-
your most commonly used
72-
73-
72+
your most recent and common commands.
7473
### Optional Extensions and Settings
7574

76-
77-
Open the settings, either with `> Preferences: User Settings` (recall this can be found with the palette and `<Ctrl-Shift-P>`) or with the menu.
75+
Open the settings with `> Preferences: User Settings` (see above for opening the command palette with `<Ctrl-Shift-P>`).
7876

7977
As a few optional suggestions for working with the settings,
8078

@@ -83,10 +81,78 @@ As a few optional suggestions for working with the settings,
8381
- Finally, if you are on Windows, search for `eol` and change `Files: Eol` to be `\n`.
8482

8583

84+
(vscode)=
85+
## Using VS Code with Julia
86+
87+
The documentation for the VS Code extension provides many examples:
88+
- [Creating a Hello World](https://www.julia-vscode.org/docs/dev/gettingstarted/#Creating-Your-First-Julia-Hello-World-program-1)
89+
- [Debugging](https://www.julia-vscode.org/docs/dev/userguide/debugging/)
90+
- [Integrated Plots](https://www.julia-vscode.org/docs/dev/userguide/plotgallery/)
91+
- [Code Completion](https://www.julia-vscode.org/docs/dev/userguide/editingcode/)
92+
- [Code Navigation](https://www.julia-vscode.org/docs/dev/userguide/codenavigation/)
93+
94+
In addition, there are excellent youtube videos about provide more background. FOr example, [Package Development in VSCode](https://www.youtube.com/watch?v=F1R3ETaRQXY) shows advanced features.
95+
96+
### Simple Example
97+
To walk through a simple, but complete example.
98+
99+
Create a new directory on your computer, for example `hello_world` and then open VS Code in that folder This can be done several ways,
100+
- Within a terminal on your operating system, navigate that directory and type `code .`
101+
- On Windows, right click on the folder and choose `Open with Code` - trusting the authors as required on opening the folder.
102+
- In the VS Code Menu, choose `File/Open Folder...`
103+
104+
Next, in the left hand panel, under `HELLO_WORLD`, right click and choose `New File` and create as `hello.jl`. The screen should look something like
105+
106+
```{figure} /_static/figures/vscode_file_created.png
107+
:width: 100%
108+
```
109+
110+
Type some code as such `f(x) = x + 1` into the file, into the `.jl` file, save it, and while your mouse curser is on the line of code do `<Shift-Enter>`. If a julia REPL wasn't already started, it will be started and the code will be run within its kernel
111+
112+
```{figure} /_static/figures/vscode_jl_function.png
113+
:width: 100%
114+
```
115+
116+
At this point, the function is available for use within either the code or the REPL. You can get inline results by adding more code to the file and executing each line with `<Shift=Enter>`.
117+
118+
```{figure} /_static/figures/vscode_jl_function_2.png
119+
:width: 100%
120+
```
121+
122+
That code is also accessible within the REPL. Executing the function there,
123+
124+
```{figure} /_static/figures/vscode_repl_1.png
125+
:width: 100%
126+
```
86127

128+
Because the REPL and the files are synchronized, you can modify functions and simple choose `<shift-Enter>` to update their definitions before analyzing the results in the REPL or in the file itself.
129+
130+
131+
### Adding Packages
132+
133+
Next we will go through simple use of the plotting and package management.
134+
135+
To add a package, we can execute a command in the REPL. First, type `]` to enter the package management mode, then `add Plots`. Depending on whether you have done similar operations before, this may download a lot of dependencies. See below for an example
136+
137+
```{figure} /_static/figures/vscode_package_added.png
138+
:width: 100%
139+
```
140+
141+
Crucially, you will notice that two new files are created. `Project.toml` and `Manifest.toml`. These provide a snapshot of all of the packages used in this particular project.
142+
143+
Add code in the `.jl` file for a simple plot, and it will be shown on a separate pane
144+
145+
```{figure} /_static/figures/vscode_plots.png
146+
:width: 100%
147+
```
148+
149+
150+
151+
** Note:** The If you use the Julia REPL within VS Code, then it will automaticallly activate that project file. Otherwise, you will have to start your REPL with the `julia --project` from within that folder, or you will need to manually call `using Pkg; Pkg.activate()` after launching Julia.
87152

88153
(repl_main)=
89154
## The REPL
155+
Note that the REPL could also be started with `> Julia: Start REPL`, which should provide a prompt at the bottom of the window.
90156

91157
Previously, we discussed basic use of the Julia REPL ("Read-Evaluate-Print Loop").
92158

@@ -158,93 +224,6 @@ using Test
158224

159225
will succeed.
160226

161-
## Atom
162-
163-
As discussed {doc}`previously <../getting_started_julia/getting_started>`, eventually you will want to use a fully fledged text editor.
164-
165-
The most feature-rich one for Julia development is [Atom](https://atom.io/), with the [Juno](http://junolab.org/) package.
166-
167-
There are several reasons to use a text editor like Atom, including
168-
169-
(upgrading_julia)=
170-
#### Upgrading Julia
171-
172-
To get a new release working with Jupyter, run (in the new version's REPL)
173-
174-
```{code-block} julia
175-
] add IJulia
176-
] build IJulia
177-
```
178-
179-
This will install (and build) the `IJulia` kernel.
180-
181-
To get it working with Atom, open the command palette and type "Julia Client: Settings."
182-
183-
Then, in the box labelled "Julia Path," enter the path to yor Julia executabe.
184-
185-
You can find the folder by running `Sys.BINDIR` in a new REPL, and then add the `/julia` at the end to give the exact path.
186-
187-
For example:
188-
189-
```{figure} /_static/figures/julia-path.png
190-
:width: 100%
191-
```
192-
193-
### Standard Layout
194-
195-
If you follow the instructions, you should see something like this when you open a new file.
196-
197-
If you don't, simply go to the command palette and type "Julia standard layout"
198-
199-
```{figure} /_static/figures/juno-standard-layout.png
200-
:width: 100%
201-
```
202-
203-
The bottom pane is a standard REPL, which supports the different modes above.
204-
205-
The "workspace" pane is a snapshot of currently-defined objects.
206-
207-
For example, if we define an object in the REPL
208-
209-
```{code-cell} julia
210-
x = 2
211-
```
212-
213-
Our workspace should read
214-
215-
```{figure} /_static/figures/juno-workspace-1.png
216-
:width: 100%
217-
```
218-
219-
The `ans` variable simply captures the result of the last computation.
220-
221-
The `Documentation` pane simply lets us query Julia documentation
222-
223-
```{figure} /_static/figures/juno-docs.png
224-
:width: 100%
225-
```
226-
227-
The `Plots` pane captures Julia plots output (the code is as follows)
228-
229-
```{code-block} julia
230-
using Plots
231-
gr(fmt = :png);
232-
data = rand(10, 10)
233-
h = heatmap(data)
234-
```
235-
236-
```{figure} /_static/figures/juno-plots.png
237-
:width: 100%
238-
```
239-
240-
**Note:** The plots feature is not perfectly reliable across all plotting backends, see [the Basic Usage](http://docs.junolab.org/latest/man/basic_usage.html) page.
241-
242-
### Other Features
243-
244-
* `` Shift + Enter `` will evaluate a highlighted selection or line (as above).
245-
* The run symbol in the left sidebar (or `Ctrl+Shift+Enter`) will run the whole file.
246-
247-
See [basic usage](http://docs.junolab.org/latest/man/basic_usage.html) for an exploration of features, and the [FAQ](http://docs.junolab.org/latest/man/faq.html) for more advanced steps.
248227

249228
(jl_packages)=
250229
## Package Environments
@@ -335,12 +314,3 @@ without any arguments.
335314
```{code-cell} julia
336315
; rm -rf ExampleEnvironment
337316
```
338-
339-
### InstantiateFromURL
340-
341-
With this knowledge, we can explain the operation of the setup block
342-
343-
344-
What this `github_project` function does is activate (and if necessary, download, instantiate and precompile) a particular Julia environment.
345-
346-
(docker_main)=

0 commit comments

Comments
 (0)