@@ -350,20 +350,13 @@ public static boolean checkImportStatus() {
350350 return hasError ;
351351 }
352352
353- // Threshold for triggering external dependency resolution
354- // If project source classes < this value, supplement with external dependencies
355- private static final int MIN_SOURCE_CLASSES_THRESHOLD = 5 ;
356-
357- // Maximum number of external dependency classes to include
358- private static final int MAX_DEPENDENCY_CLASSES = 10 ;
359-
360353 // Maximum methods to display for binary (external) classes
361- private static final int MAX_METHODS_FOR_BINARY = 5 ;
354+ private static final int MAX_METHODS_FOR_BINARY = 50 ;
362355
363356 /**
364357 * Get import class content for Copilot integration.
365358 * This method extracts information about imported classes from a Java file.
366- * Uses an adaptive strategy: only includes external dependencies when project sources are sparse .
359+ * Uses a time-controlled strategy: prioritizes internal classes, adds external classes only if time permits .
367360 *
368361 * @param arguments List containing the file URI as the first element
369362 * @param monitor Progress monitor for cancellation support
@@ -374,6 +367,11 @@ public static List<ImportClassInfo> getImportClassContent(List<Object> arguments
374367 return Collections .emptyList ();
375368 }
376369
370+ // Time control: total budget 80ms, early return at 75ms
371+ long startTime = System .currentTimeMillis ();
372+ final long TIME_BUDGET_MS = 80 ;
373+ final long EARLY_RETURN_MS = 75 ;
374+
377375 try {
378376 String fileUri = (String ) arguments .get (0 );
379377
@@ -408,17 +406,18 @@ public static List<ImportClassInfo> getImportClassContent(List<Object> arguments
408406 org .eclipse .jdt .core .ICompilationUnit compilationUnit = (org .eclipse .jdt .core .ICompilationUnit ) javaElement ;
409407
410408 // Parse imports and resolve local project files
411- // Delegate to JavaContentParser for processing
412409 List <ImportClassInfo > classInfoList = new ArrayList <>();
413410
414411 // Get all imports from the compilation unit
415412 org .eclipse .jdt .core .IImportDeclaration [] imports = compilationUnit .getImports ();
416413 Set <String > processedTypes = new HashSet <>();
417414
418- // Phase 1: Resolve project source classes only
415+ // Phase 1: Priority - Resolve project source classes (internal)
419416 for (org .eclipse .jdt .core .IImportDeclaration importDecl : imports ) {
420- if (monitor .isCanceled ()) {
421- break ;
417+ // Check time budget before each operation
418+ long elapsed = System .currentTimeMillis () - startTime ;
419+ if (monitor .isCanceled () || elapsed >= EARLY_RETURN_MS ) {
420+ return classInfoList ; // Early return if approaching time limit
422421 }
423422
424423 String importName = importDecl .getElementName ();
@@ -437,34 +436,41 @@ public static List<ImportClassInfo> getImportClassContent(List<Object> arguments
437436 }
438437 }
439438
440- // Phase 2: Adaptive external dependency resolution
441- // Only trigger if project source classes are sparse (< threshold)
442- if (classInfoList . size () < MIN_SOURCE_CLASSES_THRESHOLD && !monitor .isCanceled ()) {
443- // Track external classes separately to apply limits
444- List < ImportClassInfo > externalClasses = new ArrayList <>() ;
439+ // Phase 2: If time permits, resolve external dependencies
440+ long elapsedAfterInternal = System . currentTimeMillis () - startTime ;
441+ if (elapsedAfterInternal < EARLY_RETURN_MS && !monitor .isCanceled ()) {
442+ // Calculate remaining time budget for external classes
443+ long remainingTime = TIME_BUDGET_MS - elapsedAfterInternal ;
445444
446- for (org .eclipse .jdt .core .IImportDeclaration importDecl : imports ) {
447- if (monitor .isCanceled () || externalClasses .size () >= MAX_DEPENDENCY_CLASSES ) {
448- break ;
449- }
450-
451- String importName = importDecl .getElementName ();
452- boolean isStatic = (importDecl .getFlags () & org .eclipse .jdt .core .Flags .AccStatic ) != 0 ;
445+ // Only proceed with external if we have reasonable time left (at least 15ms)
446+ if (remainingTime >= 15 ) {
447+ List <ImportClassInfo > externalClasses = new ArrayList <>();
453448
454- // Skip package imports (*.* ) - too broad for external dependencies
455- if (importName .endsWith (".*" )) {
456- continue ;
449+ for (org .eclipse .jdt .core .IImportDeclaration importDecl : imports ) {
450+ // Check time before each external resolution
451+ long currentElapsed = System .currentTimeMillis () - startTime ;
452+ if (monitor .isCanceled () || currentElapsed >= EARLY_RETURN_MS ) {
453+ break ;
454+ }
455+
456+ String importName = importDecl .getElementName ();
457+ boolean isStatic = (importDecl .getFlags () & org .eclipse .jdt .core .Flags .AccStatic ) != 0 ;
458+
459+ // Skip package imports (*.* ) - too broad for external dependencies
460+ if (importName .endsWith (".*" )) {
461+ continue ;
462+ }
463+
464+ // Resolve external (binary) types with simplified content
465+ if (!isStatic ) {
466+ ContextResolver .resolveBinaryType (javaProject , importName , externalClasses ,
467+ processedTypes , MAX_METHODS_FOR_BINARY , monitor );
468+ }
457469 }
458470
459- // Resolve external (binary) types with simplified content
460- if (!isStatic ) {
461- ContextResolver .resolveBinaryType (javaProject , importName , externalClasses ,
462- processedTypes , MAX_METHODS_FOR_BINARY , monitor );
463- }
471+ // Append external classes after project sources
472+ classInfoList .addAll (externalClasses );
464473 }
465-
466- // Append external classes after project sources
467- classInfoList .addAll (externalClasses );
468474 }
469475
470476 return classInfoList ;
0 commit comments