VSCode-Debug-Code
Overview
This plugin can quickly generate configurations in launch.json. It can generate configurations in three commands:
Debug file: It will automatically match the most suitable configuration based on the file extension of the currently opened file in the editor and persist it to .vscode/launch.json. You can extend this configuration, such as adding environment variables. Currently, it supports Python, Go, TypeScript, and JavaScript.
Debug here: It will parse the text of the line where the mouse cursor is currently located to generate a configuration. Currently, it supports Python, Pytest, Rust (Cargo), Go run, Go test, Node, and CMake/C++ tests.
Debug last: If you have ever run the Debug here command, it will be recorded in the last-commands.txt file. The Debug last command allows you to quickly run the commands in last-commands.txt, which acts as a shortcut.
Why use it?
It helps us dynamically generate .vscode/launch.json, which is especially convenient and efficient when developing command-line tools. Imagine you have N parameters for your command-line tool, and the combinations between these parameters result in M different scenarios. That means with traditional methods, you would need M configurations. That’s too cumbersome and not very conducive to direct communication among developers.
Through Debug here, you can directly input parameters into the text, for example:
$cwd=${workspaceFolder}/python-project; DEBUG=ON; PYTHONPATH="lib1"; python -m a.main --help
CMake/C++ Test Debugging
The plugin now supports debugging CMake/C++ projects with Catch2 test framework. It automatically detects the project structure and chooses the appropriate build method:
Automatic Build Method Detection
CMake Preset Projects (Recommended for modern CMake projects):
- Automatically detected when
CMakePresets.json or CMakeUserPresets.json exists in the project root
- Uses
cmake --preset=<preset-name> and cmake --build --preset=<preset-name> commands
- Supports variable substitution in
binaryDir (e.g., ${sourceDir}/build/${presetName})
- Example project:
/Users/whc/Workspace/Code/qe/test with dev preset
Traditional CMake Projects:
- Used when no CMake preset files are found
- Uses
cmake -DCMAKE_BUILD_TYPE=Debug .. and make -j4 commands
- Builds in
build directory by default
- Example project:
examples/cmake in this repository
Catch2 Test Support
- Supports
TEST_CASE("test_name", "[tag]") syntax
- Supports
SCENARIO("scenario_name", "[tag]") syntax (automatically adds Scenario: prefix)
- Test filters use correct syntax:
"test_name" (with quotes)
- Automatic executable path detection based on source filename
Usage Examples
Traditional CMake project (examples/cmake/test_example.cpp):
- Place cursor on:
TEST_CASE("Addition", "[math]")
- Run
Debug here command
- Plugin will:
- Build with
cmake -DCMAKE_BUILD_TYPE=Debug .. and make -j4
- Run
./test_example "Addition" in debugger
CMake preset project (like /Users/whc/Workspace/Code/qe/test):
- Place cursor on:
TEST_CASE("Name is qe", "[library]")
- Run
Debug here command
- Plugin will:
- Detect
CMakePresets.json with dev preset
- Build with
cmake --preset=dev and cmake --build --preset=dev
- Run
./qe_test "Name is qe" in debugger
Debugger Configuration
- Uses LLDB as the default debugger on macOS (
MIMode: "lldb")
- Sets
MIDebuggerPath: "/usr/bin/lldb"
- Configures working directory to the build directory
- Builds in Debug mode for breakpoint support
Supported File Extensions
.cpp, .c, .hpp, .h, .cc, .cxx
- Also supports
ctest commands in any file type
Examples
For more examples, please refer to the code in the examples directory.
Debug file
Debug here






Debug last
| |