|
30 | 30 | import org.apache.commons.lang3.StringUtils;
|
31 | 31 | import org.eclipse.core.resources.IFile;
|
32 | 32 | import org.eclipse.core.resources.IProject;
|
| 33 | +import org.eclipse.core.resources.IResource; |
| 34 | +import org.eclipse.core.resources.IResourceVisitor; |
33 | 35 | import org.eclipse.core.resources.IWorkspaceRoot;
|
34 | 36 | import org.eclipse.core.resources.ResourcesPlugin;
|
35 | 37 | import org.eclipse.core.runtime.CoreException;
|
@@ -110,9 +112,21 @@ public static List<PackageNode> listProjects(List<Object> arguments, IProgressMo
|
110 | 112 |
|
111 | 113 | PackageNode projectNode = PackageNode.createNodeForProject(JavaCore.create(project));
|
112 | 114 |
|
113 |
| - // set the folder name as the project name when the project location |
114 |
| - // is out of the workspace folder. |
115 | 115 | 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. |
116 | 130 | projectNode.setDisplayName(workspaceFolderPath.lastSegment());
|
117 | 131 | }
|
118 | 132 | children.add(projectNode);
|
@@ -292,4 +306,40 @@ private static String getSeverityString(int severity) {
|
292 | 306 | return "UNKNOWN STATUS";
|
293 | 307 | }
|
294 | 308 | }
|
| 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 | + } |
295 | 345 | }
|
0 commit comments