22// Licensed under the MIT license.
33
44import { commands , Uri , CancellationToken } from "vscode" ;
5- import { sendError , sendInfo } from "vscode-extension-telemetry-wrapper" ;
6- import { GetImportClassContentError , GetProjectDependenciesError , sendContextOperationTelemetry , JavaContextProviderUtils } from "./utils" ;
5+ import { sendError } from "vscode-extension-telemetry-wrapper" ;
6+ import { GetImportClassContentError , GetProjectDependenciesError , JavaContextProviderUtils } from "./utils" ;
77import { Commands } from '../commands' ;
88
99/**
@@ -259,27 +259,35 @@ export namespace CopilotHelper {
259259 }
260260 }
261261
262+ /**
263+ * Result interface for dependency resolution with diagnostic information
264+ */
265+ export interface IResolveResult {
266+ items : any [ ] ;
267+ emptyReason ?: string ;
268+ itemCount : number ;
269+ }
270+
262271 /**
263272 * Resolves project dependencies and converts them to context items with cancellation support
264- * @param workspaceFolders The workspace folders , or undefined if none
273+ * @param activeEditor The active text editor , or undefined if none
265274 * @param copilotCancel Cancellation token from Copilot
266275 * @param checkCancellation Function to check for cancellation
267- * @returns Array of context items for project dependencies, or empty array if no workspace folders
276+ * @returns Result object containing context items and diagnostic information
268277 */
269278 export async function resolveAndConvertProjectDependencies (
270279 activeEditor : { document : { uri : Uri ; languageId : string } } | undefined ,
271280 copilotCancel : CancellationToken ,
272281 checkCancellation : ( token : CancellationToken ) => void
273- ) : Promise < { name : string ; value : string ; importance : number } [ ] > {
282+ ) : Promise < IResolveResult > {
274283 const items : any [ ] = [ ] ;
284+
275285 // Check if workspace folders exist
276286 if ( ! activeEditor ) {
277- sendContextOperationTelemetry ( "resolveLocalImports" , "ContextEmpty" , sendInfo , EmptyReason . NoActiveEditor ) ;
278- return items ;
287+ return { items : [ ] , emptyReason : EmptyReason . NoActiveEditor , itemCount : 0 } ;
279288 }
280289 if ( activeEditor . document . languageId !== 'java' ) {
281- sendContextOperationTelemetry ( "resolveLocalImports" , "ContextEmpty" , sendInfo , EmptyReason . NotJavaFile ) ;
282- return items ;
290+ return { items : [ ] , emptyReason : EmptyReason . NotJavaFile , itemCount : 0 } ;
283291 }
284292 const documentUri = activeEditor . document . uri ;
285293
@@ -289,9 +297,9 @@ export namespace CopilotHelper {
289297 // Check for cancellation after dependency resolution
290298 checkCancellation ( copilotCancel ) ;
291299
292- // Send telemetry if result is empty
300+ // Return empty result with reason if no dependencies found
293301 if ( projectDependenciesResult . isEmpty && projectDependenciesResult . emptyReason ) {
294- sendContextOperationTelemetry ( "resolveProjectDependencies" , "ContextEmpty" , sendInfo , projectDependenciesResult . emptyReason ) ;
302+ return { items : [ ] , emptyReason : projectDependenciesResult . emptyReason , itemCount : 0 } ;
295303 }
296304
297305 // Check for cancellation after telemetry
@@ -306,31 +314,29 @@ export namespace CopilotHelper {
306314 items . push ( ...contextItems ) ;
307315 }
308316
309- return items ;
317+ return { items, itemCount : items . length } ;
310318 }
311319
312320 /**
313321 * Resolves local imports and converts them to context items with cancellation support
314322 * @param activeEditor The active text editor, or undefined if none
315323 * @param copilotCancel Cancellation token from Copilot
316324 * @param checkCancellation Function to check for cancellation
317- * @param createContextItems Function to create context items from imports
318- * @returns Array of context items for local imports, or empty array if no valid editor
325+ * @returns Result object containing context items and diagnostic information
319326 */
320327 export async function resolveAndConvertLocalImports (
321328 activeEditor : { document : { uri : Uri ; languageId : string } } | undefined ,
322329 copilotCancel : CancellationToken ,
323330 checkCancellation : ( token : CancellationToken ) => void
324- ) : Promise < any [ ] > {
331+ ) : Promise < IResolveResult > {
325332 const items : any [ ] = [ ] ;
333+
326334 // Check if there's an active editor with a Java document
327335 if ( ! activeEditor ) {
328- sendContextOperationTelemetry ( "resolveLocalImports" , "ContextEmpty" , sendInfo , EmptyReason . NoActiveEditor ) ;
329- return items ;
336+ return { items : [ ] , emptyReason : EmptyReason . NoActiveEditor , itemCount : 0 } ;
330337 }
331338 if ( activeEditor . document . languageId !== 'java' ) {
332- sendContextOperationTelemetry ( "resolveLocalImports" , "ContextEmpty" , sendInfo , EmptyReason . NotJavaFile ) ;
333- return items ;
339+ return { items : [ ] , emptyReason : EmptyReason . NotJavaFile , itemCount : 0 } ;
334340 }
335341
336342 const documentUri = activeEditor . document . uri ;
@@ -343,10 +349,11 @@ export namespace CopilotHelper {
343349 // Check for cancellation after resolution
344350 checkCancellation ( copilotCancel ) ;
345351
346- // Send telemetry if result is empty
352+ // Return empty result with reason if no imports found
347353 if ( importClassResult . isEmpty && importClassResult . emptyReason ) {
348- sendContextOperationTelemetry ( "resolveLocalImports" , "ContextEmpty" , sendInfo , importClassResult . emptyReason ) ;
354+ return { items : [ ] , emptyReason : importClassResult . emptyReason , itemCount : 0 } ;
349355 }
356+
350357 // Check for cancellation before processing results
351358 checkCancellation ( copilotCancel ) ;
352359 if ( importClassResult . classInfoList && importClassResult . classInfoList . length > 0 ) {
@@ -357,6 +364,6 @@ export namespace CopilotHelper {
357364 items . push ( ...contextItems ) ;
358365 }
359366
360- return items ;
367+ return { items, itemCount : items . length } ;
361368 }
362369}
0 commit comments