|
11 | 11 | import org.eclipse.core.resources.IResourceChangeListener; |
12 | 12 | import org.eclipse.core.resources.IResourceDelta; |
13 | 13 | import org.eclipse.core.resources.IResourceDeltaVisitor; |
14 | | -import org.eclipse.core.resources.IWorkspaceRoot; |
15 | 14 | import org.eclipse.core.resources.ResourcesPlugin; |
16 | 15 | import org.eclipse.core.runtime.CoreException; |
17 | 16 | import org.eclipse.core.runtime.IPath; |
|
25 | 24 | import org.eclipse.jdt.core.JavaCore; |
26 | 25 | import org.eclipse.jdt.core.JavaModelException; |
27 | 26 | import org.eclipse.jdt.launching.JavaRuntime; |
28 | | -import org.eclipse.jdt.ls.core.internal.ResourceUtils; |
| 27 | +import org.eclipse.jdt.ls.core.internal.JDTUtils; |
29 | 28 |
|
30 | 29 | import com.microsoft.jdtls.ext.core.JdtlsExtActivator; |
31 | 30 |
|
@@ -214,7 +213,6 @@ private static long calculateClasspathHash(IJavaProject javaProject) { |
214 | 213 | private static final String KEY_MODULE_NAME = "moduleName"; |
215 | 214 | private static final String KEY_TOTAL_LIBRARIES = "totalLibraries"; |
216 | 215 | private static final String KEY_TOTAL_PROJECT_REFS = "totalProjectReferences"; |
217 | | - private static final String KEY_JRE_CONTAINER_PATH = "jreContainerPath"; |
218 | 216 | private static final String KEY_JRE_CONTAINER = "jreContainer"; |
219 | 217 |
|
220 | 218 | public static class DependencyInfo { |
@@ -242,12 +240,16 @@ public static List<DependencyInfo> resolveProjectDependencies(String fileUri, IP |
242 | 240 | List<DependencyInfo> result = new ArrayList<>(); |
243 | 241 |
|
244 | 242 | 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); |
246 | 247 |
|
247 | | - // Find the project |
248 | | - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); |
249 | | - IProject project = findProjectByPath(root, fileIPath); |
| 248 | + if (resource == null) { |
| 249 | + return result; |
| 250 | + } |
250 | 251 |
|
| 252 | + IProject project = resource.getProject(); |
251 | 253 | if (project == null || !project.isAccessible()) { |
252 | 254 | return result; |
253 | 255 | } |
@@ -290,36 +292,6 @@ public static List<DependencyInfo> resolveProjectDependencies(String fileUri, IP |
290 | 292 | return result; |
291 | 293 | } |
292 | 294 |
|
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 | | - |
323 | 295 | /** |
324 | 296 | * Add basic project information including name, location, and Java version settings. |
325 | 297 | */ |
|
0 commit comments