Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 30, 2025

Problem

The #openPullRequest tool was not detecting PRs where only new files were created. When a newly added file from a PR was opened as a single file (not in a diff view), the tool failed to recognize it as being associated with a PR. This prevented users from asking Copilot about the PR context when viewing these files.

Root Cause

The OpenPullRequestTool._findActivePullRequest() method only checked for TabInputTextDiff (diff editors), but when files with GitChangeType.ADD status are opened in a PR, they open as single files using TabInputText with a Schemes.Pr URI scheme, not as diffs.

Solution

Extended the PR detection logic to also check for TabInputText (single file editors) in addition to the existing TabInputTextDiff support. The fix:

  1. Added an else if branch to check for vscode.TabInputText instances
  2. Extracts PR parameters from URIs with either:
    • Schemes.Pr - PR files from GitHub (non-checkout PRs)
    • Schemes.Review - Checked out PR files
  3. Finds and returns the corresponding pull request model

Changes

  • Updated src/lm/tools/openPullRequestTool.ts:
    • Added 16 lines of new logic to handle single file editors
    • Mirrors the existing pattern used for diff editors
    • Maintains consistency with the codebase

Example Scenario

Before: User opens a newly added file newFile.ts in a PR → #openPullRequest shows "No active pull request"

After: User opens a newly added file newFile.ts in a PR → #openPullRequest correctly detects and provides context about the PR

Testing

  • ✅ Linting passed
  • ✅ Hygiene checks passed
  • ✅ Build completed successfully
  • ✅ Code follows existing patterns

Fixes the issue where PRs with only newly created files were not detected by the #openPullRequest tool.

Original prompt

This section details on the original issue you should resolve

<issue_title>Want #openPullRequest to consider PRs where only new files created</issue_title>
<issue_description>

After verifying #7737, I found another variant I'd love to be supported: explaining PRs where the diffs are just newly created files.

I have quite a few PRs in my repo where only new files were added. I'd still love to be able to ask about #openPullRequest if I have a newly added file open.

Image

Image</issue_description>

<agent_instructions>The problem here is for files, we only detect PR related files when a diff is open. We should also detect that the file is associated with a PR when a PR file scheme file is open, even if not a diff.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #7889

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits September 30, 2025 08:20
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
The OpenPullRequestTool now also detects PR-associated files when a single file with PR scheme is open, not just when a diff is open. This allows users to ask about #openPullRequest when they have newly added files open in a PR.

Added support for:
- TabInputText with Schemes.Pr (PR files from GitHub)
- TabInputText with Schemes.Review (checked out PR files)

This fixes the issue where PRs with only newly created files were not detected.

Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot AI changed the title [WIP] Want #openPullRequest to consider PRs where only new files created Fix: Detect PR files in #openPullRequest when single file is open Sep 30, 2025
@alexr00 alexr00 marked this pull request as ready for review September 30, 2025 09:48
@alexr00 alexr00 enabled auto-merge (squash) September 30, 2025 09:48
@vs-code-engineering vs-code-engineering bot added this to the September 2025 milestone Sep 30, 2025
@alexr00 alexr00 merged commit 5978bda into main Sep 30, 2025
6 checks passed
@alexr00 alexr00 deleted the copilot/fix-25b745f2-4841-4a2f-974f-05788c8394d6 branch September 30, 2025 10:00
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.

Want #openPullRequest to consider PRs where only new files created

3 participants