Skip to content

Commit 930f333

Browse files
committed
Answer a folder with the matches that are inside it
A project brought into the search by its source folders can link them in from more than one workspace folder, and accepting every match by the project alone then answers one folder with the main classes of another. Check where the match itself is as well. The project checks stay in front of it: a caller can ask with a project's own location rather than with a workspace folder, and for a project whose description lives outside of the workspace folders no match is contained in that location.
1 parent 3231c5e commit 930f333

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveMainClassHandler.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void acceptSearchMatch(SearchMatch match) {
143143
if (parentPaths.isEmpty()
144144
|| ResourceUtils.isContainedIn(project.getLocation(), parentPaths)
145145
|| isContainedInInvisibleProject(project, parentPaths)
146-
|| hasSourceFolderContainedIn(project, parentPaths)) {
146+
|| isMatchContainedIn(match, parentPaths)) {
147147
String filePath = null;
148148

149149
if (match.getResource() instanceof IFile) {
@@ -259,6 +259,20 @@ private boolean isMainMethod(IMethod method) {
259259
return false;
260260
}
261261

262+
/**
263+
* Where the match itself is, for the projects the source folder check brings into the search:
264+
* their source folders can be linked in from more than one workspace folder, and a folder is
265+
* only asking about the main classes that are in it. The project checks stay in front of this
266+
* one - a caller can ask with a project's own location rather than with a workspace folder, and
267+
* for a project whose description lives outside of the workspace folders no match would be
268+
* contained in that location. A match whose resource has no location falls back to them as well,
269+
* since {@link ResourceUtils#isContainedIn} answers false for a null.
270+
*/
271+
private boolean isMatchContainedIn(SearchMatch match, Collection<IPath> rootPaths) {
272+
IResource resource = match.getResource();
273+
return resource != null && ResourceUtils.isContainedIn(resource.getLocation(), rootPaths);
274+
}
275+
262276
/**
263277
* A project can keep its description outside of the workspace folders and reach the sources
264278
* through linked folders. The invisible project does it with a single link named after

0 commit comments

Comments
 (0)