Skip to content

Implement session state tracking for "Run and Debug" button when Inte… - #14719

Open
Prashant Kumar Rai (8prashant) wants to merge 2 commits into
microsoft:mainfrom
8prashant:main
Open

Implement session state tracking for "Run and Debug" button when Inte…#14719
Prashant Kumar Rai (8prashant) wants to merge 2 commits into
microsoft:mainfrom
8prashant:main

Conversation

@8prashant

Copy link
Copy Markdown

Fixes #13001

When C_Cpp.intelliSenseEngine is set to "disabled", the language server client is not started. Previously, cpptools.buildAndDebug.isSourceFile and cpptools.buildAndDebug.isFolderOpen context keys (which control the visibility of the "Run / Debug C/C++ File" and "Add Debug Configuration" editor action buttons) were only updated within the language server client (client.ts). Consequently, disabling IntelliSense would cause the Run/Debug shortcut buttons to never appear in the editor title bar.

This PR updates the Debugger extension initialization (Debugger/extension.ts) to track active text editor changes and keep buildAndDebugIsSourceFile and buildAndDebugIsFolderOpen up to date regardless of whether IntelliSense is enabled or disabled.

Changes

  1. Added updateBuildAndDebugSessionState and registered an onDidChangeActiveTextEditor listener in DebuggerExtension.initialize.
  2. Added unit tests in Extension/test/scenarios/SingleRootProject/tests/buildAndDebug.test.ts verifying session state updates for source files, header files, non-C/C++ files, and undefined editors.

Verification

  • Compiled with TypeScript (yarn compile) with 0 errors.
  • Ran tests via yarn test --scenario=SingleRootProject and verified all BuildAndDebug SessionState Tests pass.

@github-project-automation github-project-automation Bot moved this to Pull Request in cpptools Aug 30, 2026
@8prashant
Prashant Kumar Rai (8prashant) marked this pull request as ready for review August 30, 2026 18:35
…lliSense is disabled and add corresponding tests

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ensures Run/Debug editor actions remain available when IntelliSense is disabled.

Changes:

  • Tracks active editor changes in the debugger extension.
  • Updates build/debug session context keys.
  • Adds source, header, non-C/C++, and undefined-editor tests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Extension/src/Debugger/extension.ts Adds independent session-state tracking.
Extension/test/scenarios/SingleRootProject/tests/buildAndDebug.test.ts Tests source-file state updates.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found one session-state lifecycle gap that should be addressed before merging.

export function updateBuildAndDebugSessionState(editor?: vscode.TextEditor): void {
if (editor && isCpp(editor.document)) {
void SessionState.buildAndDebugIsSourceFile.set(isCppOrCFile(editor.document.uri, editor.document.languageId));
void SessionState.buildAndDebugIsFolderOpen.set(isFolderOpen(editor.document.uri));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨Copilot (agent146): [Moderate] Please keep the folder context key current on every transition that can change isFolderOpen. This listener recomputes it only when the active editor is C/C++, and there is no debugger-side onDidChangeWorkspaceFolders listener. With IntelliSense disabled, opening an in-workspace C++ file sets the key to true; switching to a non-C/C++ editor leaves it true, so the editor context menu still offers C_Cpp.AddDebugConfiguration because that contribution checks only cpptools.buildAndDebug.isFolderOpen. Likewise, adding or removing the active file's workspace folder leaves the key stale until another editor change. Clear/recompute this key for non-C++/undefined editors and recompute it when workspace folders change; the tests should assert the folder key for those transitions as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pull Request

Development

Successfully merging this pull request may close these issues.

Disabling intellisense disables debugging

3 participants