Skip to content

Fix bug where workspace tasks cannot be run#4705

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-workspace-task-issue
Draft

Fix bug where workspace tasks cannot be run#4705
Copilot wants to merge 2 commits intomainfrom
copilot/fix-workspace-task-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 9, 2026

This change addresses item #4529

This changes visible behavior

The following changes are proposed:

  • Extract workspace folder resolution into a shared getWorkspaceFolderFromTask() static helper method in CMakeTaskProvider
  • The helper properly checks if task.scope is a WorkspaceFolder object (via typeof check) before using it
  • When the scope is not a WorkspaceFolder (e.g., TaskScope.Workspace for tasks defined in .code-workspace files), falls back to the active project's workspace folder, then to the first available workspace folder
  • Update both resolveTask and resolveInternalTask to use the new helper
  • Add CHANGELOG entry under 1.23 Bug Fixes

The purpose of this change

When a CMake task is defined in a .code-workspace file, VS Code sets task.scope to TaskScope.Workspace (the number 2), not a WorkspaceFolder object. The previous code blindly cast task.scope to WorkspaceFolder, which meant that workspaceFolder.uri was undefined, causing a crash with TypeError: Cannot read properties of undefined (reading 'path') in CustomBuildTaskTerminal.getProject(). This left the task stuck in a "Task is running" state.

The fix ensures that when task.scope is not a WorkspaceFolder object, the extension gracefully resolves the workspace folder from the active project or the first available workspace folder, allowing tasks defined in .code-workspace files to run correctly.

Other Notes/Information

Repro steps:

  1. Create a .code-workspace file with a CMake task definition (type: "cmake")
  2. Open the workspace in VS Code
  3. Run the task via "Tasks: Run Task" → "cmake" → task label
  4. Observe the task gets stuck with the TypeError in the ExtensionHost output

Tasks defined in tasks.json were unaffected because VS Code provides a proper WorkspaceFolder object as the task scope in that case.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug] Task defined inside workspace file can not be run, it is stuck in "Task is running" state.</issue_title>
<issue_description>### Brief Issue Summary

If the task is defined in workspace file, it is stuck with error:

[error] TypeError: Cannot read properties of undefined (reading 'path')
	at CustomBuildTaskTerminal.getProject (<home>\.vscode\extensions\ms-vscode.cmake-tools-1.21.36\dist\main.js:87896:80)

Seems the problem with workspaceFolder.uri. The task example:
<...>.code-workspace:

{
  "launch": {
    "version": "0.2.0",
    "configurations": [
     <...>
    ],
  },
  "tasks": {
    "version": "2.0.0",
    "tasks": [
      {
        "type": "cmake",
        "label": "Prelaunch Build",
        "command": "build",
        "targets": [
          "all"
        ],
      }
    ]
  },
  "folders": [
    {
      "path": "."
    }
  ],
}

