@@ -310,7 +310,8 @@ public static ReadFileResult readFileWithStats(String uri) {
310310
311311 /**
312312 * Reads the contents of a directory given its URI. Used by workspace/readDirectory API to list directory entries.
313- * Works with both local filesystem URIs and virtual URIs (e.g., semanticfs://) through Eclipse's IResource API.
313+ * Works with local filesystem URIs, platform:/resource URIs (produced by {@link #getResourceUri(IResource)}), and
314+ * virtual URIs (e.g., semanticfs://) through Eclipse's IResource API.
314315 *
315316 * @param uri the directory URI
316317 * @return ReadDirectoryResult containing the directory entries
@@ -324,21 +325,31 @@ public static ReadDirectoryResult readDirectoryEntries(String uri) {
324325 URI parsedUri = new URI (uri );
325326 IWorkspaceRoot root = ResourcesPlugin .getWorkspace ().getRoot ();
326327
327- // Try to find containers (folders/projects) for the given URI
328- IContainer [] containers = root .findContainersForLocationURI (parsedUri );
329- if (containers == null || containers .length == 0 ) {
330- return new ReadDirectoryResult (Collections .emptyList ());
331- }
332-
333- // findContainersForLocationURI may return multiple matches;
334- // pick the first accessible one to avoid reading a closed/phantom project
335328 IContainer container = null ;
336- for (IContainer c : containers ) {
337- if (c .isAccessible ()) {
338- container = c ;
339- break ;
329+ if ("platform" .equals (parsedUri .getScheme ())) {
330+ // Handle platform:/resource/... URIs by resolving via workspace path
331+ String path = parsedUri .getPath ();
332+ String prefix = "/resource" ;
333+ if (path != null && path .startsWith (prefix )) {
334+ String workspacePath = path .substring (prefix .length ());
335+ IResource resource = root .findMember (workspacePath );
336+ if (resource instanceof IContainer c && c .isAccessible ()) {
337+ container = c ;
338+ }
339+ }
340+ } else {
341+ // For file://, semanticfs://, and other URIs, use location URI lookup
342+ IContainer [] containers = root .findContainersForLocationURI (parsedUri );
343+ if (containers != null ) {
344+ for (IContainer c : containers ) {
345+ if (c .isAccessible ()) {
346+ container = c ;
347+ break ;
348+ }
349+ }
340350 }
341351 }
352+
342353 if (container == null ) {
343354 return new ReadDirectoryResult (Collections .emptyList ());
344355 }
0 commit comments