From 5a877dc44936e294c64d1a437298963712a8d50b Mon Sep 17 00:00:00 2001 From: Federico Brancasi Date: Sun, 29 Nov 2026 21:17:29 +0100 Subject: [PATCH 1/2] Only filter issue completions by an owner/repo written right before # When you type `#` in the commit message box, a plaintext or markdown file, or a code comment, issue suggestions disappear if any word with a `/` appears earlier on the same line. For example, in the commit message `Fix crash in src/extension.ts, closes #` the list shows only "Configure issue queries..." instead of your issues. The same happens after a URL (`// See https://example.com/docs for details, tracked in #`), "and/or", or a date like `11/29`. Why: the owner/repo filter added in #5262 (for `owner/repo#`) runs `/([^\s]+)\/([^\s]+)/` on all the text from the start of the line to the `#`. It is not anchored to the `#`, so it finds `src/extension.ts,`, filters to owner `src` and repo `extension.ts,`, and no issue matches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/issues/issueCompletionProvider.ts | 2 +- .../issues/issueCompletionProvider.test.ts | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/test/issues/issueCompletionProvider.test.ts diff --git a/src/issues/issueCompletionProvider.ts b/src/issues/issueCompletionProvider.ts index d2ccdcaaf7..47e70000ee 100644 --- a/src/issues/issueCompletionProvider.ts +++ b/src/issues/issueCompletionProvider.ts @@ -123,7 +123,7 @@ export class IssueCompletionProvider implements vscode.CompletionItemProvider { wordRange.start ); const ownerRepo = document.getText(ownerRepoRange); - const ownerRepoMatch = ownerRepo.match(/([^\s]+)\/([^\s]+)/); + const ownerRepoMatch = ownerRepo.match(/([A-Za-z0-9_.\-]+)\/([A-Za-z0-9_.\-]+)$/); if (ownerRepoMatch) { filterOwnerAndRepo = { owner: ownerRepoMatch[1], diff --git a/src/test/issues/issueCompletionProvider.test.ts b/src/test/issues/issueCompletionProvider.test.ts new file mode 100644 index 0000000000..a675a70720 --- /dev/null +++ b/src/test/issues/issueCompletionProvider.test.ts @@ -0,0 +1,56 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { default as assert } from 'assert'; +import * as vscode from 'vscode'; +import { IssueCompletionProvider } from '../../issues/issueCompletionProvider'; +import { StateManager } from '../../issues/stateManager'; +import { IssueModel } from '../../github/issueModel'; +import { RepositoriesManager } from '../../github/repositoriesManager'; +import { MockExtensionContext } from '../mocks/mockExtensionContext'; + +describe('IssueCompletionProvider', function () { + // The first completion request in the test run can take more than the default 2 seconds + this.timeout(10000); + + function createIssue(owner: string, repositoryName: string, number: number): IssueModel { + return { + number, + title: `Issue ${number}`, + body: '', + html_url: `https://github.com/${owner}/${repositoryName}/issues/${number}`, + remote: { owner, repositoryName }, + milestone: undefined, + item: {}, + } as unknown as IssueModel; + } + + async function getCompletionLabels(line: string): Promise { + const issues = [createIssue('microsoft', 'vscode', 1), createIssue('octocat', 'hello-world', 2)]; + const stateManager = { + getIssueCollection: () => new Map([['query', Promise.resolve({ groupBy: [], issues })]]), + } as unknown as StateManager; + const repositoriesManager = { + getManagerForFile: () => undefined, + } as unknown as RepositoriesManager; + const provider = new IssueCompletionProvider(stateManager, repositoriesManager, new MockExtensionContext()); + const document = await vscode.workspace.openTextDocument({ content: line, language: 'plaintext' }); + const items = await provider.provideCompletionItems( + document, + new vscode.Position(0, line.length), + new vscode.CancellationTokenSource().token, + { triggerKind: vscode.CompletionTriggerKind.TriggerCharacter, triggerCharacter: '#' }, + ); + return items.map(item => typeof item.label === 'string' ? item.label : item.label.label); + } + + it('filters to the repository written directly before the #', async function () { + assert.deepStrictEqual(await getCompletionLabels('See octocat/hello-world#'), ['2: Issue 2']); + }); + + it('does not filter by a path that appears earlier on the line', async function () { + assert.deepStrictEqual(await getCompletionLabels('Fix crash in src/extension.ts, closes #'), ['1: Issue 1', '2: Issue 2']); + }); +}); From ac893872f26cd63d7c78c29d08fb124ac5f055e0 Mon Sep 17 00:00:00 2001 From: Federico Brancasi Date: Sun, 29 Nov 2026 21:35:44 +0100 Subject: [PATCH 2/2] Dispose the cancellation token source in the issue completion test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../issues/issueCompletionProvider.test.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/test/issues/issueCompletionProvider.test.ts b/src/test/issues/issueCompletionProvider.test.ts index a675a70720..4fdda1a4a1 100644 --- a/src/test/issues/issueCompletionProvider.test.ts +++ b/src/test/issues/issueCompletionProvider.test.ts @@ -37,13 +37,18 @@ describe('IssueCompletionProvider', function () { } as unknown as RepositoriesManager; const provider = new IssueCompletionProvider(stateManager, repositoriesManager, new MockExtensionContext()); const document = await vscode.workspace.openTextDocument({ content: line, language: 'plaintext' }); - const items = await provider.provideCompletionItems( - document, - new vscode.Position(0, line.length), - new vscode.CancellationTokenSource().token, - { triggerKind: vscode.CompletionTriggerKind.TriggerCharacter, triggerCharacter: '#' }, - ); - return items.map(item => typeof item.label === 'string' ? item.label : item.label.label); + const cts = new vscode.CancellationTokenSource(); + try { + const items = await provider.provideCompletionItems( + document, + new vscode.Position(0, line.length), + cts.token, + { triggerKind: vscode.CompletionTriggerKind.TriggerCharacter, triggerCharacter: '#' }, + ); + return items.map(item => typeof item.label === 'string' ? item.label : item.label.label); + } finally { + cts.dispose(); + } } it('filters to the repository written directly before the #', async function () {