Skip to content

Implement multi-root CodeQL query resolution with workspace support#308

Open
data-douser wants to merge 6 commits into
mainfrom
dd/extension-ql-resolution-improvements/1
Open

Implement multi-root CodeQL query resolution with workspace support#308
data-douser wants to merge 6 commits into
mainfrom
dd/extension-ql-resolution-improvements/1

Conversation

@data-douser

@data-douser data-douser commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

This pull request:

Summary of Changes

This pull request introduces significant improvements to how the VS Code extension for CodeQL MCP resolves query and pack paths, especially in multi-root workspaces. It adds new settings to give users explicit control over which directories are scanned, makes the extension aware of CodeQL workspaces by default, and ensures that queries in any workspace folder can be found and used regardless of folder order. It also improves test isolation and updates documentation to reflect these changes.

Multi-root workspace and resolution improvements:

  • Added three new settings to package.json and documented them in README.md: codeql-mcp.queryPackIncludeDirs (explicitly include directories for query/pack resolution), codeql-mcp.queryPackExcludeDirs (exclude certain directories from resolution), and codeql-mcp.requireCodeqlWorkspace (use only folders with a top-level codeql-workspace.yml by default). These settings are folded into the environment variables passed to the MCP server. [1] [2]
  • The extension now, by default, only treats workspace folders containing a top-level codeql-workspace.yml as CodeQL query/pack resolution roots, matching the CodeQL CLI's workspace model. The previous behavior (using every open folder) is still available via settings or fallback. [1] [2]
  • Fixed a bug where workflow prompts could only target queries in the first workspace folder; now, all roots are scanned independently, and the new settings ensure queries in any folder (or outside the workspace) are discoverable.
  • Implemented the resolution logic in environment-builder.ts with helper functions for workspace file detection, path resolution, and exclusion, making the codebase more robust and testable. [1] [2]

Testing and infrastructure:

  • Test infrastructure was updated so that multi-root workspace tests copy the fixture workspace into a temporary directory before running, ensuring that test runs do not dirty the working tree. Additional integration tests were added for the new resolution logic. [1] [2] [3]

These changes provide more predictable, user-configurable, and CodeQL-native behavior for resolving queries and packs in complex workspace setups.

Copilot AI and others added 3 commits June 24, 2026 16:00
Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Make the VS Code extension select CodeQL query/pack resolution roots
from workspace folders that contain a top-level codeql-workspace.yml,
and give the MCP server's completion providers an independent per-root
scan budget so non-first folders are never starved.

Extension:
- Add codeql-mcp.requireCodeqlWorkspace (default true); only folders
  with a top-level codeql-workspace.yml become resolution roots.
- queryPackIncludeDirs remains the explicit opt-in; fall back to all
  folders with a warning when none qualify and no include dirs are set.
- Export computeResolutionRoots/hasTopLevelCodeqlWorkspaceFile.

Server:
- Give each workspace root (and base dir) its own completion scan
  budget so a populous first root no longer hides later roots.

Tests/docs:
- Add codeql-workspace-resolution and multi-root completion integration
  suites, unit tests, and codeql-workspace.yml fixtures.
- Update README and CHANGELOG.
@data-douser data-douser self-assigned this Jun 25, 2026
Copilot AI review requested due to automatic review settings June 25, 2026 03:47
@data-douser data-douser added bug Something isn't working enhancement New feature or request labels Jun 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

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

