### Clone and Setup VS Code C++ Tools Repository Source: https://github.com/microsoft/vscode-cpptools/blob/main/Extension/readme.developer.md Clone the repository and install dependencies using npm and Yarn. Ensure you have Node.js v16+ installed. The bootstrap script installs Yarn and then runs `yarn install --frozen-lockfile`. ```bash git clone https://github.com/microsoft/vscode-cpptools.git cd vscode-cpptools/Extension npm run bootstrap ``` -------------------------------- ### Troubleshoot Missing Binary Error Source: https://github.com/microsoft/vscode-cpptools/blob/main/Documentation/Building the Extension.md If the C/C++ language server fails to start due to a missing binary, copy the 'cpptools' and 'cpptools-srv' binaries from a Marketplace installation to the local Extension/bin directory. ```bash get the binaries from installing the extension and then copying the binaries 1. To do this, install this extension from the Visual Studio Marketplace and find its location on your device. It might be in a directory like `\wsl$\\Ubuntu\\home\\hamir\.vscode-server\\extensions\\ms-vscode.cpptools-`, for example. 2. Next, go to the `bin/` directory of the aforementioned directory, and drag-and-drop, or copy-and-paste, `cpptools` and `cpptools-srv` from `...\\extensions\\ms-vscode.cpptools-\\bin\\` to this repository's `Extension\\bin\\` directory on your local device, so that `.../vscode-cpptools/Extension/bin/cpptools` and `.../vscode-cpptools/Extension/bin/cpptools-srv` both exist in your workspace. 3. The aforementioned warning should be gone, and Intellisense, which gives those squiggly red error lines, should now be present. 4. The `insiders` branch has binaries compatible with the latest Pre-Release version of the extension, and the `release` branch has binaries compatible with the latest Release version, but the `main` branch may have TypeScript changes that are incompatible with the published binaries, in which case, you'll need to create a branch off the `insiders` or `release` branches. ``` -------------------------------- ### Install vsce Globally (Optional) Source: https://github.com/microsoft/vscode-cpptools/blob/main/Documentation/Building the Extension.md Install the 'vsce' tool globally to package the extension into a VSIX file. ```bash yarn global add vsce ``` -------------------------------- ### Verify Clang Installation Source: https://github.com/microsoft/vscode-cpptools/blob/main/Extension/walkthrough/installcompiler/install-clang-macos.md After installing the developer tools, execute this command in the Terminal to confirm that Clang is installed and to view its version information. ```bash clang --version ``` -------------------------------- ### Install Extension Dependencies Source: https://github.com/microsoft/vscode-cpptools/blob/main/Documentation/Building the Extension.md Install the required dependencies for building the extension using yarn. ```bash yarn install ``` -------------------------------- ### Example C/C++ Extension Directory Path Source: https://github.com/microsoft/vscode-cpptools/blob/main/Extension/Reinstalling the Extension.md This is an example of a specific C/C++ extension directory path. You would typically delete a directory like this to force a clean reinstallation. ```bash %USERPROFILE%\.vscode\extensions\ms-vscode.cpptools-1.9.0 ``` ```bash $HOME/.vscode/extensions/ms-vscode.cpptools-1.9.0 ``` -------------------------------- ### Install linux-tools-common Package Source: https://github.com/microsoft/vscode-cpptools/wiki/Troubleshooting-Performance-Issues Installs the common tools package for the perf profiling tool on Linux. ```bash sudo apt-get install linux-tools-common ``` -------------------------------- ### Install Command Line Developer Tools Source: https://github.com/microsoft/vscode-cpptools/blob/main/Extension/walkthrough/installcompiler/install-clang-macos.md Run this command in a Terminal window to install the necessary command line developer tools, which include the Clang compiler. ```bash xcode-select --install ``` -------------------------------- ### Verify MSVC Compiler Installation Source: https://github.com/microsoft/vscode-cpptools/blob/main/Extension/walkthrough/installcompiler/install-compiler-windows10.md After installation, open the Developer Command Prompt for VS and run 'cl' to check if the MSVC compiler is installed correctly. A copyright message indicates a successful installation. ```bash cl ``` -------------------------------- ### Verify GCC Installation Source: https://github.com/microsoft/vscode-cpptools/blob/main/Extension/walkthrough/installcompiler/install-gcc-linux.md Checks if GCC has been successfully installed. This command should display the GCC version and copyright information. ```bash gcc --version ``` -------------------------------- ### Install GCC and GDB on Linux Source: https://github.com/microsoft/vscode-cpptools/blob/main/Extension/walkthrough/installcompiler/install-gcc-linux.md Installs the essential GNU compiler tools and the GDB debugger. This command is necessary for C++ development on Linux. ```bash sudo apt install build-essential gdb ``` -------------------------------- ### Generate Debug Configurations for launch.json Source: https://context7.com/microsoft/vscode-cpptools/llms.txt This method generates `launch.json` debug configurations by scanning the workspace for installed compilers and build tasks. It presents a Quick Pick menu if multiple options exist. ```jsonc // .vscode/launch.json — result of running "Add Configuration" or the play button { "version": "2.0.0", "configurations": [ { // cppdbg: GDB on Linux / LLDB on macOS "name": "C/C++: g++ build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "/usr/bin/gdb", "preLaunchTask": "C/C++: g++ build active file", "setupCommands": [ { "text": "-enable-pretty-printing", "ignoreFailures": true }, { "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } ] }, { // cppvsdbg: Windows-only Visual Studio debugger "name": "C/C++: cl.exe build and debug active file", "type": "cppvsdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "console": "integratedTerminal", "preLaunchTask": "C/C++: cl.exe build active file" }, { // Attach to a running process "name": "C/C++: Attach to process", "type": "cppdbg", "request": "attach", "program": "${workspaceFolder}/build/myapp", "processId": "${command:pickProcess}", "MIMode": "gdb" } ] } ``` -------------------------------- ### Update Ubuntu Package Lists Source: https://github.com/microsoft/vscode-cpptools/blob/main/Extension/walkthrough/installcompiler/install-gcc-linux.md Run this command before installing new packages to ensure your package lists are up-to-date. This helps prevent installation issues. ```bash sudo apt update ``` -------------------------------- ### C/C++ Build Tasks Configuration Source: https://context7.com/microsoft/vscode-cpptools/llms.txt Example tasks.json configuration for C/C++ build tasks, automatically generated by the extension. It shows configurations for g++ and clang++ compilers. ```json { "version": "2.0.0", "tasks": [ { "type": "cppbuild", "label": "C/C++: g++ build active file", "command": "/usr/bin/g++", "args": [ "-fdiagnostics-color=always", "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": ["$gcc"], "group": { "kind": "build", "isDefault": true }, "detail": "compiler: /usr/bin/g++" }, { "type": "cppbuild", "label": "C/C++: clang++ build active file", "command": "/usr/bin/clang++", "args": ["-std=c++20", "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"], "options": { "cwd": "${fileDirname}" }, "problemMatcher": ["$gcc"], "group": "build", "detail": "compiler: /usr/bin/clang++" } ] } ``` -------------------------------- ### Install MSVC Compiler on Windows Source: https://github.com/microsoft/vscode-cpptools/blob/main/Extension/walkthrough/installcompiler/install-compiler-windows11.md Use this command in the VS Code terminal to install the Visual Studio Build Tools, including the MSVC compiler and Windows 11 SDK. ```shell winget install Microsoft.VisualStudio.2022.BuildTools --force --override "--wait --passive --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows11SDK.26100" ``` -------------------------------- ### Install MSVC Compiler on Windows Source: https://github.com/microsoft/vscode-cpptools/blob/main/Extension/walkthrough/installcompiler/install-compiler-windows10.md Use this command in the VS Code terminal to install the Visual Studio Build Tools, including the MSVC compiler and necessary components for C++ development. ```bash winget install Microsoft.VisualStudio.2022.BuildTools --force --override "--wait --passive --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK.19041" ``` -------------------------------- ### Attach Debugger Configuration for Mac (lldb) Source: https://github.com/microsoft/vscode-cpptools/wiki/Attaching-debugger-to-cpptools-or-cpptools‐srv Set up launch.json to attach lldb to the cpptools process on macOS. The 'program' path needs to be specified, and 'processId' should be set to '${command:pickProcess}'. ```json { "version": "0.2.0", "configurations": [ { "name": "(lldb) Attach", "type": "cppdbg", "request": "attach", "processId": "${command:pickProcess}", "program": "/Users/MyName/.vscode/extensions/ms-vscode.cpptools-1.0.0/bin/cpptools", "MIMode": "lldb" } ] } ``` -------------------------------- ### Configure IntelliSense with c_cpp_properties.json Source: https://context7.com/microsoft/vscode-cpptools/llms.txt Defines IntelliSense configurations for different platforms, specifying compiler paths, include paths, preprocessor defines, and language standards. Use this file to customize how the C/C++ extension parses and understands your code. ```json // .vscode/c_cpp_properties.json { "configurations": [ { "name": "Linux", "compilerPath": "/usr/bin/g++", "compilerArgs": ["-m64"], "cStandard": "c17", "cppStandard": "c++20", "intelliSenseMode": "linux-gcc-x64", "includePath": [ "${workspaceFolder}/**", "/usr/local/include" ], "defines": [ "MY_FEATURE=1", "NDEBUG" ], "forcedInclude": [ "${workspaceFolder}/include/pch.h" ], "browse": { "path": ["${workspaceFolder}"], "limitSymbolsToIncludedHeaders": true }, "customConfigurationVariables": { "myBuildType": "release" } }, { "name": "Win32", "compilerPath": "cl.exe", "windowsSdkVersion": "10.0.22621.0", "intelliSenseMode": "windows-msvc-x64", "cppStandard": "c++17" }, { "name": "Mac", "compilerPath": "/usr/bin/clang++", "intelliSenseMode": "macos-clang-arm64", "macFrameworkPath": ["/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"], "cppStandard": "c++20" } ], "version": 4 } ``` -------------------------------- ### Configure Pipe Transport for Launching Source: https://github.com/microsoft/vscode-cpptools/wiki/Debugger/gdb/PipeTransport Use this configuration in launch.json to establish a pipe connection for launching a remote process. Specify the working directory, program, arguments for the pipe, and the debugger path. ```json "pipeTransport": { "pipeCwd": "/usr/bin", "pipeProgram": "/usr/bin/ssh", "pipeArgs": [ "-pw", "", "user@10.10.10.10" ], "debuggerPath": "/usr/bin/gdb" }, ``` -------------------------------- ### Install Linux Kernel Specific Tools Source: https://github.com/microsoft/vscode-cpptools/wiki/Troubleshooting-Performance-Issues Installs the perf tool package specific to the Linux kernel version. Replace '' with your actual kernel version obtained via 'uname -r'. ```bash sudo apt-get install linux-tools-5.4.0-42-generic ``` -------------------------------- ### Clone CppTools Repository Source: https://github.com/microsoft/vscode-cpptools/blob/main/Documentation/Building the Extension.md Clone the release branch of the CppTools repository to get the necessary source code. ```bash git clone -b release https://github.com/Microsoft/vscode-cpptools ``` -------------------------------- ### registerCustomConfigurationProvider() Source: https://context7.com/microsoft/vscode-cpptools/llms.txt Registers a custom configuration provider with the C/C++ extension. This allows extensions to dynamically supply per-file IntelliSense settings based on custom build systems. ```APIDOC ## `CppTools.registerCustomConfigurationProvider()` ### Description Registers a custom configuration provider with the C/C++ extension. This allows extensions to dynamically supply per-file IntelliSense settings based on custom build systems. ### Method Signature `registerCustomConfigurationProvider(provider: CustomConfigurationProvider): void` ### Parameters - **provider** (CustomConfigurationProvider) - Required - An object implementing the `CustomConfigurationProvider` interface. ### Usage Third-party extensions implement the `CustomConfigurationProvider` interface and call this method to supply per-file IntelliSense settings dynamically. After registering, the provider must call `notifyReady()` within 30 seconds to signal it has finished loading, and then call `didChangeCustomConfiguration()` / `didChangeCustomBrowseConfiguration()` whenever settings change. ### Example ```typescript import { CppToolsApi, CustomConfigurationProvider, getCppToolsApi, Version } from 'vscode-cpptools'; import * as vscode from 'vscode'; class MyBuildSystemProvider implements CustomConfigurationProvider { readonly name = 'My Build System'; readonly extensionId = 'my-org.my-build-system'; async canProvideConfiguration(uri: vscode.Uri): Promise { return uri.fsPath.endsWith('.cpp') || uri.fsPath.endsWith('.c'); } async provideConfigurations(uris: vscode.Uri[]): Promise { return uris.map(uri => ({ uri, configuration: { includePath: ['/usr/local/include', `${vscode.workspace.rootPath}/include`], defines: ['MY_BUILD=1', 'PLATFORM_LINUX'], intelliSenseMode: 'linux-gcc-x64', standard: 'c++20', compilerPath: '/usr/bin/g++' } })); } async canProvideBrowseConfiguration(): Promise { return true; } async provideBrowseConfiguration(): Promise { return { browsePath: [vscode.workspace.rootPath ?? ''] }; } async canProvideBrowseConfigurationsPerFolder(): Promise { return false; } async provideFolderBrowseConfiguration(_uri: vscode.Uri): Promise { return { browsePath: [] }; } dispose(): void {} } // Called from the integrating extension's activate(): export async function activate(context: vscode.ExtensionContext): Promise { const cppToolsApi: CppToolsApi | undefined = await getCppToolsApi(Version.v6); if (!cppToolsApi) { return; } const provider = new MyBuildSystemProvider(); cppToolsApi.registerCustomConfigurationProvider(provider); // Load build data, then signal ready: await loadBuildDatabase(); cppToolsApi.notifyReady(provider); } ``` ```