IDE
IDE stands for Integrated Development Environment. It is a tool that combines everything needed for development into a single software. You have already used other IDEs in previous courses, such as Code::Blocks, Eclipse, or Visual Studio.
VSCodium¶
Why VSCodium?
In this course, we will use VSCodium because it provides a lightweight and customizable development environment. Unlike IDEs dedicated to specific languages or tools, VSCodium is free, open source, and allows you to add only the features you need through extensions.
Open VSCodium.
In the following sections, we will explore some useful features of VSCodium and its extensions.
Opening a project¶
Click File > Open Folder and open your Git repository. You can trust the authors of this repository.
You should see your repository with the different labs displayed in the Explorer tab at the top of the left sidebar.
If VSCodium asks whether you want to regularly perform a
git fetch, you can answer yes. If you answered no, that’s fine, you will just need to remember to do it manually from time to time.
Colors¶
You can choose the color theme that suits you for the editor and your code by going to File > Preferences > Themes > Color Theme.
Explorer && Editor¶
You can create files and directories using the icons that appear when you hover over the project name at the top of the Explorer tab.
Create a
Lab10/directory in your project.Create a file in this new directory with any content you like.
Notice the minimap on the right side of your screen, which allows quick navigation through your code. It also displays errors and recent changes. If you don’t see it, enable it via View > Appearance > Minimap.
You can also split your screen to view multiple files at once using the Split Editor Right button (a square divided into two rectangles at the top of the minimap).
Splitting the screen on Linux
A simple way to split the screen on Linux (outside of VSCodium) is to use the keyboard shortcut Win + an arrow key.
If you have multiple screens, you can quickly organize them using Win + Shift + an arrow key.
If you have long lines of code that do not fit on a single line, you can enable View > Word Wrap (or Alt + Z).
LSP¶
Language Server Protocol
An LSP (Language Server Protocol) allows a code editor (such as VSCodium) to send requests (auto-completion, errors, etc.) to a local language server that analyzes the code and returns responses.
At the bottom of the left sidebar, you will find the Extensions tab.
If you see the error Error while fetching extensions. XHR failed on Debian at the IUT, consult the VSCodium technical support to configure the proxy.
Install the clangd extension from llvm-vs-code-extensions.
clangd
clangd is an LSP for C++. It analyzes your files in the background and provides features such as auto-completion, error detection, and code navigation.
For clangd to work properly, it needs to know how your project is compiled. To do this, you must provide a compile_flags.txt file.
Add the following
compile_flags.txtfile toLab7/, at the same level as themakefile.
-xc++
-std=c++17
-IincludeAdd the following
compile_flags.txtfile toLab8/andLab9/, at the same level as themakefile.
-xc++
-std=c++17
-Iinclude
-Itests/includecompile_flags.txt
compile_flags.txtThis file is only used to provide compilation parameters to the clangd extension so that it understands:
that this is a C++ project (
-xc++),that the version used is C++17 (
-std=c++17),that headers are located in
include/(-Iinclude) ortests/include/(-Itests/include).
This file does not interact with the makefile.
Review the contents of previous labs (Lab7, Lab8, and Lab9). If you see errors (underlined in red), reload the clangd extension by going to Extensions > Installed > clangd, then click Disable, then Restart Extensions, and finally Enable.
Code navigation¶
Open the file
Lab8/source/fizz-buzz.cppin the VSCodium editor.Hover over underlined headers: you should see where the corresponding header is located as well as the methods used/implemented in the
.cpp.Hover over the class name
FizzBuzz: you should see which header declares it as well as its documentation.Hover over the function name
fizzBuzzand observe the documentation.
Documentation
We will learn how to write documentation in a future lab, but you can already see the usefulness of well-written documentation in your development environment.
Open
Lab8/include/fizz-buzz.h, double-click onfizzBuzz, then right-click and choose Go to Definition (or press F12): you will be taken to its definition inLab8/source/fizz-buzz.cpp.You can navigate back from
fizzBuzz.cppusing Go to Declaration.Open
Lab7/source/main.cppand observe that objects and functions with parameters now display the parameter name before its value (for exampletitle:).
This also highlights the importance of properly naming variables.
Add a line in
int main()starting withlibrary.and observe the auto-completion suggestions.If you do not end the line with
;, an error will appear (underlined in red). Hover over it to see the message.If you do not save the modification, a white dot appears next to the file name. It disappears after saving (Ctrl + S).
Terminal¶
Open an integrated terminal via Terminal > New Terminal.
You will see a panel appear at the bottom. The useful tabs for now are Terminal and Problems.
If there is an error, you can view it in the Problems tab.
The integrated terminal works like a standard terminal, and you can open multiple terminals simultaneously.
Search && Replace¶
A useful feature is searching and replacing text.
In the Search tab (magnifying glass in the sidebar), you can perform a search with replacement.
Search for
fizzBuzz.Click on an occurrence to view the corresponding code.
Enable Match Case (
Aa) to distinguishfizzBuzzfromFizzBuzz.If you fill in the Replace field, you will see a preview of the changes before applying them.
Build, Run && Clean¶
In the IDEs you have used so far, you could compile, run, and clean your code using somewhat “mysterious” buttons.
We will now lift the curtain and build these buttons ourselves in VSCodium, which will execute the commands make, make run, and make clean.
You can of course still use these commands directly in the terminal.
In general, a project has a single root with a build file. However, since our repository contains multiple mini-projects, we will create generic tasks that can take arguments.
Create the
.vscode/directory at the root of the repository (at the same level as theLabX/directories) if it does not already exist.Add
.vscode/to your.gitignorefile.Create the
tasks.jsonfile in the.vscode/directory with the following content:
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "make",
"options": {
"cwd": "${workspaceFolder}/${input:lab}"
}
},
{
"label": "Run",
"type": "shell",
"command": "make run",
"options": {
"cwd": "${workspaceFolder}/${input:lab}"
}
},
{
"label": "Clean",
"type": "shell",
"command": "make clean",
"options": {
"cwd": "${workspaceFolder}/${input:lab}"
}
}
],
"inputs": [
{
"id": "lab",
"type": "pickString",
"description": "Select the Lab",
"options": ["Lab7", "Lab8", "Lab9"]
}
]
}tasks.json
tasks.jsonThis file is part of our IDE configuration. These tasks correspond to shortcuts that we can execute directly from the IDE, without needing to type commands in the terminal.
The syntax is as follows:
version: corresponds to the.jsonfile format used to define tasks.tasks: list of tasks we are going to create.label: the name of the task.type: the type of task; here, it is ashellcommand executed in the terminal.command: the command to execute.options: options passed to the command. Here, for example, we runmakein the directory${workspaceFolder}/${input:lab}, which corresponds toqualite-dev-s2-prenom-nom/LabX/.
inputs: inputs used in the definition of tasks.id: the input identifier.type: the input type. Here,pickStringallows selecting from a list of strings.description: description displayed in the interface.options: list of possible values. Here,["Lab7", "Lab8", "Lab9"]correspond to the three labs completed so far with a makefile.
Install the Task Buttons extension by spencerwmiles. This extension allows you to add buttons linked to tasks in the status bar at the bottom of the screen.
Create a
settings.jsonfile in.vscode/with the following content:
{
"VsCodeTaskButtons.tasks": [
{
"label": "🔨 Build",
"task": "Build"
},
{
"label": "▶️ Run",
"task": "Run"
},
{
"label": "🧹 Clean",
"task": "Clean"
}
]
}You should see the buttons appear at the bottom left of your screen. Click on them to test them and observe how they work.
Now that you understand what is behind the “magic” buttons in your IDEs, we will create a new “🧪 Tests” button that will execute make tests in the correct directory.
Add a “Tests” task in
tasks.jsonwith the appropriate parameters and a new inputlabWithTests.Add an input with the identifier
labWithTestsand set its options to only the labs that contain tests (Lab8andLab9).In
settings.json, add a new button with the label “🧪 Tests” in"VsCodeTaskButtons.tasks".Test your new “🧪 Tests” button.
Bonus: other useful extensions¶
Project Manager
Project Manager (by alefragnani) allows you to save your projects in VSCodium so that you can open them directly from a tab in the left sidebar. You can also organize them by adding tags.
Code Spell Checker
Code Spell Checker and French - Code Spell Checker (by Street Side Software) allow you to correct spelling mistakes in English and French, respectively.
You can add the following line to your settings.json after installing these extensions (if you use both at the same time):
"cSpell.language": "en,fr",If you frequently use words that are not in the dictionaries, you can add them by clicking on 💡 next to an underlined word (or by pressing Ctrl + .), then choosing an option such as Add: “...” to workspace settings to add it to the current workspace.
If you are ahead, you can start the next lab on Git integration in VSCodium, as well as the basics of debugging and the use of debugging tools integrated into IDEs.