2021-08-27 00:01:31 +00:00
# Visual Studio Code Project Configuration
Visual Studio Code does not work optimally for Serenity development, and there's a bunch of configuring and fiddling around you'll have to do.
The WSL Remote extension allows you to use VSCode in Windows while using the normal WSL workflow. This works surprisingly well, but for code comprehension speed you should put the Serenity directory on your WSL root partition.
## Code comprehension
Both C++ comprehension tools listed below report fake errors.
### clangd
2022-04-26 16:59:18 +00:00
The official clangd extension can be used for C++ comprehension. It is recommended in general, as it is most likely to work on all platforms. You'll have to use the following .clangd:
2021-08-27 00:01:31 +00:00
```yaml
CompileFlags:
2022-10-13 12:09:51 +00:00
Add: [-D__serenity__, -I/path/to/serenity/Toolchain/Local/x86_64/x86_64-pc-serenity/include/c++/12.2.0, -I/path/to/serenity/Toolchain/Local/x86_64/x86_64-pc-serenity/include/c++/12.2.0/x86_64-pc-serenity]
CompilationDatabase: Build/x86_64
2021-08-27 00:01:31 +00:00
```
2022-10-13 12:09:51 +00:00
You only need the `Add:` line if you're using GCC. Run cmake at least once for this to work. There's some configuring to do for the include paths: First, replace `/path/to/serenity` with the actual path to the Serenity source folder. Then, you should replace the toolchain subdirectory and target triple architecture, here `x86_64` , with the one you're compiling most often. And finally, the compiler version (`12.2.0`) might need to be updated in the future. Just look in the `c++` parent folder and see what's currently there.
2022-04-26 16:59:18 +00:00
A known issue with clangd in general is that it likes to crash. You can usually just restart it via the command palette. If that doesn't help, close currently open C++ files and/or switch branches before restarting, which helps sometimes.
2021-08-27 00:01:31 +00:00
### Microsoft C/C++ tools
These extensions can be used as-is, but you need to point them to the custom Serenity compilers. Use the following cpp-preferences to circumvent some errors:
< details >
2021-10-11 21:34:53 +00:00
< summary > .vscode/c_cpp_properties.json< / summary >
2021-08-27 00:01:31 +00:00
```json
{
2021-12-14 03:47:34 +00:00
"configurations": [
{
"name": "userland-i386-gcc",
"includePath": [
"${workspaceFolder}",
2022-10-13 12:09:51 +00:00
"${workspaceFolder}/Build/x86_64/",
"${workspaceFolder}/Build/x86_64/Userland",
"${workspaceFolder}/Build/x86_64/Userland/Applications",
"${workspaceFolder}/Build/x86_64/Userland/Libraries",
"${workspaceFolder}/Build/x86_64/Userland/Services",
"${workspaceFolder}/Build/x86_64/Root/usr/include/**",
2021-12-14 03:47:34 +00:00
"${workspaceFolder}/Userland",
"${workspaceFolder}/Userland/Libraries",
"${workspaceFolder}/Userland/Libraries/LibC",
"${workspaceFolder}/Userland/Services",
2022-10-13 12:09:51 +00:00
"${workspaceFolder}/Toolchain/Local/x86_64/x86_64-pc-serenity/include/c++/**"
2021-12-14 03:47:34 +00:00
],
"defines": [
"DEBUG",
"__serenity__"
],
2022-10-13 12:09:51 +00:00
"compilerPath": "${workspaceFolder}/Toolchain/Local/x86_64/bin/x86_64-pc-serenity-g++",
2021-12-14 03:47:34 +00:00
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "linux-gcc-x86",
2022-10-13 12:09:51 +00:00
"compileCommands": "Build/x86_64/compile_commands.json",
2021-12-14 03:47:34 +00:00
"compilerArgs": [
2022-08-01 13:35:36 +00:00
"-Wall",
"-Wextra",
"-Werror"
2021-12-14 03:47:34 +00:00
],
"browse": {
"path": [
"${workspaceFolder}",
2022-10-13 12:09:51 +00:00
"${workspaceFolder}/Build/x86_64/",
"${workspaceFolder}/Build/x86_64/Userland",
"${workspaceFolder}/Build/x86_64/Userland/Applications",
"${workspaceFolder}/Build/x86_64/Userland/Libraries",
"${workspaceFolder}/Build/x86_64/Userland/Services",
"${workspaceFolder}/Build/x86_64/Root/usr/include/**",
2021-12-14 03:47:34 +00:00
"${workspaceFolder}/Userland",
"${workspaceFolder}/Userland/Libraries",
"${workspaceFolder}/Userland/Libraries/LibC",
"${workspaceFolder}/Userland/Services",
2022-10-13 12:09:51 +00:00
"${workspaceFolder}/Toolchain/Local/x86_64/x86_64-pc-serenity/include/c++/**"
2021-12-14 03:47:34 +00:00
],
"limitSymbolsToIncludedHeaders": true,
2022-10-13 12:09:51 +00:00
"databaseFilename": "${workspaceFolder}/Build/x86_64/"
2021-12-14 03:47:34 +00:00
}
}
2021-08-27 00:01:31 +00:00
],
2021-12-14 03:47:34 +00:00
"version": 4
2021-08-27 00:01:31 +00:00
}
```
< / details >
2022-01-06 14:07:15 +00:00
Most nonsensical errors from the extension also involve not finding methods, types etc.
2021-08-27 00:01:31 +00:00
### DSL syntax highlighting
There's a syntax highlighter extension for both IPC and GML called "SerenityOS DSL Syntax Highlight", available [here ](https://marketplace.visualstudio.com/items?itemName=kleinesfilmroellchen.serenity-dsl-syntaxhighlight ) or [here ](https://open-vsx.org/extension/kleinesfilmroellchen/serenity-dsl-syntaxhighlight ).
## Formatting
2022-04-26 16:59:18 +00:00
clang-format is included with the Microsoft tools (see above); there's also a separate extension which works well. The settings below include a key that makes it use the proper style. Alternatively, you can use the clang-format extension itself, which should work out of the box.
2021-08-27 00:01:31 +00:00
## Settings
These belong in the `.vscode/settings.json` of Serenity.
```json
2021-12-14 03:47:34 +00:00
{
// Excluding the generated directories keeps your file view clean and speeds up search.
"files.exclude": {
"**/.git": true,
"Toolchain/Local/**": true,
"Toolchain/Tarballs/**": true,
"Toolchain/Build/**": true,
"Build/**": true,
"build/**": true,
},
"search.exclude": {
"**/.git": true,
"Toolchain/Local/**": true,
"Toolchain/Tarballs/**": true,
"Toolchain/Build/**": true,
"Build/**": true,
"build/**": true,
},
2022-04-26 16:59:18 +00:00
// Force clang-format to respect Serenity's .clang-format style file. This is not necessary if you're not using the Microsoft C++ extension.
2021-12-14 03:47:34 +00:00
"C_Cpp.clang_format_style": "file",
// Tab settings
"editor.tabSize": 4,
2022-03-06 19:07:59 +00:00
"editor.useTabStops": false,
// format trailing new lines
"files.trimFinalNewlines": true,
"files.insertFinalNewline": true,
// git commit message length
"git.inputValidationLength": 72,
"git.inputValidationSubjectLength": 72
2021-12-14 03:47:34 +00:00
}
2021-08-27 00:01:31 +00:00
```
## Customization
### Custom Tasks
2021-11-03 12:57:26 +00:00
You can create custom tasks (`.vscode/tasks.json`) to quickly compile Serenity.
The following three example tasks should suffice in most situations, and allow you to specify the build system to use, as well as give you error highlighting.
Note: The Assertion und KUBSan Problem matchers will only run after you have closed qemu.
< details >
2022-11-03 06:18:17 +00:00
< summary > .vscode/tasks.json< / summary >
2021-08-27 00:01:31 +00:00
```json
{
2021-12-14 03:47:34 +00:00
"version": "2.0.0",
2021-08-27 00:01:31 +00:00
"tasks": [
{
2021-11-03 12:57:26 +00:00
"label": "build lagom",
2021-08-27 00:01:31 +00:00
"type": "shell",
2021-12-14 03:47:34 +00:00
"problemMatcher": [
{
"base": "$gcc",
"fileLocation": [
"relative",
"${workspaceFolder}/Build/lagom"
]
}
],
2021-08-27 00:01:31 +00:00
"command": [
"bash"
],
"args": [
"-c",
2021-11-03 12:57:26 +00:00
"\"Meta/serenity.sh build lagom\""
2021-08-27 00:01:31 +00:00
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"group": "build",
"panel": "shared",
"showReuseMessage": true,
"clear": true
}
},
2021-11-03 12:57:26 +00:00
{
"label": "build",
"type": "shell",
"command": "bash",
2021-12-14 03:47:34 +00:00
"args": [
"-c",
"Meta/serenity.sh build ${input:arch} ${input:compiler}"
],
"problemMatcher": [
{
"base": "$gcc",
"fileLocation": [
"relative",
// FIXME: Clang uses ${input:arch}clang
"${workspaceFolder}/Build/${input:arch}"
]
2021-11-03 12:57:26 +00:00
},
2021-12-14 03:47:34 +00:00
{
"source": "gcc",
"fileLocation": [
"relative",
// FIXME: Clang uses ${input:arch}clang
"${workspaceFolder}/Build/${input:arch}"
],
"pattern": [
{
"regexp": "^([^\\s]*\\.S):(\\d*): (.*)$",
"file": 1,
"location": 2,
"message": 3
}
]
}
],
"group": {
"kind": "build",
"isDefault": true
}
2021-11-03 12:57:26 +00:00
},
2021-08-27 00:01:31 +00:00
{
"label": "launch",
"type": "shell",
2021-11-03 12:57:26 +00:00
"command": "bash",
2021-12-14 03:47:34 +00:00
"args": [
"-c",
"Meta/serenity.sh run ${input:arch} ${input:compiler}"
],
"options": {
"env": {
// Put your custom run configuration here, e.g. SERENITY_RAM_SIZE
}
},
"problemMatcher": [
{
"base": "$gcc",
"fileLocation": [
"relative",
// FIXME: Clang uses ${input:arch}clang
"${workspaceFolder}/Build/${input:arch}"
]
},
{
"source": "gcc",
"fileLocation": [
"relative",
// FIXME: Clang uses ${input:arch}clang
"${workspaceFolder}/Build/${input:arch}"
],
"pattern": [
{
"regexp": "^([^\\s]*\\.S):(\\d*): (.*)$",
"file": 1,
"location": 2,
"message": 3
}
]
},
{
"source": "KUBSan",
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": [
{
"regexp": "KUBSAN: (.*)",
"message": 0
},
{
"regexp": "KUBSAN: at ../(.*), line (\\d*), column: (\\d*)",
"file": 1,
"line": 2,
"column": 3
}
]
2021-08-27 00:01:31 +00:00
},
2021-12-14 03:47:34 +00:00
{
"source": "Assertion Failed",
"owner": "cpp",
"pattern": [
{
"regexp": "ASSERTION FAILED: (.*)$",
"message": 1
},
{
"regexp": "^((?:.*)\\.(h|cpp|c|S)):(\\d*)$",
"file": 1,
"location": 3
}
],
"fileLocation": [
"relative",
// FIXME: Clang uses ${input:arch}clang
"${workspaceFolder}/Build/${input:arch}"
]
}
]
2021-11-03 12:57:26 +00:00
}
],
"inputs": [
{
"id": "compiler",
"description": "Compiler to use",
"type": "pickString",
"default": "GNU",
"options": [
"GNU",
"Clang"
]
2021-08-27 00:01:31 +00:00
},
2021-11-03 12:57:26 +00:00
{
"id": "arch",
"description": "Architecture to compile for",
"type": "pickString",
2022-10-13 12:09:51 +00:00
"default": "x86_64",
2021-11-03 12:57:26 +00:00
"options": [
"i686",
"x86_64",
"aarch64"
]
}
2021-08-27 00:01:31 +00:00
]
}
```
2021-11-03 12:57:26 +00:00
< / details >
2021-08-27 00:01:31 +00:00
### License snippet
The following snippet may be useful if you want to quickly generate a license header, put it in `.vscode/serenity.code-snippets` :
```json
{
"License": {
"scope": "cpp,c",
"prefix": "license",
"body": [
"/*",
" * Copyright (c) $CURRENT_YEAR, ${1:Your Name} < ${2:YourName@Email.com}>.",
" *",
" * SPDX-License-Identifier: BSD-2-Clause",
" */"
],
2022-01-06 14:07:15 +00:00
"description": "License header"
2021-08-27 00:01:31 +00:00
}
}
```