@@ -44,7 +44,7 @@ export interface IProjectDependency {
4444}
4545
4646export interface IProjectDependenciesResult {
47- dependencyInfoList : Array < { key : string ; value : string } > ;
47+ dependencyInfoList : { key : string ; value : string } [ ] ;
4848 emptyReason ?: string ;
4949 isEmpty : boolean ;
5050}
@@ -80,9 +80,11 @@ export namespace CopilotHelper {
8080
8181 try {
8282 const normalizedUri = decodeURIComponent ( Uri . file ( fileUri . fsPath ) . toString ( ) ) ;
83-
84- const commandPromise = commands . executeCommand ( Commands . EXECUTE_WORKSPACE_COMMAND , Commands . JAVA_PROJECT_GET_IMPORT_CLASS_CONTENT , normalizedUri ) as Promise < IImportClassContentResult > ;
85-
83+ const commandPromise = commands . executeCommand (
84+ Commands . EXECUTE_WORKSPACE_COMMAND ,
85+ Commands . JAVA_PROJECT_GET_IMPORT_CLASS_CONTENT ,
86+ normalizedUri
87+ ) as Promise < IImportClassContentResult > ;
8688 if ( cancellationToken ) {
8789 const result = await Promise . race ( [
8890 commandPromise ,
@@ -97,15 +99,13 @@ export namespace CopilotHelper {
9799 } , 80 ) ; // 80ms timeout
98100 } )
99101 ] ) ;
100-
101102 if ( ! result ) {
102103 return {
103104 classInfoList : [ ] ,
104105 emptyReason : EmptyReason . CommandNullResult ,
105106 isEmpty : true
106107 } ;
107108 }
108-
109109 return result ;
110110 } else {
111111 const result = await Promise . race ( [
@@ -116,15 +116,13 @@ export namespace CopilotHelper {
116116 } , 80 ) ; // 80ms timeout
117117 } )
118118 ] ) ;
119-
120119 if ( ! result ) {
121120 return {
122121 classInfoList : [ ] ,
123122 emptyReason : EmptyReason . CommandNullResult ,
124123 isEmpty : true
125124 } ;
126125 }
127-
128126 return result ;
129127 }
130128 } catch ( error : any ) {
@@ -135,15 +133,13 @@ export namespace CopilotHelper {
135133 isEmpty : true
136134 } ;
137135 }
138-
139136 if ( error . message === ErrorMessage . OperationTimedOut ) {
140137 return {
141138 classInfoList : [ ] ,
142139 emptyReason : EmptyReason . Timeout ,
143140 isEmpty : true
144141 } ;
145142 }
146-
147143 const errorMessage = 'TsException_' + ( ( error as Error ) . message || "unknown" ) ;
148144 sendError ( new GetImportClassContentError ( errorMessage ) ) ;
149145 return {
@@ -162,13 +158,13 @@ export namespace CopilotHelper {
162158 */
163159 export async function resolveProjectDependencies ( projectUri : Uri , cancellationToken ?: CancellationToken ) : Promise < IProjectDependency > {
164160 const result = await resolveProjectDependenciesWithReason ( projectUri , cancellationToken ) ;
165-
161+
166162 // Convert to legacy format
167163 const dependencies : IProjectDependency = { } ;
168164 for ( const dep of result . dependencyInfoList ) {
169165 dependencies [ dep . key ] = dep . value ;
170166 }
171-
167+
172168 return dependencies ;
173169 }
174170
@@ -178,7 +174,10 @@ export namespace CopilotHelper {
178174 * @param cancellationToken Optional cancellation token to abort the operation
179175 * @returns Result object containing project dependencies and error information
180176 */
181- export async function resolveProjectDependenciesWithReason ( projectUri : Uri , cancellationToken ?: CancellationToken ) : Promise < IProjectDependenciesResult > {
177+ export async function resolveProjectDependenciesWithReason (
178+ projectUri : Uri ,
179+ cancellationToken ?: CancellationToken
180+ ) : Promise < IProjectDependenciesResult > {
182181 if ( cancellationToken ?. isCancellationRequested ) {
183182 return {
184183 dependencyInfoList : [ ] ,
@@ -189,9 +188,12 @@ export namespace CopilotHelper {
189188
190189 try {
191190 const normalizedUri = decodeURIComponent ( Uri . file ( projectUri . fsPath ) . toString ( ) ) ;
191+ const commandPromise = commands . executeCommand (
192+ Commands . EXECUTE_WORKSPACE_COMMAND ,
193+ Commands . JAVA_PROJECT_GET_DEPENDENCIES ,
194+ normalizedUri
195+ ) as Promise < IProjectDependenciesResult > ;
192196
193- const commandPromise = commands . executeCommand ( Commands . EXECUTE_WORKSPACE_COMMAND , Commands . JAVA_PROJECT_GET_DEPENDENCIES , normalizedUri ) as Promise < IProjectDependenciesResult > ;
194-
195197 if ( cancellationToken ) {
196198 const result = await Promise . race ( [
197199 commandPromise ,
@@ -206,15 +208,13 @@ export namespace CopilotHelper {
206208 } , 40 ) ; // 40ms timeout
207209 } )
208210 ] ) ;
209-
210211 if ( ! result ) {
211212 return {
212213 dependencyInfoList : [ ] ,
213214 emptyReason : EmptyReason . CommandNullResult ,
214215 isEmpty : true
215216 } ;
216217 }
217-
218218 return result ;
219219 } else {
220220 const result = await Promise . race ( [
@@ -225,15 +225,13 @@ export namespace CopilotHelper {
225225 } , 40 ) ; // 40ms timeout
226226 } )
227227 ] ) ;
228-
229228 if ( ! result ) {
230229 return {
231230 dependencyInfoList : [ ] ,
232231 emptyReason : EmptyReason . CommandNullResult ,
233232 isEmpty : true
234233 } ;
235234 }
236-
237235 return result ;
238236 }
239237 } catch ( error : any ) {
@@ -244,15 +242,13 @@ export namespace CopilotHelper {
244242 isEmpty : true
245243 } ;
246244 }
247-
248245 if ( error . message === ErrorMessage . OperationTimedOut ) {
249246 return {
250247 dependencyInfoList : [ ] ,
251248 emptyReason : EmptyReason . Timeout ,
252249 isEmpty : true
253250 } ;
254251 }
255-
256252 const errorMessage = 'TsException_' + ( ( error as Error ) . message || "unknown" ) ;
257253 sendError ( new GetProjectDependenciesError ( errorMessage ) ) ;
258254 return {
@@ -274,40 +270,38 @@ export namespace CopilotHelper {
274270 workspaceFolders : readonly { uri : Uri } [ ] | undefined ,
275271 copilotCancel : CancellationToken ,
276272 checkCancellation : ( token : CancellationToken ) => void
277- ) : Promise < Array < { name : string ; value : string ; importance : number } > > {
273+ ) : Promise < { name : string ; value : string ; importance : number } [ ] > {
278274 const items : any [ ] = [ ] ;
279-
280275 // Check if workspace folders exist
281276 if ( ! workspaceFolders || workspaceFolders . length === 0 ) {
282277 sendContextOperationTelemetry ( "resolveProjectDependencies" , "ContextEmpty" , sendInfo , EmptyReason . NoWorkspace ) ;
283278 return items ;
284279 }
285-
286280 const projectUri = workspaceFolders [ 0 ] ;
287-
281+
288282 // Resolve project dependencies
289283 const projectDependenciesResult = await resolveProjectDependenciesWithReason ( projectUri . uri , copilotCancel ) ;
290-
284+
291285 // Check for cancellation after dependency resolution
292286 checkCancellation ( copilotCancel ) ;
293-
287+
294288 // Send telemetry if result is empty
295289 if ( projectDependenciesResult . isEmpty && projectDependenciesResult . emptyReason ) {
296290 sendContextOperationTelemetry ( "resolveProjectDependencies" , "ContextEmpty" , sendInfo , projectDependenciesResult . emptyReason ) ;
297291 }
298-
292+
299293 // Check for cancellation after telemetry
300294 checkCancellation ( copilotCancel ) ;
301-
295+
302296 // Convert project dependencies to context items
303297 if ( projectDependenciesResult . dependencyInfoList && projectDependenciesResult . dependencyInfoList . length > 0 ) {
304298 const contextItems = JavaContextProviderUtils . createContextItemsFromProjectDependencies ( projectDependenciesResult . dependencyInfoList ) ;
305-
299+
306300 // Check cancellation once after creating all items
307301 checkCancellation ( copilotCancel ) ;
308302 items . push ( ...contextItems ) ;
309303 }
310-
304+
311305 return items ;
312306 }
313307
@@ -325,46 +319,40 @@ export namespace CopilotHelper {
325319 checkCancellation : ( token : CancellationToken ) => void
326320 ) : Promise < any [ ] > {
327321 const items : any [ ] = [ ] ;
328-
329322 // Check if there's an active editor with a Java document
330323 if ( ! activeEditor ) {
331324 sendContextOperationTelemetry ( "resolveLocalImports" , "ContextEmpty" , sendInfo , EmptyReason . NoActiveEditor ) ;
332325 return items ;
333326 }
334-
335327 if ( activeEditor . document . languageId !== 'java' ) {
336328 sendContextOperationTelemetry ( "resolveLocalImports" , "ContextEmpty" , sendInfo , EmptyReason . NotJavaFile ) ;
337329 return items ;
338330 }
339-
331+
340332 const documentUri = activeEditor . document . uri ;
341-
333+
342334 // Check for cancellation before resolving imports
343335 checkCancellation ( copilotCancel ) ;
344-
345336 // Resolve imports directly without caching
346337 const importClassResult = await resolveLocalImportsWithReason ( documentUri , copilotCancel ) ;
347-
338+
348339 // Check for cancellation after resolution
349340 checkCancellation ( copilotCancel ) ;
350-
341+
351342 // Send telemetry if result is empty
352343 if ( importClassResult . isEmpty && importClassResult . emptyReason ) {
353344 sendContextOperationTelemetry ( "resolveLocalImports" , "ContextEmpty" , sendInfo , importClassResult . emptyReason ) ;
354345 }
355346 // Check for cancellation before processing results
356347 checkCancellation ( copilotCancel ) ;
357-
358348 if ( importClassResult . classInfoList && importClassResult . classInfoList . length > 0 ) {
359349 // Process imports in batches to reduce cancellation check overhead
360350 const contextItems = JavaContextProviderUtils . createContextItemsFromImports ( importClassResult . classInfoList ) ;
361-
362351 // Check cancellation once after creating all items
363352 checkCancellation ( copilotCancel ) ;
364-
365353 items . push ( ...contextItems ) ;
366354 }
367-
355+
368356 return items ;
369357 }
370358}
0 commit comments