Skip to content

Commit 27d64e8

Browse files
authored
add filepath to resolve main class for better options to vscode side. (#171)
1 parent 4660b0e commit 27d64e8

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313

1414
import java.util.ArrayList;
1515
import java.util.List;
16+
import java.util.Objects;
1617
import java.util.logging.Level;
1718
import java.util.logging.Logger;
1819
import java.util.stream.Collectors;
1920

21+
import org.eclipse.core.resources.IFile;
2022
import org.eclipse.core.resources.IProject;
2123
import org.eclipse.core.resources.IResource;
2224
import org.eclipse.core.runtime.CoreException;
@@ -85,7 +87,16 @@ public void acceptSearchMatch(SearchMatch match) {
8587
if (projectName == null
8688
|| targetProjectPath.isEmpty()
8789
|| ResourceUtils.isContainedIn(project.getLocation(), targetProjectPath)) {
88-
res.add(new ResolutionItem(mainClass, projectName));
90+
String filePath = null;
91+
92+
if (match.getResource() instanceof IFile) {
93+
try {
94+
filePath = match.getResource().getLocation().toOSString();
95+
} catch (Exception ex) {
96+
// ignore
97+
}
98+
}
99+
res.add(new ResolutionItem(mainClass, projectName, filePath));
89100
}
90101
}
91102
}
@@ -109,10 +120,12 @@ public void acceptSearchMatch(SearchMatch match) {
109120
private class ResolutionItem {
110121
private String mainClass;
111122
private String projectName;
123+
private String filePath;
112124

113-
public ResolutionItem(String mainClass, String projectName) {
125+
public ResolutionItem(String mainClass, String projectName, String filePath) {
114126
this.mainClass = mainClass;
115127
this.projectName = projectName;
128+
this.filePath = filePath;
116129
}
117130

118131
@Override
@@ -122,20 +135,16 @@ public boolean equals(Object o) {
122135
}
123136
if (o instanceof ResolutionItem) {
124137
ResolutionItem item = (ResolutionItem) o;
125-
if (mainClass != null ? !mainClass.equals(item.mainClass) : item.mainClass != null) {
126-
return false;
127-
}
128-
if (projectName != null ? !projectName.equals(item.projectName) : item.projectName != null) {
129-
return false;
130-
}
131-
return true;
138+
return Objects.equals(mainClass, item.mainClass)
139+
&& Objects.equals(projectName, item.projectName)
140+
&& Objects.equals(filePath, item.filePath);
132141
}
133142
return false;
134143
}
135144

136145
@Override
137146
public int hashCode() {
138-
return (mainClass == null ? 0 : mainClass.hashCode()) * 13 + (projectName == null ? 0 : projectName.hashCode());
147+
return Objects.hash(mainClass, projectName, filePath);
139148
}
140149
}
141150
}

0 commit comments

Comments
 (0)