Skip to content

Commit 9110089

Browse files
authored
Add project scope when resolving multiple-root project. (#114)
1 parent 388b5fc commit 9110089

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
4343
return handler.resolveClasspaths(arguments);
4444
} else if (RESOLVE_MAINCLASS.equals(commandId)) {
4545
ResolveMainClassHandler handler = new ResolveMainClassHandler();
46-
return handler.resolveMainClass();
46+
return handler.resolveMainClass(arguments);
4747
} else if (BUILD_WORKSPACE.equals(commandId)) {
4848
// TODO
4949
} else if (FETCH_USER_DATA.equals(commandId)) {

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.eclipse.core.resources.IProject;
2121
import org.eclipse.core.resources.IResource;
2222
import org.eclipse.core.runtime.CoreException;
23+
import org.eclipse.core.runtime.IPath;
2324
import org.eclipse.jdt.core.IJavaProject;
2425
import org.eclipse.jdt.core.IMethod;
2526
import org.eclipse.jdt.core.JavaModelException;
@@ -30,6 +31,7 @@
3031
import org.eclipse.jdt.core.search.SearchParticipant;
3132
import org.eclipse.jdt.core.search.SearchPattern;
3233
import org.eclipse.jdt.core.search.SearchRequestor;
34+
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
3335
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager;
3436

3537
import com.microsoft.java.debug.core.Configuration;
@@ -42,11 +44,19 @@ public class ResolveMainClassHandler {
4244
* @return an array of main class and project name
4345
* @throws CoreException when there are errors when resolving main class.
4446
*/
45-
public Object resolveMainClass() throws CoreException {
46-
return resolveMainClassCore();
47+
public Object resolveMainClass(List<Object> arguments) throws CoreException {
48+
return resolveMainClassCore(arguments);
4749
}
4850

49-
private List<ResolutionItem> resolveMainClassCore() throws CoreException {
51+
private List<ResolutionItem> resolveMainClassCore(List<Object> arguments) throws CoreException {
52+
IPath rootPath = null;
53+
if (arguments != null && arguments.size() > 0) {
54+
rootPath = ResourceUtils.filePathFromURI((String) arguments.get(0));
55+
}
56+
final ArrayList<IPath> targetProjectPath = new ArrayList<>();
57+
if (rootPath != null) {
58+
targetProjectPath.add(rootPath);
59+
}
5060
IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
5161
SearchPattern pattern = SearchPattern.createPattern("main(String[]) void", IJavaSearchConstants.METHOD,
5262
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_EXACT_MATCH);
@@ -72,7 +82,11 @@ public void acceptSearchMatch(SearchMatch match) {
7282
}
7383
}
7484
String projectName = ProjectsManager.DEFAULT_PROJECT_NAME.equals(project.getName()) ? null : project.getName();
75-
res.add(new ResolutionItem(mainClass, projectName));
85+
if (projectName == null
86+
|| targetProjectPath.isEmpty()
87+
|| ResourceUtils.isContainedIn(project.getLocation(), targetProjectPath)) {
88+
res.add(new ResolutionItem(mainClass, projectName));
89+
}
7690
}
7791
}
7892
}

0 commit comments

Comments
 (0)