Skip to content

Commit 098e84d

Browse files
authored
Merge branch 'main' into wenyt/cache
2 parents f968cd3 + a9fa707 commit 098e84d

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ private static String getSeverityString(int severity) {
506506
/**
507507
* Get project dependencies information including JDK version.
508508
*
509-
* @param arguments List containing the project URI as the first element
509+
* @param arguments List containing the file URI as the first element
510510
* @param monitor Progress monitor for cancellation support
511511
* @return List of DependencyInfo containing key-value pairs of project information
512512
*/
@@ -515,8 +515,8 @@ public static List<DependencyInfo> getProjectDependencies(List<Object> arguments
515515
return new ArrayList<>();
516516
}
517517

518-
String projectUri = (String) arguments.get(0);
519-
List<ProjectResolver.DependencyInfo> resolverResult = ProjectResolver.resolveProjectDependencies(projectUri, monitor);
518+
String fileUri = (String) arguments.get(0);
519+
List<ProjectResolver.DependencyInfo> resolverResult = ProjectResolver.resolveProjectDependencies(fileUri, monitor);
520520

521521
// Convert ProjectResolver.DependencyInfo to ProjectCommand.DependencyInfo
522522
List<DependencyInfo> result = new ArrayList<>();

jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/parser/ProjectResolver.java

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ public DependencyInfo(String key, String value) {
229229

230230
/**
231231
* Resolve project dependencies information including JDK version.
232+
* Supports both single projects and multi-module aggregator projects.
232233
*
233-
* @param projectUri The project URI
234+
* @param fileUri The file URI
234235
* @param monitor Progress monitor for cancellation support
235236
* @return List of DependencyInfo containing key-value pairs of project information
236237
*/
@@ -241,11 +242,11 @@ public static List<DependencyInfo> resolveProjectDependencies(String projectUri,
241242
List<DependencyInfo> result = new ArrayList<>();
242243

243244
try {
244-
IPath projectPath = ResourceUtils.canonicalFilePathFromURI(projectUri);
245+
IPath fileIPath = ResourceUtils.canonicalFilePathFromURI(fileUri);
245246

246247
// Find the project
247248
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
248-
IProject project = findProjectByPath(root, projectPath);
249+
IProject project = findProjectByPath(root, fileIPath);
249250

250251
if (project == null || !project.isAccessible()) {
251252
return result;
@@ -291,14 +292,31 @@ public static List<DependencyInfo> resolveProjectDependencies(String projectUri,
291292

292293
/**
293294
* Find project by path from all projects in workspace.
295+
* The path can be either a project root path or a file/folder path within a project.
296+
* This method will find the project that contains the given path.
297+
*
298+
* @param root The workspace root
299+
* @param filePath The path to search for (can be project root or file within project)
300+
* @return The project that contains the path, or null if not found
294301
*/
295-
private static IProject findProjectByPath(IWorkspaceRoot root, IPath projectPath) {
302+
private static IProject findProjectByPath(IWorkspaceRoot root, IPath filePath) {
296303
IProject[] allProjects = root.getProjects();
304+
305+
// First pass: check for exact project location match (most efficient)
306+
for (IProject p : allProjects) {
307+
if (p.getLocation() != null && p.getLocation().equals(filePath)) {
308+
return p;
309+
}
310+
}
311+
312+
// Second pass: check if the file path is within any project directory
313+
// This handles cases where filePath points to a file or folder inside a project
297314
for (IProject p : allProjects) {
298-
if (p.getLocation() != null && p.getLocation().equals(projectPath)) {
315+
if (p.getLocation() != null && p.getLocation().isPrefixOf(filePath)) {
299316
return p;
300317
}
301318
}
319+
302320
return null;
303321
}
304322

@@ -363,17 +381,19 @@ private static void processClasspathEntries(List<DependencyInfo> result, IJavaPr
363381

364382
/**
365383
* Process a library classpath entry.
384+
* Only returns the library file name without full path to reduce data size.
366385
*/
367386
private static void processLibraryEntry(List<DependencyInfo> result, IClasspathEntry entry, int libCount) {
368387
IPath libPath = entry.getPath();
369388
if (libPath != null) {
370-
result.add(new DependencyInfo("library_" + libCount,
371-
libPath.lastSegment() + " (" + libPath.toOSString() + ")"));
389+
// Only keep the file name, remove the full path
390+
result.add(new DependencyInfo("library_" + libCount, libPath.lastSegment()));
372391
}
373392
}
374393

375394
/**
376395
* Process a project reference classpath entry.
396+
* Simplified to only extract essential information.
377397
*/
378398
private static void processProjectEntry(List<DependencyInfo> result, IClasspathEntry entry, int projectRefCount) {
379399
IPath projectRefPath = entry.getPath();
@@ -390,12 +410,21 @@ private static void processContainerEntry(List<DependencyInfo> result, IClasspat
390410
String containerPath = entry.getPath().toString();
391411

392412
if (containerPath.contains("JRE_CONTAINER")) {
393-
result.add(new DependencyInfo(KEY_JRE_CONTAINER_PATH, containerPath));
413+
// Only extract the JRE version, not the full container path
394414
try {
395415
String vmInstallName = JavaRuntime.getVMInstallName(entry.getPath());
396416
addIfNotNull(result, KEY_JRE_CONTAINER, vmInstallName);
397417
} catch (Exception e) {
398-
// Ignore if unable to get VM install name
418+
// Fallback: try to extract version from path
419+
if (containerPath.contains("JavaSE-")) {
420+
int startIdx = containerPath.lastIndexOf("JavaSE-");
421+
String version = containerPath.substring(startIdx);
422+
// Clean up any trailing characters
423+
if (version.contains("/")) {
424+
version = version.substring(0, version.indexOf("/"));
425+
}
426+
result.add(new DependencyInfo(KEY_JRE_CONTAINER, version));
427+
}
399428
}
400429
} else if (containerPath.contains("MAVEN")) {
401430
result.add(new DependencyInfo(KEY_BUILD_TOOL, "Maven"));

0 commit comments

Comments
 (0)