@@ -10,7 +10,7 @@ import { escapeRegExp } from '../common/utils';
1010import { CopilotRemoteAgentManager } from '../github/copilotRemoteAgent' ;
1111import { ISSUE_OR_URL_EXPRESSION } from '../github/utils' ;
1212
13- export class IssueTodoProvider implements vscode . CodeActionProvider {
13+ export class IssueTodoProvider implements vscode . CodeActionProvider , vscode . CodeLensProvider {
1414 private expression : RegExp | undefined ;
1515
1616 constructor (
@@ -87,4 +87,50 @@ export class IssueTodoProvider implements vscode.CodeActionProvider {
8787 } while ( range . end . line >= lineNumber ) ;
8888 return codeActions ;
8989 }
90+
91+ provideCodeLenses (
92+ document : vscode . TextDocument ,
93+ _token : vscode . CancellationToken ,
94+ ) : vscode . CodeLens [ ] {
95+ if ( this . expression === undefined ) {
96+ return [ ] ;
97+ }
98+
99+ const codeLenses : vscode . CodeLens [ ] = [ ] ;
100+ for ( let lineNumber = 0 ; lineNumber < document . lineCount ; lineNumber ++ ) {
101+ const line = document . lineAt ( lineNumber ) . text ;
102+ const truncatedLine = line . substring ( 0 , MAX_LINE_LENGTH ) ;
103+ const matches = truncatedLine . match ( ISSUE_OR_URL_EXPRESSION ) ;
104+ if ( ! matches ) {
105+ const match = truncatedLine . match ( this . expression ) ;
106+ const search = match ?. index ?? - 1 ;
107+ if ( search >= 0 && match ) {
108+ const range = new vscode . Range ( lineNumber , search , lineNumber , search + match [ 0 ] . length ) ;
109+ const indexOfWhiteSpace = truncatedLine . substring ( search ) . search ( / \s / ) ;
110+ const insertIndex =
111+ search +
112+ ( indexOfWhiteSpace > 0 ? indexOfWhiteSpace : truncatedLine . match ( this . expression ) ! [ 0 ] . length ) ;
113+
114+ // Create GitHub Issue CodeLens
115+ const createIssueCodeLens = new vscode . CodeLens ( range , {
116+ title : vscode . l10n . t ( 'Create GitHub Issue' ) ,
117+ command : 'issue.createIssueFromSelection' ,
118+ arguments : [ { document, lineNumber, line, insertIndex, range } ] ,
119+ } ) ;
120+ codeLenses . push ( createIssueCodeLens ) ;
121+
122+ // Delegate to coding agent CodeLens (if copilot manager is available)
123+ if ( this . copilotRemoteAgentManager ) {
124+ const startAgentCodeLens = new vscode . CodeLens ( range , {
125+ title : vscode . l10n . t ( 'Delegate to coding agent' ) ,
126+ command : 'issue.startCodingAgentFromTodo' ,
127+ arguments : [ { document, lineNumber, line, insertIndex, range } ] ,
128+ } ) ;
129+ codeLenses . push ( startAgentCodeLens ) ;
130+ }
131+ }
132+ }
133+ }
134+ return codeLenses ;
135+ }
90136}
0 commit comments