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:
2024-06-04 21:30:09 +00:00
- [CMake Tools ](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools )
2023-03-10 09:12:17 +00:00
- [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
2024-06-04 21:30:09 +00:00
## Configuration
2024-07-13 20:42:13 +00:00
Run `./Meta/ladybird.sh build` at least once to kick off downloading and building vcpkg dependencies.
2024-06-04 21:30:09 +00:00
The CMake Tools plugin should automatically detect the `CMakePresets.json` at the root of the repository.
2024-07-13 20:42:13 +00:00
Selecting and activating the `default` preset should be enough to get started after the initial build.
You can also use the `Debug` preset to build with debug symbols, or the `Sanitizer` preset to build with ASAN/UBSAN.
For additional settings recommendations, see the [Settings ](#settings ) section below.
2024-06-04 21:30:09 +00:00
2021-08-27 00:01:31 +00:00
## Code comprehension
2024-06-04 21:30:09 +00:00
Clangd has the best support for modern compilers, especially if configured as noted below. The Microsoft C/C++ tools can work, but may require more configuration.
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-09-30 13:55:48 +00:00
clangd uses ``compile_commands.json`` files to understand the project. CMake will generate these in Build/release.
2024-02-05 11:28:11 +00:00
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 ).
2024-07-03 17:48:01 +00:00
The extension provides syntax highlighting for LibIPC's IPC files, [Web IDL ](https://webidl.spec.whatwg.org/ ), and LibJS's
2023-03-10 09:12:17 +00:00
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-09-30 13:55:48 +00:00
"${workspaceFolder}/Build/release/",
2024-11-09 17:25:08 +00:00
"${workspaceFolder}/Build/release/Libraries",
2024-11-09 17:13:18 +00:00
"${workspaceFolder}/Build/release/Services",
2024-11-09 17:25:08 +00:00
"${workspaceFolder}/Libraries",
2024-11-09 17:13:18 +00:00
"${workspaceFolder}/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-09-30 13:55:48 +00:00
"compileCommands": "Build/release/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-09-30 13:55:48 +00:00
"${workspaceFolder}/Build/release/",
2024-11-09 17:25:08 +00:00
"${workspaceFolder}/Build/release/Libraries",
2024-11-09 17:13:18 +00:00
"${workspaceFolder}/Build/release/Services",
2024-11-09 17:25:08 +00:00
"${workspaceFolder}/Libraries",
2024-11-09 17:13:18 +00:00
"${workspaceFolder}/Services"
2021-12-14 03:47:34 +00:00
],
"limitSymbolsToIncludedHeaders": true,
2024-09-30 13:55:48 +00:00
"databaseFilename": "${workspaceFolder}/Build/release/"
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
2024-10-27 13:26:23 +00:00
These belong in the `.vscode/settings.json` of Ladybird.
2021-08-27 00:01:31 +00:00
```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,
},
2024-06-04 21:30:09 +00:00
// Force clang-format to respect Ladybird'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,
2024-07-17 17:52:56 +00:00
// If clangd was obtained from a package manager, its path can be set here.
2024-07-13 20:42:13 +00:00
"clangd.path": "clangd-18",
2023-03-10 09:12:17 +00:00
"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-09-30 13:55:48 +00:00
"${workspaceFolder}/Build/release"
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-09-30 13:55:48 +00:00
"${workspaceFolder}/Build/release"
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-09-30 13:55:48 +00:00
"${workspaceFolder}/Build/release"
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-09-30 13:55:48 +00:00
"${workspaceFolder}/Build/release"
2021-12-14 03:47:34 +00:00
]
},
{
"source": "gcc",
"fileLocation": [
"relative",
2024-09-30 13:55:48 +00:00
"${workspaceFolder}/Build/release"
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-09-30 13:55:48 +00:00
"${workspaceFolder}/Build/release"
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
2024-10-30 19:18:38 +00:00
### Debugging
#### Mac
If you want to run the debugger, first place the content below in `.vscode/launch.json` in the root of the project.
2024-11-09 17:13:18 +00:00
```json
2024-10-30 19:18:38 +00:00
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to WebContent",
"type": "lldb",
"request": "attach",
"program": "${workspaceFolder}/Build/ladybird-debug/bin/Ladybird.app/Contents/MacOS/WebContent",
}
],
}
```
then run Ladybird with the debug preset and with the `--debug-process WebContent` flag:
```bash
CC=$(brew --prefix llvm)/bin/clang CXX=$(brew --prefix llvm)/bin/clang++ BUILD_PRESET=Debug ./Meta/ladybird.sh run ladybird --debug-process WebContent
```
2024-11-09 17:13:18 +00:00
Running Ladybird in this way will pause execution until a debugger is attached. You can then run the debugger by going to the **Run and Debug** menu and selecting the **Attach to WebContent** configuration.
2024-10-30 19:18:38 +00:00
#### Linux
For Linux, the `launch.json` will instead be the file below.
```json
{
"version": "2.0.0",
"configurations": [
{
"name": "Attach and debug",
"type": "cppdbg",
"request": "attach",
"program": "${workspaceRoot}/Build/ladybird-debug/libexec/WebContent",
"MIMode": "gdb",
},
]
}
```
Running Ladybird as follows:
```bash
BUILD_PRESET=Debug Meta/ladybird.sh run ladybird --debug-process WebContent
```
Then follow the same steps found in the Mac section.
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
}
}
```