Skip to content

Commit 2f0abf3

Browse files
committed
fix: update findtype to more useable
1 parent 6bf5cb1 commit 2f0abf3

1 file changed

Lines changed: 38 additions & 9 deletions

File tree

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

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -425,15 +425,44 @@ private static void resolveSingleType(IJavaProject javaProject, String typeName,
425425
}
426426
processedTypes.add(typeName);
427427

428-
// Find the type in the project
429-
org.eclipse.jdt.core.IType type = javaProject.findType(typeName);
430-
if (type != null && type.exists()) {
431-
// Check if it's a local project type (not from external dependencies)
432-
IPackageFragmentRoot packageRoot = (IPackageFragmentRoot) type
433-
.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
434-
if (packageRoot != null && packageRoot.getKind() == IPackageFragmentRoot.K_SOURCE) {
435-
// This is a source type from the local project
436-
extractTypeInfo(type, result);
428+
// Extract package and simple name from the fully qualified type name
429+
int lastDotIndex = typeName.lastIndexOf('.');
430+
if (lastDotIndex == -1) {
431+
// Default package or invalid type name
432+
return;
433+
}
434+
435+
String packageName = typeName.substring(0, lastDotIndex);
436+
String simpleName = typeName.substring(lastDotIndex + 1);
437+
438+
// Search for the type in source package fragments only
439+
IPackageFragmentRoot[] packageRoots = javaProject.getPackageFragmentRoots();
440+
for (IPackageFragmentRoot packageRoot : packageRoots) {
441+
if (packageRoot.getKind() == IPackageFragmentRoot.K_SOURCE) {
442+
org.eclipse.jdt.core.IPackageFragment packageFragment = packageRoot.getPackageFragment(packageName);
443+
if (packageFragment != null && packageFragment.exists()) {
444+
// Look for compilation unit with matching name
445+
org.eclipse.jdt.core.ICompilationUnit cu = packageFragment.getCompilationUnit(simpleName + ".java");
446+
if (cu != null && cu.exists()) {
447+
// Get primary type from compilation unit
448+
org.eclipse.jdt.core.IType primaryType = cu.findPrimaryType();
449+
if (primaryType != null && primaryType.exists() &&
450+
typeName.equals(primaryType.getFullyQualifiedName())) {
451+
// This is a local project type
452+
extractTypeInfo(primaryType, result);
453+
return;
454+
}
455+
456+
// Also check for inner types in the compilation unit
457+
org.eclipse.jdt.core.IType[] allTypes = cu.getAllTypes();
458+
for (org.eclipse.jdt.core.IType type : allTypes) {
459+
if (typeName.equals(type.getFullyQualifiedName())) {
460+
extractTypeInfo(type, result);
461+
return;
462+
}
463+
}
464+
}
465+
}
437466
}
438467
}
439468
} catch (JavaModelException e) {

0 commit comments

Comments
 (0)