Skip to content

Commit f625d9f

Browse files
committed
fix: update
1 parent 2f0abf3 commit f625d9f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,29 @@ private static void resolveSingleType(IJavaProject javaProject, String typeName,
435435
String packageName = typeName.substring(0, lastDotIndex);
436436
String simpleName = typeName.substring(lastDotIndex + 1);
437437

438-
// Search for the type in source package fragments only
438+
// First try to find the type using JDT's built-in type resolution
439+
try {
440+
org.eclipse.jdt.core.IType type = javaProject.findType(typeName);
441+
if (type != null && type.exists() && type.isBinary() == false) {
442+
// This is a local project type (not from a JAR)
443+
extractTypeInfo(type, result);
444+
return;
445+
}
446+
} catch (JavaModelException e) {
447+
JdtlsExtActivator.logException("Error finding type: " + typeName, e);
448+
// Fall back to manual search if findType fails
449+
return;
450+
}
451+
452+
// Fallback: Search for the type in source package fragments manually
439453
IPackageFragmentRoot[] packageRoots = javaProject.getPackageFragmentRoots();
440454
for (IPackageFragmentRoot packageRoot : packageRoots) {
441455
if (packageRoot.getKind() == IPackageFragmentRoot.K_SOURCE) {
442456
org.eclipse.jdt.core.IPackageFragment packageFragment = packageRoot.getPackageFragment(packageName);
443457
if (packageFragment != null && packageFragment.exists()) {
444458
// Look for compilation unit with matching name
445459
org.eclipse.jdt.core.ICompilationUnit cu = packageFragment.getCompilationUnit(simpleName + ".java");
446-
if (cu != null && cu.exists()) {
460+
if (cu != null && cu.exists() && cu.getResource() != null && cu.getResource().exists()) {
447461
// Get primary type from compilation unit
448462
org.eclipse.jdt.core.IType primaryType = cu.findPrimaryType();
449463
if (primaryType != null && primaryType.exists() &&

0 commit comments

Comments
 (0)