Skip to content

Commit b80000b

Browse files
authored
add vscode clangd setup (#12)
1 parent 1615dfc commit b80000b

5 files changed

Lines changed: 94 additions & 11 deletions

File tree

.vscode/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# VSCode Config
22

3-
Add `launch.json` to your Node.js core repository in `.vscode` folder and run tests as shown below:
3+
Add `launch.json` and `tasks.json` to your Node.js core repository in `.vscode` folder and run tests as shown below:
44

5-
![Screen Recording](./ScreenRecording.gif)
5+
![Screen Recording](./ScreenRecording.gif)

.vscode/launch.json

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,46 @@
11
{
22
"version": "0.2.0",
33
"configurations": [
4+
// Debugging JS files
45
{
56
"type": "node",
67
"request": "launch",
78
"name": "Run single test",
89
"program": "${workspaceFolder}/${relativeFile}",
910
"cwd": "${workspaceFolder}",
1011
"runtimeExecutable": "${workspaceFolder}/node"
11-
}
12+
},
13+
// Debugging C++ files
14+
{
15+
"name": "node (debug)",
16+
"type": "cppdbg", // "cppdbg" for GDB/LLDB, "cppvsdbg" for Windows Visual Studio debugger
17+
"request": "launch",
18+
"program": "${workspaceFolder}/out/Debug/node",
19+
"args": [], // Optional command line args
20+
"preLaunchTask": "make debug",
21+
"stopAtEntry": true,
22+
"cwd": "${workspaceFolder}",
23+
"environment": [],
24+
"externalConsole": false,
25+
// GDB
26+
"setupCommands": [
27+
{
28+
"description": "Enable pretty printing for gdb",
29+
"text": "-enable-pretty-printing"
30+
},
31+
{
32+
"description": "Load v8 gdb configuration",
33+
"text": "-interpreter-exec console \"source -v ${workspaceFolder}/deps/v8/tools/gdbinit\""
34+
},
35+
],
36+
// LLDB
37+
"MIMode": "lldb",
38+
"setupCommands": [
39+
{
40+
"description": "Load v8 lldb configuration",
41+
"text": "-interpreter-exec mi \"command script import ${workspaceFolder}/deps/v8/tools/lldb_commands.py\""
42+
},
43+
],
44+
},
1245
]
1346
}

.vscode/settings.json

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
{
2-
"eslint.format.enable": true,
3-
"eslint.nodePath": "./tools/node_modules/eslint",
4-
"eslint.options": {
5-
"configFile": "./.eslintrc.js"
6-
},
7-
"eslint.validate": [
8-
"javascript"
9-
]
2+
"eslint.format.enable": true,
3+
"eslint.nodePath": "./tools/node_modules/eslint",
4+
"eslint.options": {
5+
"configFile": "./.eslintrc.js"
6+
},
7+
"eslint.validate": [
8+
"javascript"
9+
],
10+
// clangd config
11+
"clangd.arguments": [
12+
"-header-insertion=never" // More annoying than helpful
13+
],
14+
"clangd.onConfigChanged": "restart",
15+
"[cpp]": {
16+
"editor.defaultFormatter": "xaver.clang-format"
17+
},
18+
// Let clangd take care of these features.
19+
"C_Cpp.autocomplete": "disabled",
20+
"C_Cpp.errorSquiggles": "disabled",
21+
"C_Cpp.intelliSenseEngine": "disabled",
1022
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# node-code-ide-configs
2+
23
Here are some IDE specific configs you can use while developing on [Node.js core](https://github.com/nodejs/node)
4+
5+
- Visual Studio Code, see [./vscode.md](./vscode.md)

vscode.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Set up VSCode
2+
3+
1. In Node.js working directory, run `./configure -C` (if building with ninja, run `./configure --ninja -C`).
4+
1. This creates the `compile_commands.json` file that clangd requires for indexing. Re-run this tool every time you pull in (or make) significant changes (in particular: adding, moving, or removing files).
5+
1. Install VSCode extensions:
6+
1. [C/C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) (by Microsoft)
7+
1. [clangd](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd) (by LLVM)
8+
1. Configure settings. See the example `settings.json` below for inspiration.
9+
1. Note that there are `~/.config/Code/User/settings.json` for system-wide config and `./.vscode/settings.json` for project-specific settings. Choose wisely which setting goes where.
10+
1. on Windows, the paths are `%AppData%\Code\User\settings.json` and `.\code\settings.json`, respectively.
11+
12+
**Notes and gotchas:**
13+
14+
clangd sometimes crashes (e.g. when you keep making changes quicker than it can index them, it sometimes gets confused). VSCode will give up on restarting it if this happens too frequently. In that case, hit `F1` (or `Ctrl+Shift+P`), type "reload", and select "Developer: Reload Window" to reload VSCode.
15+
16+
Example `settings.json`:
17+
18+
```json
19+
{
20+
"clangd.arguments": [
21+
"-header-insertion=never" // More annoying than helpful
22+
],
23+
"clangd.onConfigChanged": "restart",
24+
// Let clangd take care of these features.
25+
"C_Cpp.autocomplete": "disabled",
26+
"C_Cpp.errorSquiggles": "disabled",
27+
"C_Cpp.intelliSenseEngine": "disabled"
28+
}
29+
```
30+
31+
If you want to use VSCode's "build tasks" feature to build from the IDE (default shortcut: `Ctrl+Shift+B`), set up a task to your liking. See the example in [`.vscode/`](./.vscode/README.md) for inspiration.
32+
33+
See also how to setup VSCode for V8 and Chromium:
34+
- https://v8.dev/docs/ide-setup
35+
- https://chromium.googlesource.com/chromium/src/+/master/docs/vscode.md

0 commit comments

Comments
 (0)