Skip to content

Commit b00b2df

Browse files
authored
fix: Better handling the linked resource when getting projects (#694)
- When comparing the project location with the workspace folder path, scan the folder with one level deep and check if the linked folder belongs to the workspace folder. Signed-off-by: Sheng Chen <[email protected]>
1 parent e60b2b3 commit b00b2df

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

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

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.apache.commons.lang3.StringUtils;
3131
import org.eclipse.core.resources.IFile;
3232
import org.eclipse.core.resources.IProject;
33+
import org.eclipse.core.resources.IResource;
34+
import org.eclipse.core.resources.IResourceVisitor;
3335
import org.eclipse.core.resources.IWorkspaceRoot;
3436
import org.eclipse.core.resources.ResourcesPlugin;
3537
import org.eclipse.core.runtime.CoreException;
@@ -110,9 +112,21 @@ public static List<PackageNode> listProjects(List<Object> arguments, IProgressMo
110112

111113
PackageNode projectNode = PackageNode.createNodeForProject(JavaCore.create(project));
112114

113-
// set the folder name as the project name when the project location
114-
// is out of the workspace folder.
115115
if (!workspaceFolderPath.isPrefixOf(project.getLocation())) {
116+
LinkedFolderVisitor visitor = new LinkedFolderVisitor(workspaceFolderPath);
117+
try {
118+
project.accept(visitor, IResource.DEPTH_ONE, false);
119+
} catch (CoreException e) {
120+
JdtlsExtActivator.log(e);
121+
continue;
122+
}
123+
124+
if (!visitor.isBelongsToWorkspace()) {
125+
continue;
126+
}
127+
128+
// set the folder name as the project name when the project location
129+
// is out of the workspace folder.
116130
projectNode.setDisplayName(workspaceFolderPath.lastSegment());
117131
}
118132
children.add(projectNode);
@@ -292,4 +306,40 @@ private static String getSeverityString(int severity) {
292306
return "UNKNOWN STATUS";
293307
}
294308
}
309+
310+
private static final class LinkedFolderVisitor implements IResourceVisitor {
311+
312+
private boolean belongsToWorkspace;
313+
314+
private IPath workspaceFolderPath;
315+
316+
public LinkedFolderVisitor(IPath workspaceFolderPath) {
317+
this.belongsToWorkspace = false;
318+
this.workspaceFolderPath = workspaceFolderPath;
319+
}
320+
321+
@Override
322+
public boolean visit(IResource resource) throws CoreException {
323+
if (this.belongsToWorkspace) {
324+
return false;
325+
}
326+
327+
if (!resource.exists()) {
328+
return false;
329+
}
330+
331+
if (resource.isLinked()) {
332+
IPath realPath = resource.getLocation();
333+
if (workspaceFolderPath.isPrefixOf(realPath)) {
334+
this.belongsToWorkspace = true;
335+
}
336+
}
337+
338+
return true;
339+
}
340+
341+
public boolean isBelongsToWorkspace() {
342+
return belongsToWorkspace;
343+
}
344+
}
295345
}

0 commit comments

Comments
 (0)