Skip to content

Commit 276ac71

Browse files
committed
feat: adjust logic and bump up version
1 parent 125bd9b commit 276ac71

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/ProjectCommand.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,29 @@ private static void resolveSingleType(IJavaProject javaProject, String typeName,
440440
String packageName = typeName.substring(0, lastDotIndex);
441441
String simpleName = typeName.substring(lastDotIndex + 1);
442442

443-
// Strategy: First search in local source packages (fast), then fallback to global search (slow)
444-
// This optimizes for the common case where imports reference local project types
443+
// Strategy: Use JDT's global type resolution first (comprehensive),
444+
// then fallback to manual package fragment traversal if needed
445445

446-
// Fast path: Search for the type in source package fragments directly
446+
// Primary path: Use JDT's findType which searches all sources and dependencies
447+
try {
448+
org.eclipse.jdt.core.IType type = javaProject.findType(typeName);
449+
if (type != null && type.exists()) {
450+
// Found type - check if it's a source type we want to process
451+
if (!type.isBinary()) {
452+
// Source type found - extract information and return
453+
extractTypeInfo(type, result);
454+
return;
455+
}
456+
// Note: Binary types (from JARs/JRE) are intentionally ignored
457+
// as they don't provide useful context for code completion
458+
}
459+
} catch (JavaModelException e) {
460+
JdtlsExtActivator.logException("Error in primary type search: " + typeName, e);
461+
// Continue to fallback method
462+
}
463+
464+
// Fallback path: Manual search in local source package fragments
465+
// This is used when findType() doesn't return results or fails
447466
IPackageFragmentRoot[] packageRoots = javaProject.getPackageFragmentRoots();
448467
for (IPackageFragmentRoot packageRoot : packageRoots) {
449468
if (packageRoot.getKind() == IPackageFragmentRoot.K_SOURCE) {
@@ -456,7 +475,7 @@ private static void resolveSingleType(IJavaProject javaProject, String typeName,
456475
org.eclipse.jdt.core.IType primaryType = cu.findPrimaryType();
457476
if (primaryType != null && primaryType.exists() &&
458477
typeName.equals(primaryType.getFullyQualifiedName())) {
459-
// Found local project source type - fast path success
478+
// Found local project source type via fallback method
460479
extractTypeInfo(primaryType, result);
461480
return;
462481
}
@@ -473,23 +492,6 @@ private static void resolveSingleType(IJavaProject javaProject, String typeName,
473492
}
474493
}
475494
}
476-
477-
// Slow path: Use JDT's global type resolution as fallback for external dependencies
478-
// This is only needed if the type is not found in local source packages
479-
try {
480-
org.eclipse.jdt.core.IType type = javaProject.findType(typeName);
481-
if (type != null && type.exists()) {
482-
// Found type in dependencies/JRE, but we only process local source types
483-
// for this specific use case (Copilot context)
484-
if (!type.isBinary()) {
485-
extractTypeInfo(type, result);
486-
}
487-
// Note: Binary types (from JARs) are intentionally ignored
488-
// as they don't provide useful context for code completion
489-
}
490-
} catch (JavaModelException e) {
491-
JdtlsExtActivator.logException("Error finding type in global search: " + typeName, e);
492-
}
493495
} catch (JavaModelException e) {
494496
// Log but continue processing other types
495497
JdtlsExtActivator.logException("Error resolving type: " + typeName, e);

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-java-dependency",
33
"displayName": "Project Manager for Java",
44
"description": "%description%",
5-
"version": "0.25.0",
5+
"version": "0.26.0",
66
"publisher": "vscjava",
77
"preview": false,
88
"aiKey": "5c642b22-e845-4400-badb-3f8509a70777",

0 commit comments

Comments
 (0)