Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/issues/issueTodoProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { MAX_LINE_LENGTH } from './util';
import { isComment, MAX_LINE_LENGTH } from './util';
import { CODING_AGENT, CREATE_ISSUE_TRIGGERS, ISSUES_SETTINGS_NAMESPACE, SHOW_CODE_LENS } from '../common/settingKeys';
import { escapeRegExp } from '../common/utils';
import { CopilotRemoteAgentManager } from '../github/copilotRemoteAgent';
Expand Down Expand Up @@ -114,19 +114,24 @@ export class IssueTodoProvider implements vscode.CodeActionProvider, vscode.Code

const codeLenses: vscode.CodeLens[] = [];
for (let lineNumber = 0; lineNumber < document.lineCount; lineNumber++) {
const line = document.lineAt(lineNumber).text;
const textLine = document.lineAt(lineNumber);
const { text: line, firstNonWhitespaceCharacterIndex } = textLine;
const todoInfo = this.findTodoInLine(line);
if (todoInfo) {
const { match, search, insertIndex } = todoInfo;
const range = new vscode.Range(lineNumber, search, lineNumber, search + match[0].length);
if (this.copilotRemoteAgentManager && (await this.copilotRemoteAgentManager.isAvailable())) {
const startAgentCodeLens = new vscode.CodeLens(range, {
title: vscode.l10n.t('Delegate to coding agent'),
command: 'issue.startCodingAgentFromTodo',
arguments: [{ document, lineNumber, line, insertIndex, range }],
});
codeLenses.push(startAgentCodeLens);
}
if (!todoInfo) {
continue;
}
if (!(await isComment(document, new vscode.Position(lineNumber, firstNonWhitespaceCharacterIndex)))) {
Copy link
Member Author

@joshspicer joshspicer Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't decide what is more efficient/correct to do first, the comment check or the findTodoInLine() check. @alexr00 preference?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, isComment ends up being a round trip to the renderer, so findTodoInLine is probably cheaper time-wise to do first.

continue;
}
const { match, search, insertIndex } = todoInfo;
const range = new vscode.Range(lineNumber, search, lineNumber, search + match[0].length);
if (this.copilotRemoteAgentManager && (await this.copilotRemoteAgentManager.isAvailable())) {
const startAgentCodeLens = new vscode.CodeLens(range, {
title: vscode.l10n.t('Delegate to coding agent'),
command: 'issue.startCodingAgentFromTodo',
arguments: [{ document, lineNumber, line, insertIndex, range }],
});
codeLenses.push(startAgentCodeLens);
}
}
return codeLenses;
Expand Down
29 changes: 25 additions & 4 deletions src/test/issues/issueTodoProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,31 @@ import * as vscode from 'vscode';
import { IssueTodoProvider } from '../../issues/issueTodoProvider';
import { CopilotRemoteAgentManager } from '../../github/copilotRemoteAgent';
import { CODING_AGENT, CREATE_ISSUE_TRIGGERS, ISSUES_SETTINGS_NAMESPACE, SHOW_CODE_LENS } from '../../common/settingKeys';
import * as issueUtil from '../../issues/util';

const mockCopilotManager: Partial<CopilotRemoteAgentManager> = {
isAvailable: () => Promise.resolve(true)
}

describe('IssueTodoProvider', function () {
// Mock isComment
// We don't have a real 'vscode.TextDocument' in these tests, which
// causes 'vscode.languages.getTokenInformationAtPosition' to throw.
const originalIsComment = issueUtil.isComment;
before(() => {
(issueUtil as any).isComment = async (document: vscode.TextDocument, position: vscode.Position) => {
try {
const lineText = document.lineAt(position.line).text;
return lineText.trim().startsWith('//');
} catch {
return false;
}
};
});
after(() => {
(issueUtil as any).isComment = originalIsComment;
});

it('should provide both actions when CopilotRemoteAgentManager is available', async function () {
const mockContext = {
subscriptions: []
Expand Down Expand Up @@ -119,10 +138,12 @@ describe('IssueTodoProvider', function () {

// Create a mock document with TODO comment
const document = {
lineAt: (line: number) => ({
text: line === 1 ? ' // TODO: Fix this' : 'function test() {}'
}),
lineCount: 4
lineAt: (lineNo: number) => ({
text: lineNo === 1 ? ' // TODO: Fix this' : 'function test() {}',
firstNonWhitespaceCharacterIndex: lineNo === 1 ? 2 : 0,
} as vscode.TextLine),
lineCount: 4,
languageId: 'javascript'
} as vscode.TextDocument;

const originalGetConfiguration = vscode.workspace.getConfiguration;
Expand Down