This PR (#308) fixes multi-root workspace resolution for CodeQL MCP prompt-driven workflows by making both the VS Code extension and the MCP server’s prompt completion providers “multi-root aware”, with explicit include/exclude controls and a default CodeQL-workspace-based root selection model.

Changes:

  • Extend server-side prompt completions to scan all workspace roots (CODEQL_MCP_WORKSPACE_FOLDERS) with a per-root scan budget to avoid “first root starvation”.
  • Add VS Code extension settings (queryPackIncludeDirs, queryPackExcludeDirs, requireCodeqlWorkspace) and implement CodeQL-workspace-aware root selection in the environment builder.
  • Add/expand unit + integration tests, update extension README, and add changelog entries.
Show a summary per file
File Description
server/test/src/prompts/prompt-completions.test.ts Adds server-side unit tests asserting completions span multiple workspace roots and that later roots aren’t starved.
server/src/utils/package-paths.ts Clarifies multi-root workspace dir resolution documentation (uses CODEQL_MCP_WORKSPACE_FOLDERS).
server/src/prompts/workflow-prompts.ts Minor doc/comment updates related to multi-root path resolution.
server/src/prompts/prompt-completions.ts Implements multi-root scanning and per-root budgets for query/sarif/db/pack completions.
server/dist/codeql-development-mcp-server.js Updates the bundled server build output to reflect TypeScript changes.
extensions/vscode/src/bridge/environment-builder.ts Computes effective resolution roots using new settings + codeql-workspace.yml detection and exports them via env vars.
extensions/vscode/package.json Adds settings definitions/descriptions for include/exclude and CodeQL workspace requirement.
extensions/vscode/README.md Documents multi-root behavior, new settings, and recommended codeql-workspace.yml usage.
extensions/vscode/test/bridge/environment-builder.test.ts Adds unit tests for root computation logic, include/exclude behavior, and fallback warning.
extensions/vscode/test/suite/workspace-scenario.integration.test.ts Adds integration coverage for CODEQL_MCP_WORKSPACE_FOLDERS and include/exclude effects.
extensions/vscode/test/suite/workspace-folder-change.integration.test.ts Adjusts workspace-folder change tests to align with the default CodeQL-workspace requirement.
extensions/vscode/test/suite/mcp-completion-multiroot.integration.test.ts New end-to-end test spawning the server with synthetic multi-root env to validate completions + prompt resolution.
extensions/vscode/test/suite/codeql-workspace-resolution.integration.test.ts New integration tests for default CodeQL-workspace-aware root selection and opt-in/out settings.
extensions/vscode/test/fixtures/single-folder-workspace/codeql-workspace.yml Adds fixture CodeQL workspace marker file.
extensions/vscode/test/fixtures/multi-root-workspace/folder-a/codeql-workspace.yml Adds fixture CodeQL workspace marker file.
extensions/vscode/test/fixtures/multi-root-workspace/folder-b/codeql-workspace.yml Adds fixture CodeQL workspace marker file.
extensions/vscode/test/fixtures/multi-root-workspace/folder-c/codeql-workspace.yml Adds fixture CodeQL workspace marker file.
extensions/vscode/test/fixtures/multi-root-workspace/folder-d/codeql-workspace.yml Adds fixture CodeQL workspace marker file.
extensions/vscode/esbuild.config.js Registers new extension integration test entrypoints in the test bundle config.
CHANGELOG.md Adds Unreleased entries describing the new settings, default behavior changes, and the multi-root prompt fix.

Copilot's findings

  • Files reviewed: 19/21 changed files
  • Comments generated: 8

Comment thread server/src/prompts/prompt-completions.ts
Comment thread server/src/prompts/prompt-completions.ts
Comment thread server/src/prompts/prompt-completions.ts
Comment thread server/src/prompts/prompt-completions.ts
Comment thread extensions/vscode/src/bridge/environment-builder.ts Outdated
Comment thread CHANGELOG.md Outdated
Comment thread CHANGELOG.md Outdated
Comment thread CHANGELOG.md Outdated
Copilot AI review requested due to automatic review settings June 25, 2026 18:20

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.

Copilot's findings

  • Files reviewed: 20/22 changed files
  • Comments generated: 3

Comment thread extensions/vscode/src/bridge/environment-builder.ts Outdated
Comment thread extensions/vscode/src/bridge/environment-builder.ts Outdated
Comment thread extensions/vscode/.vscode-test.mjs Outdated
Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
@data-douser data-douser marked this pull request as ready for review June 26, 2026 01:40
Copilot AI review requested due to automatic review settings June 26, 2026 01:40
@data-douser data-douser requested review from a team and enyil as code owners June 26, 2026 01:40

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.

Review details

  • Files reviewed: 20/22 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment on lines +389 to 394
}
aggregated.push(...perRoot);
}

allResults = results;
allResults = [...new Set(aggregated)];
setCachedResults(cacheKey, allResults);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VS Code extension: MCP workflow prompts cannot target queries outside the first workspace folder

3 participants