Skip to content

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

Open
Prashant Kumar Rai (8prashant) wants to merge 4 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 4 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.

Comment thread Extension/src/Debugger/extension.ts Outdated
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.

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): Thanks for adding the workspace-folder listener and folder-state tests. One correction to my original comment: the contribution gated only by this key is the Command Palette entry, not the editor context menu. The latest implementation still leaves the active-file case incorrect, though: if an unrelated workspace folder is open while the active C++ source is outside it, workspaceFolders !== undefined sets this key to true, so the editor title/context actions are shown even though AddDebugConfiguration immediately warns/returns because getWorkspaceFolder(textEditor.document.uri) is undefined. Removing the active file's folder from a multi-root workspace while another root remains has the same result. It also makes enabled and disabled IntelliSense disagree because LanguageServer/client.ts still writes the URI-specific isFolderOpen(editor.document.uri) value. Please preserve active-URI membership for the editor actions and use a separate context key if the Command Palette needs global workspace existence; add an external-file or multi-root-removal test for this distinction.

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

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

Comment thread Extension/test/scenarios/SingleRootProject/tests/buildAndDebug.test.ts Outdated
Comment thread Extension/src/Debugger/extension.ts Outdated

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +141 to 148
export function updateBuildAndDebugSessionState(editor?: vscode.TextEditor): void {
void SessionState.buildAndDebugIsFolderOpen.set(vscode.workspace.workspaceFolders !== undefined);
if (editor && isCpp(editor.document)) {
void SessionState.buildAndDebugIsSourceFile.set(isCppOrCFile(editor.document.uri, editor.document.languageId));
} else {
void SessionState.buildAndDebugIsSourceFile.set(false);
}
}
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