Created
June 7, 2021 18:21
-
-
Save GavinRay97/3ec4412891845be6ecd6ccb31210a730 to your computer and use it in GitHub Desktop.
VS Code "clangd" base config, with: CMake Tools extension, MS C/C++ extension (debugging), vcpkg integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"recommendations": [ | |
"twxs.cmake", | |
"ms-vscode.cpptools", | |
"ms-vscode.cmake-tools", | |
"llvm-vs-code-extensions.vscode-clangd" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOTE: I prefer to put this in each project, at "<PROJECT>/.vscode/settings.json" | |
// This makes it easier to collaborate with others, as they can clone the repo | |
// and have a mostly-working cross-platform VS Code config | |
{ | |
"editor.formatOnSave": true, | |
// Disable formatting and intellisense engine in Microsoft C/C++ extension (provides debugging) | |
// This way you can have the other features of the extension but use clangd for LSP | |
"C_Cpp.formatting": "Disabled", | |
"C_Cpp.intelliSenseEngine": "Default", | |
// Configure .clangd arguments | |
"clangd.checkUpdates": true, | |
"clangd.onConfigChanged": "restart", | |
"clangd.arguments": [ | |
// --background-index - Index project code in the background and persist index on disk. | |
"-background-index", | |
// --header-insertion=<value> - Add #include directives when accepting code completions | |
// =iwyu - Include what you use. Insert the owning header for top-level symbols, unless the header is already directly included or the symbol is forward-declared | |
// =never - Never insert #include directives as part of code completion | |
"-header-insertion=iwyu", | |
// --header-insertion-decorators - Prepend a circular dot or space before the completion label, depending on whether an include line will be inserted or not | |
"-header-insertion-decorators", | |
// --inlay-hints - Enable preview of InlayHints feature | |
"--inlay-hints", | |
// --function-arg-placeholders - When disabled, completions contain only parentheses for function calls. When enabled, completions also contain placeholders for method parameters | |
"--function-arg-placeholders", | |
], | |
// Prefer "Ninja" | |
"cmake.generator": "Ninja", | |
"cmake.sourceDirectory": "${workspaceFolder}", | |
// Set build directory to format: "./build/clang13-msvc-x86_64/debug | |
"cmake.buildDirectory": "${workspaceFolder}/build/${buildKit}/${buildType}", | |
// Copy compile_commands.json from the build folder to root folder, so that clangd can use it | |
// NOTE: Alternatively, you can pass --compile-commands-dir=<string> in the "clangd.arguments" array above | |
"cmake.copyCompileCommands": "${workspaceFolder}/compile_commands.json", | |
// Configure the environment for VCPKG and compile_commands. Disable verbose if you want less information from builds. | |
"cmake.environment": { | |
"VERBOSE": "1", | |
// Assuming you have vcpkg in-tree at "<project>/vcpkg", otherwise change this or set it in your ENV system-wide | |
"VCPKG_ROOT": "${workspaceFolder}/vcpkg", | |
// Set your default triplet here to match your host and preference | |
"VCPKG_DEFAULT_TRIPLET": "x64-windows-static" | |
}, | |
"cmake.configureSettings": { | |
"CMAKE_EXPORT_COMPILE_COMMANDS": 1, | |
"CMAKE_TOOLCHAIN_FILE": "$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Curious why in extensions.json both
twxs.cmake
andms-vscode.cmake-tools
are recommended. Is one better in some scenarios and the other in other scenarios?