Skip to content

Fix permalinks on the same line merging in review comments - #9240

Draft
Federico Brancasi (federicobrancasi) wants to merge 3 commits into
mainfrom
fbrancasi/permalinks-on-one-line
Draft

Federico Brancasi (federicobrancasi) wants to merge 3 commits into
mainfrom
fbrancasi/permalinks-on-one-line

Conversation

@federicobrancasi

Copy link
Copy Markdown
Member

When a review comment has two code permalinks to the repository on the same line, the comment widget in the editor shows only one code snippet and drops the rest of the line. For example, Compare https://github.com/owner/repo/blob/<sha>/src/a.ts#L1 and https://github.com/owner/repo/blob/<sha>/src/b.ts#L2-L3 is shown as a single snippet of src/b.ts: the src/a.ts link and the word "and" are gone, and the src/b.ts link points to the whole text from the first URL to the second one. Why: GHPRComment.replacePermalink matches the owner with (.+) and the file path with (.*). Both are greedy, so one match runs from the first https://github.com/ to the last #L on the line.

This PR limits the owner to one path segment ([^/\s]+) and the file path to the text before the # ([^#\s]+), so each permalink is matched and expanded on its own.

How to test

Command Result
npm run compile:test, then the repo's extension test runner (out/src/test/index.js through @vscode/test-electron runTests, with a local VS Code Insiders 1.148.0 instead of the download in out/src/test/runTests.js) 1430 passing; the new test "permalink replacement expands each permalink when there are several on one line" fails without the change
npx eslint src/github/prComment.ts, npx tsc --noEmit -p tsconfig.json, node ./build/hygiene.js src/github/prComment.ts src/test/github/prComment.test.ts, npm run compile pass

When a review comment has two code permalinks to the repository on the same line, the comment widget in the editor shows only one code snippet and drops the rest of the line. For example, `Compare https://github.com/owner/repo/blob/<sha>/src/a.ts#L1 and https://github.com/owner/repo/blob/<sha>/src/b.ts#L2-L3` is shown as a single snippet of `src/b.ts`: the `src/a.ts` link and the word "and" are gone, and the `src/b.ts` link points to the whole text from the first URL to the second one. Why: `GHPRComment.replacePermalink` matches the owner with `(.+)` and the file path with `(.*)`. Both are greedy, so one match runs from the first `https://github.com/` to the last `#L` on the line.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

Fixes greedy permalink matching so multiple GitHub permalinks on the same line are expanded independently in review comments.

Changes:

  • Tighten the permalink regex to avoid greedy owner/path matching across multiple URLs.
  • Add a regression test covering multiple permalinks on one line.
File Description
src/​github/​prComment.ts Updates permalink-matching regex to prevent multi-URL overmatching.
src/​test/​github/​prComment.test.ts Adds a regression test for expanding multiple permalinks on one line.

Review effort: Lite

Comment on lines +116 to +120
const githubRepository = {
remote: { host: 'github.com', owner: 'owner', repositoryName: 'repo' },
rootUri: vscode.Uri.file('/nonexistent-permalink-root'),
getLines: async (_sha: string, file: string) => `contents of ${file}`,
} as unknown as GitHubRepository;
Comment thread src/test/github/prComment.test.ts Resolved
user: { login: 'reviewer', id: '1', url: 'https://github.com/reviewer', accountType: AccountType.User },
}, thread, [githubRepository]);

const replaced: string = await (comment as any).replacePermalink(`Compare ${first} and ${second}`);
Compare the full replaced body, so the test also fails when the text around the permalinks is lost or when two permalinks end up in one expansion.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

The test’s mock extension URI can cause an unhandled emoji-cache loading rejection and cache the failure, affecting later tests; it should use the real extension URI before constructing GHPRComment.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Set mock extension URI before constructing GHPRComment

src/​test/​github/​prComment.test.ts:123

If this test runs before the emoji cache is initialized, constructing GHPRComment tries to load resources/emojis.json relative to the mock context's test-directory URI, causing an unhandled rejection. The failed load also stays cached and can affect later tests. Set the mock's extensionUri to the real extension URI before constructing the comment, following src/test/github/issueOverview.test.ts:72.

1 resolved since last review

Review effort: Balanced

`GHPRComment` loads the emojis relative to the context's extension URI, and the mock context points to the test folder, which has no `resources/emojis.json`. Run on its own, the test left an unhandled rejection and a cached failed load for later tests. Set the real extension URI, as the issue overview tests do.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

One or more custom setup steps configured for this repository failed during this Copilot code review run:

Install dependencies

Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review.

Note

You can configure setup steps for Copilot code review separately from Copilot cloud agent with a copilot-code-review.yml file. Read the docs for details.

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.

🟢 Approval recommended

There are no active review issues for the change to render multiple permalinks independently while preserving surrounding text.

2 open issues

Review effort: Balanced

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.

2 participants