Skip to content

Commit 2bd7be8

Browse files
Pesc0bgbsww
authored andcommitted
vscode documentation inital draft and Add more basic instructions
1 parent 8db1b02 commit 2bd7be8

File tree

6 files changed

+120
-0
lines changed

6 files changed

+120
-0
lines changed

howtousevscode.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
2+
# Getting started with VSCode
3+
4+
A convenient way of working with the FreeCAD source code is to use an IDE or Integrated Development Environment. The FreeCAD repository contains a VSCode configuration which makes it particularly easy to get started with.
5+
6+
Get VSCode here https://code.visualstudio.com/download and Git here https://git-scm.com/downloads
7+
8+
After that go to github and create your own fork of the FreeCAD repository by clicking the fork button. Once that's done, clone your fork to your local computer that you will be using for development.
9+
10+
```
11+
git clone https://github.com/YourUsername/FreeCAD --recurse-submodules
12+
```
13+
14+
Open VSCode and select `File > Open Folder`, then select the folder where you have cloned your fork of the repo.
15+
16+
Be sure to copy the `.vscode` folder inside `/contrib` to the root directory of the repo (`/.vscode`)
17+
18+
VSCode will probably ask to install the recommended extensions: say `yes`. If it doesn't you'll need to manually install these extensions
19+
```
20+
ms-vscode.cpptools-extension-pack
21+
ms-python.python
22+
```
23+
24+
## Select build configuration
25+
26+
<video autoplay muted playsinline loop src="images/configure.mp4" type="video/mp4"></video>
27+
28+
First on the bottom left corner, in the status bar, select the build type. Options are:
29+
- debug
30+
- release
31+
- conda debug
32+
- conda release
33+
34+
If you are using conda please select one of the respective ones.
35+
36+
Cmake should automatically configure the project with the selected configuration.
37+
38+
## First build
39+
40+
<video autoplay muted playsinline loop src="images/build.mp4" type="video/mp4"></video>
41+
42+
Press `Ctrl + Shift + B`, or click the build button with the cog icon in the status bar, or run the `CMake: build` task.
43+
44+
**NOTE:** The first build takes a while.
45+
46+
**NOTE:** If you change configuration (see step above) you will have to build again.
47+
48+
## Launching the built executable and debugging
49+
50+
<video autoplay muted playsinline loop src="images/debug.mp4" type="video/mp4"></video>
51+
52+
On the left panel go to the debug section and click the little green play button. Alternatively press `F5`. Every time you launch the debugger a build is triggered, to ensure all the latest changes you made to the code are compiled in.
53+
54+
You should see freecad launching and the debugger attaching to the process. If an error pops up the python debugger failed to attach (there's 30 second timeout).
55+
Close FreeCAD and try launching it again. If it still fails try increasing the timeout located in the file `.vscode/scripts/WaitForDebugpy.py`
56+
57+
To debug please refer to the [documentation](https://code.visualstudio.com/docs/editor/debugging#_debug-actions) or search for a tutorial online.
58+
59+
**NOTE:** VSCode has an option called 'run without debugging'. This doesn't work, don't use it. If you just want to run the application launch with `F5` and ignore the debugger.
60+
61+
**NOTE:** There's actually two debuggers: on the top panel you can see a dropdown to select either the c++ debugger or the python one.
62+
63+
**NOTE:** Don't use the restart button. It only restarts the selected debugger, which definitely is not what you want. Instead press the stop button (which stops both debuggers) and launch again.
64+
65+
## Running tests
66+
67+
<video autoplay muted playsinline loop src="images/testing.mp4" type="video/mp4"></video>
68+
69+
The IDE supports running FreeCAD tests as well. On the left panel go to the testing section and click the play button. A build takes place and then all the tests are run and results reported.
70+
71+
**NOTE:** This is much slower than running the `Tests_run` executable directly. The video above is sped up.
72+
73+
**NOTE:** Only c++ tests are currently integrated. Python tests are run from the `Test workbench` or with the command `FreeCAD -t 0`.
74+
75+
Alternatively, there are two vscode tasks that can be used to run the cpp and python tests directly.
76+
77+
**NOTE:** The debug tests button does not currently work. More configuration is needed to get that to work.
78+
79+
## General features of VSCode
80+
81+
On the left panel you can see the following sections:
82+
83+
- File manager: here you can control fils and search them with `Ctrl+F`. Press `F2` to rename the selected file.
84+
- Source control: here you can control git from the graphical user interface.
85+
- Search: powerful tool that can search all files and replace text.
86+
87+
In the status bar on the bottom:
88+
- You can see which branch you are on and change it from there
89+
- Click the error/warning counter to open the `PROBLEMS` panel. Here you will have a convenient collection of all the compiler warnings, cmake warnings, and problems from the workspace.
90+
91+
General editor useful shortcuts:
92+
- Rename all occurrencies of a symbol (e.g. a function name) with `F2`
93+
- Easily navigate code with the tools in the right click menu. For example `Go to definition` and `Find all references`.
94+
- Press `Ctrl+P` and type a file name to jump to that file.
95+
- Press `Ctrl+F` to search the current file.
96+
- Use `Alt+Up/Down` to move rows of text up and down.
97+
- Use `Ctrl+C/X/V` without selecting any text to copy/cut/paste entire rows.
98+
- Use `Ctrl+Shift+Up/Down` to create more cursors and edit many rows at the same time. Press `Esc` to go back to one cursor.
99+
- Hold `Ctrl` while moving left/right to move the cursor entire words at a time.
100+
- Hold `Shift` while moving left/right/up/down to select text with the cursor.
101+
102+
Read the documentation for more:
103+
104+
- [basic editing](https://code.visualstudio.com/docs/editor/codebasics)
105+
- [code navigaton](https://code.visualstudio.com/docs/editor/editingevolved)
106+
- [refactoring](https://code.visualstudio.com/docs/editor/refactoring)
107+
108+
Other useful extensions, recommended but not necessary are
109+
- ```gruntfuggly.todo-tree```: Scans all the files and reports where particular keywords appear. For example `TODO`, `FIXME`, `BUG`...
110+
111+
- ```mhutchie.git-graph```: Helps visualize git commits and branches.
112+
113+
- ```donjayamanne.githistory```: Adds two buttons to the right-click menu: `git: view file history` and `git: view line history`
114+
115+
116+
![](images/extensions.png)
117+
118+
- On the very left you can see the `Todo-Tree` extension reporting `TODO`s and `FIXME`
119+
- On the left half you can see the `git graph` extension showing all the commits on different branches. You can click a commit to see exactly what was modified by it.
120+
- On the right half you can see the `git history` of the DocumentObject.cpp file.

images/build.mp4

2.56 MB
Binary file not shown.

images/configure.mp4

1.54 MB
Binary file not shown.

images/debug.mp4

4.24 MB
Binary file not shown.

images/extensions.png

3.42 MB
Loading

images/testing.mp4

1.06 MB
Binary file not shown.

0 commit comments

Comments
 (0)