Skip to content

Commit 964b7f9

Browse files
committed
fix: update in project resolver
1 parent bfb797b commit 964b7f9

File tree

1 file changed

+9
-37
lines changed

1 file changed

+9
-37
lines changed

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

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.eclipse.core.resources.IResourceChangeListener;
1212
import org.eclipse.core.resources.IResourceDelta;
1313
import org.eclipse.core.resources.IResourceDeltaVisitor;
14-
import org.eclipse.core.resources.IWorkspaceRoot;
1514
import org.eclipse.core.resources.ResourcesPlugin;
1615
import org.eclipse.core.runtime.CoreException;
1716
import org.eclipse.core.runtime.IPath;
@@ -25,7 +24,7 @@
2524
import org.eclipse.jdt.core.JavaCore;
2625
import org.eclipse.jdt.core.JavaModelException;
2726
import org.eclipse.jdt.launching.JavaRuntime;
28-
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
27+
import org.eclipse.jdt.ls.core.internal.JDTUtils;
2928

3029
import com.microsoft.jdtls.ext.core.JdtlsExtActivator;
3130

@@ -214,7 +213,6 @@ private static long calculateClasspathHash(IJavaProject javaProject) {
214213
private static final String KEY_MODULE_NAME = "moduleName";
215214
private static final String KEY_TOTAL_LIBRARIES = "totalLibraries";
216215
private static final String KEY_TOTAL_PROJECT_REFS = "totalProjectReferences";
217-
private static final String KEY_JRE_CONTAINER_PATH = "jreContainerPath";
218216
private static final String KEY_JRE_CONTAINER = "jreContainer";
219217

220218
public static class DependencyInfo {
@@ -242,12 +240,16 @@ public static List<DependencyInfo> resolveProjectDependencies(String fileUri, IP
242240
List<DependencyInfo> result = new ArrayList<>();
243241

244242
try {
245-
IPath fileIPath = ResourceUtils.canonicalFilePathFromURI(fileUri);
243+
// Use JDTUtils to convert URI and find the resource
244+
java.net.URI uri = JDTUtils.toURI(fileUri);
245+
IResource resource = JDTUtils.findResource(uri,
246+
ResourcesPlugin.getWorkspace().getRoot()::findFilesForLocationURI);
246247

247-
// Find the project
248-
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
249-
IProject project = findProjectByPath(root, fileIPath);
248+
if (resource == null) {
249+
return result;
250+
}
250251

252+
IProject project = resource.getProject();
251253
if (project == null || !project.isAccessible()) {
252254
return result;
253255
}
@@ -290,36 +292,6 @@ public static List<DependencyInfo> resolveProjectDependencies(String fileUri, IP
290292
return result;
291293
}
292294

293-
/**
294-
* 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
301-
*/
302-
private static IProject findProjectByPath(IWorkspaceRoot root, IPath filePath) {
303-
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
314-
for (IProject p : allProjects) {
315-
if (p.getLocation() != null && p.getLocation().isPrefixOf(filePath)) {
316-
return p;
317-
}
318-
}
319-
320-
return null;
321-
}
322-
323295
/**
324296
* Add basic project information including name, location, and Java version settings.
325297
*/

0 commit comments

Comments
 (0)