2021-08-27 00:01:31 +00:00
# Visual Studio Code Project Configuration
2024-05-31 23:27:20 +00:00
Visual Studio Code requires some configuration files, and a tailored ``settings.json`` file to understand ladybird.
2021-08-27 00:01:31 +00:00
2024-05-31 23:27:20 +00:00
The WSL Remote extension allows you to use VS Code in Windows while using the normal WSL workflow. This works well, but for code comprehension speed you should put the ladybird directory on your WSL root partition.
2023-03-10 09:12:17 +00:00
The recommended extensions for VS Code include:
- [clangd ](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd )
- [GitLens ](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens )
2021-08-27 00:01:31 +00:00
## Code comprehension
2023-03-10 09:12:17 +00:00
Clangd has the best support for cross-compiling workflows, especially if configured as noted below. The Microsoft C/C++ tools can work, but require a lot more configuration and may not understand the sysroot in use.
2021-08-27 00:01:31 +00:00
### clangd
2023-03-10 09:12:17 +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.
2024-06-03 21:46:00 +00:00
clangd uses ``compile_commands.json`` files to understand the project. CMake will generate these in Build/ladybird.
2024-05-31 23:27:20 +00:00
Depending on which configuration you use most, set the CompilationDatabase configuration item in the below ``.clangd`` file accordingly. It goes at the root of your checkout (``ladybird/.clangd``):
2021-08-27 00:01:31 +00:00
```yaml
CompileFlags:
2024-06-03 21:46:00 +00:00
CompilationDatabase: Build/ladybird
2024-02-05 11:28:11 +00:00
Diagnostics:
UnusedIncludes: None
MissingIncludes: None
2021-08-27 00:01:31 +00:00
```
2024-02-05 11:28:11 +00:00
The UnusedIncludes and MissingIncludes flags are used to disable the [Include Cleaner ](https://clangd.llvm.org/design/include-cleaner ) feature of newer clangd releases.
It can be re-enabled if you don't mind the noisy inlay hints and problems in the problem view.
2024-05-31 23:27:20 +00:00
Run ``./Meta/ladybird.sh run ladybird`` at least once to generate the ``compile_commands.json`` file.
2022-04-26 16:59:18 +00:00
2023-03-10 09:12:17 +00:00
#### Known issues
- clangd has a tendency to crash when stressing bleeding edge compiler features. 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.
### DSL syntax highlighting
There's a syntax highlighter extension for SerenityOS DSLs 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 ).
The extension provides syntax highlighting for LibIPC's IPC files, LibGUI's GUI Markup Language (GML), [Web IDL ](https://webidl.spec.whatwg.org/ ), and LibJS's
serialization format (no extension) as output by js with the -d option.
2021-08-27 00:01:31 +00:00
### Microsoft C/C++ tools
2024-05-31 23:27:20 +00:00
Note that enabling the extension in the same workspace as the clangd and clang-format extensions will cause conflicts.
If you choose to use Microsoft C/C++ Tools rather than clangd and clang-format, use the
2023-03-10 09:12:17 +00:00
following ``c_cpp_properties.json`` to circumvent some errors. Even with the configuration in place, the extension will likely still report errors related to types and methods not being found.
2021-08-27 00:01:31 +00:00
< 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": [
{
2024-05-31 23:27:20 +00:00
"name": "ladybird-gcc",
2021-12-14 03:47:34 +00:00
"includePath": [
"${workspaceFolder}",
2024-06-03 21:46:00 +00:00
"${workspaceFolder}/Build/ladybird/",
"${workspaceFolder}/Build/ladybird/Userland",
"${workspaceFolder}/Build/ladybird/Userland/Libraries",
"${workspaceFolder}/Build/ladybird/Userland/Services",
2021-12-14 03:47:34 +00:00
"${workspaceFolder}/Userland",
"${workspaceFolder}/Userland/Libraries",
2024-05-31 23:27:20 +00:00
"${workspaceFolder}/Userland/Services"
2021-12-14 03:47:34 +00:00
],
"defines": [
2024-05-31 23:27:20 +00:00
"DEBUG"
2021-12-14 03:47:34 +00:00
],
"cStandard": "c17",
2024-04-30 13:19:35 +00:00
"cppStandard": "c++23",
2021-12-14 03:47:34 +00:00
"intelliSenseMode": "linux-gcc-x86",
2024-06-03 21:46:00 +00:00
"compileCommands": "Build/ladybird/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}",
2024-06-03 21:46:00 +00:00
"${workspaceFolder}/Build/ladybird/",
"${workspaceFolder}/Build/ladybird/Userland",
"${workspaceFolder}/Build/ladybird/Userland/Libraries",
"${workspaceFolder}/Build/ladybird/Userland/Services",
2021-12-14 03:47:34 +00:00
"${workspaceFolder}/Userland",
"${workspaceFolder}/Userland/Libraries",
2024-05-31 23:27:20 +00:00
"${workspaceFolder}/Userland/Services"
2021-12-14 03:47:34 +00:00
],
"limitSymbolsToIncludedHeaders": true,
2024-06-03 21:46:00 +00:00
"databaseFilename": "${workspaceFolder}/Build/ladybird/"
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 >
## Formatting
2024-02-23 18:57:31 +00:00
clangd provides code formatting out of the box using the ``clang-format`` engine. ``clang-format`` support is also included with the Microsoft C/C++ tools (see above). The settings below include a key that makes the Microsoft extension use the proper style.
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,
},
"search.exclude": {
"**/.git": true,
"Toolchain/Local/**": true,
"Toolchain/Tarballs/**": true,
"Toolchain/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,
2023-03-10 09:12:17 +00:00
"git.inputValidationSubjectLength": 72,
"clangd.arguments": [
"--header-insertion=never" // See https://github.com/clangd/clangd/issues/1247
]
2021-12-14 03:47:34 +00:00
}
2021-08-27 00:01:31 +00:00
```
## Customization
### Custom Tasks
2024-05-31 23:27:20 +00:00
You can create custom tasks (`.vscode/tasks.json`) to quickly compile Ladybird.
2021-11-03 12:57:26 +00:00
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.
< 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",
2024-06-03 21:46:00 +00:00
"${workspaceFolder}/Build/ladybird"
2021-12-14 03:47:34 +00:00
]
}
],
2021-08-27 00:01:31 +00:00
"command": [
"bash"
],
"args": [
"-c",
2024-05-31 23:27:20 +00:00
"\"Meta/ladybird.sh build\""
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",
2024-05-31 23:27:20 +00:00
"Meta/ladybird.sh build"
2021-12-14 03:47:34 +00:00
],
"problemMatcher": [
{
"base": "$gcc",
"fileLocation": [
"relative",
2024-06-03 21:46:00 +00:00
"${workspaceFolder}/Build/ladybird"
2021-12-14 03:47:34 +00:00
]
2021-11-03 12:57:26 +00:00
},
2021-12-14 03:47:34 +00:00
{
"source": "gcc",
"fileLocation": [
"relative",
2024-06-03 21:46:00 +00:00
"${workspaceFolder}/Build/ladybird"
2021-12-14 03:47:34 +00:00
],
"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",
2024-05-31 23:27:20 +00:00
"Meta/ladybird.sh run ladybird"
2021-12-14 03:47:34 +00:00
],
"options": {
"env": {
2024-05-31 23:27:20 +00:00
// Put your custom run configuration here
2021-12-14 03:47:34 +00:00
}
},
"problemMatcher": [
{
"base": "$gcc",
"fileLocation": [
"relative",
2024-06-03 21:46:00 +00:00
"${workspaceFolder}/Build/ladybird"
2021-12-14 03:47:34 +00:00
]
},
{
"source": "gcc",
"fileLocation": [
"relative",
2024-06-03 21:46:00 +00:00
"${workspaceFolder}/Build/ladybird"
2021-12-14 03:47:34 +00:00
],
"pattern": [
{
"regexp": "^([^\\s]*\\.S):(\\d*): (.*)$",
"file": 1,
"location": 2,
"message": 3
}
]
},
{
"source": "Assertion Failed",
"owner": "cpp",
"pattern": [
{
"regexp": "ASSERTION FAILED: (.*)$",
"message": 1
},
{
"regexp": "^((?:.*)\\.(h|cpp|c|S)):(\\d*)$",
"file": 1,
"location": 3
}
],
"fileLocation": [
"relative",
2024-06-03 21:46:00 +00:00
"${workspaceFolder}/Build/ladybird"
2021-12-14 03:47:34 +00:00
]
}
]
2021-11-03 12:57:26 +00:00
}
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
2024-05-31 23:27:20 +00:00
The following snippet may be useful if you want to quickly generate a license header, put it in `.vscode/ladybird.code-snippets` :
2021-08-27 00:01:31 +00:00
```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
}
}
```