Skip to content

Add inline Test CodeLens for per-test execution in source editor#4923

Open
Omotola wants to merge 4 commits into
mainfrom
dev/oakeredolu/add-test-codelens
Open

Add inline Test CodeLens for per-test execution in source editor#4923
Omotola wants to merge 4 commits into
mainfrom
dev/oakeredolu/add-test-codelens

Conversation

@Omotola
Copy link
Copy Markdown
Contributor

@Omotola Omotola commented May 2, 2026

Overview

Implements inline "Run" and "Debug" CodeLens buttons directly in C++ source files, enabling users to execute individual tests from the editor gutter without running all tests. Resolves #4451.

Changes

  • New File: src/ui/testCodeLensProvider.ts — Provides CodeLens UI for test locations
  • Enhanced: src/ctest.ts — Improved test source location resolution with 3-tier priority:
    1. CMake metadata (DEF_SOURCE_LINE property)
    2. Code model executable→sources mapping
    3. Fallback doctest parsing with fuzzy token matching
  • Integrated: src/extension.ts — Wired CodeLens provider and per-test command handlers
  • Localized: package.nls.json — Added UI strings for CodeLens labels

Key Improvements

  • Robust doctest parsing: Supports TEST_CASE(), SCENARIO(), TEMPLATE_TEST_CASE() macros with raw string literals (R"...")
  • Fuzzy name matching: Normalized test name comparison handles scenario prefixes and bracket tags [...]
  • Per-test execution: Commands cmake.runTestFromCodeLens and cmake.debugTestFromCodeLens route to single test instead of all tests
  • Accurate line ranges: Test items properly assigned per-line ranges for cursor-based VS Code test commands

Testing

  • ✅ Feature validated with doctest framework
  • ✅ Single-test execution working correctly
  • ✅ Source location resolution handles edge cases
  • ✅ No TypeScript diagnostics errors

Validation

image

Notes

  • Feature respects existing cmake.testExplorerIntegrationEnabled setting
  • Works in both CMake Presets and Kits/Variants modes
  • Compatible with single-config and multi-config generators

Omotola and others added 3 commits May 1, 2026 17:04
Add void operator to fire-and-forget showErrorMessage calls in
runTestFromCodeLens and debugTestFromCodeLens to satisfy the
@typescript-eslint/no-floating-promises rule.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hanniavalera hanniavalera enabled auto-merge (squash) May 13, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Run/Debug From Source

2 participants