If the task is replaced into tasks.json, the workspace folder is recognized and everything works correctly

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.95.3",
  "cmtVersion": "1.22.2",
  "configurations": [
    {
      "folder": "<>",
      "cmakeVersion": "3.26.4",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": false,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 1,
    "executablesCount": 1,
    "librariesCount": 0,
    "targets": [
      {
        "name": "main",
        "type": "EXECUTABLE"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": true
    }
  ]
}

Debug Log

ExtensionHost window (output window is empty):
[error] TypeError: Cannot read properties of undefined (reading 'path')
	at CustomBuildTaskTerminal.getProject (<>\.vscode\extensions\ms-vscode.cmake-tools-1.22.2\dist\main.js:87966:80)
	at CustomBuildTaskTerminal.runBuildTask (<>\.vscode\extensions\ms-vscode.cmake-tools-1.22.2\dist\main.js:88014:34)
	at CustomBuildTaskTerminal.open (<>\.vscode\extensions\ms-vscode.cmake-tools-1.22.2\dist\main.js:87876:28)
	at X0.startSendingEvents (file:///<>/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:114:40456)
	at Jw.S (file:///<>/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:114:44872)
	at Jw.attachPtyToTerminal (file:///<>/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:114:42916)
	at Qw.$onDidStartTask (file:///<>/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:121:52658)

Additional Information

No response</issue_description>

<agent_instructions>You are Copilot coding agent acting as a senior maintainer/contributor for the VS Code extension repository microsoft/vscode-cmake-tools.
You are deeply familiar with CMake, CMake Presets, CTest, kit/toolchain selection, VS Code extension APIs, and the architecture of this repo (TypeScript-heavy).
Your job is to resolve the GitHub issue provided below safely and in a maintainable way, matching existing patterns and UX.

SOURCE OF TRUTH

NON-NEGOTIABLE PROCESS

  1. Triage & understanding (issue-first)
  • Read the entire issue thread.
  • Extract and write down:
    • expected behavior
    • actual behavior
    • repro steps (or minimal repro you infer)
    • affected OS/toolchains/generators/presets
    • whether it is a regression and from which version/commit (if indicated)
  • Identify which CMake Tools feature area is involved (configure/build/test/debug, presets, kits, status bar, tasks, command palette, IntelliSense).
  1. Orient yourself in the repo (implementation map)
  • Identify the relevant user-facing workflows impacted (configure/build/test/debug, presets, kits, status bar, tasks, command palette).
  • Locate the existing implementation areas (commands, configuration/presets handling, test integration, UI, telemetry/logging).
  • Identify existing tests and how they are run in CI; prefer extending existing suites over inventing a new harness.
  1. Changelog discipline (required)
  • Find the project’s changelog / release notes mechanism (e.g., CHANGELOG.md, docs/changelog, “Unreleased” section, or a dedicated changes/ folder).
  • Add exactly ONE appropriate entr...

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@hanniavalera
Copy link
Contributor

@copilot try again

@hanniavalera
Copy link
Contributor

@copilot try again

Copy link
Contributor Author

Copilot AI commented Feb 9, 2026

@copilot try again

Fixed in 65a606d. The issue was that when a cmake task is defined in a .code-workspace file, task.scope is TaskScope.Workspace (a number), not a WorkspaceFolder object. The code was either blindly casting it or leaving workspaceFolder as undefined.

The fix extracts workspace folder resolution into a getWorkspaceFolderFromTask() helper that:

  1. Uses task.scope directly if it's a WorkspaceFolder object
  2. Falls back to the active project's workspace folder
  3. Falls back to the first available workspace folder

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0psvsblobprodwus2145.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/_temp/ghcca-node/node/bin/npm install (dns block)
  • 2wrvsblobprodwus2180.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
  • 40vvsblobprodwus2135.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/_temp/ghcca-node/node/bin/npm install (dns block)
  • 5bdvsblobprodwus2128.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/_temp/ghcca-node/node/bin/npm install (dns block)
  • b15vsblobprodwus2164.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
  • b53vsblobprodwus2154.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
  • d94vsblobprodwus2119.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
  • ezcvsblobprodwus2170.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/_temp/ghcca-node/node/bin/npm install (dns block)
  • k4pvsblobprodwus2140.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/_temp/ghcca-node/node/bin/npm install (dns block)
  • n6wvsblobprodwus2123.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
  • p2tvsblobprodwus2189.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
  • v41vsblobprodwus2175.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix bug where workspace tasks cannot be run Fix bug where workspace tasks cannot be run Feb 9, 2026
Copilot AI and others added 2 commits February 9, 2026 11:39
When a cmake task is defined in a .code-workspace file, task.scope is
TaskScope.Workspace (a number), not a WorkspaceFolder object. The previous
code blindly cast task.scope to WorkspaceFolder, causing a crash when
accessing workspaceFolder.uri.path.

Extract workspace folder resolution into a shared helper method that:
1. Uses the task scope directly if it's a WorkspaceFolder object
2. Falls back to the active project's workspace folder
3. Falls back to the first available workspace folder

Fixes #4529

Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
@hanniavalera hanniavalera force-pushed the copilot/fix-workspace-task-issue branch from f5b3918 to 076a55b Compare February 9, 2026 17:39
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.

[Bug] Task defined inside workspace file can not be run, it is stuck in "Task is running" state.

2 participants