Skip to content

Commit a3abd05

Browse files
authored
fix: Better handling the import error hint (#747)
1 parent b3c8565 commit a3abd05

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,25 +296,29 @@ public static String getModuleName(IJavaProject project) {
296296

297297
public static boolean checkImportStatus() {
298298
IProject[] projects = ProjectUtils.getAllProjects();
299+
boolean hasError = false;
299300
for (IProject project : projects) {
300301
if (ProjectsManager.DEFAULT_PROJECT_NAME.equals(project.getName())) {
301302
continue;
302303
}
304+
305+
// if a Java project found, we think it as success import now.
306+
if (ProjectUtils.isJavaProject(project)) {
307+
return false;
308+
}
309+
303310
try {
304-
List<IMarker> markers = ResourceUtils.getErrorMarkers(project);
305-
if (markers != null) {
306-
boolean hasError = markers.stream().anyMatch(m -> {
307-
return m.getAttribute(IMarker.SEVERITY, 0) == IMarker.SEVERITY_ERROR;
308-
});
309-
if (hasError) {
310-
return true;
311-
}
311+
int maxProblemSeverity = project.findMaxProblemSeverity(null, true, IResource.DEPTH_ONE);
312+
if (maxProblemSeverity == IMarker.SEVERITY_ERROR) {
313+
hasError = true;
314+
break;
312315
}
313316
} catch (CoreException e) {
314317
JdtlsExtActivator.log(e);
315318
}
316319
}
317-
return false;
320+
321+
return hasError;
318322
}
319323

320324
private static void reportExportJarMessage(String terminalId, int severity, String message) {

src/views/dependencyDataProvider.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
173173
return this._rootItems;
174174
}
175175

176+
const hasJavaError: boolean = await Jdtls.checkImportStatus();
177+
if (hasJavaError) {
178+
contextManager.setContextValue(Context.IMPORT_FAILED, true);
179+
return [];
180+
}
181+
176182
const rootItems: ExplorerNode[] = [];
177183
const folders = workspace.workspaceFolders;
178184
if (folders && folders.length) {
@@ -192,12 +198,7 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
192198
}
193199
}
194200
if (_.isEmpty(rootItems)) {
195-
const hasJavaError: boolean = await Jdtls.checkImportStatus();
196-
if (hasJavaError) {
197-
contextManager.setContextValue(Context.IMPORT_FAILED, true);
198-
} else {
199-
contextManager.setContextValue(Context.NO_JAVA_PROJECT, true);
200-
}
201+
contextManager.setContextValue(Context.NO_JAVA_PROJECT, true);
201202
}
202203
return rootItems;
203204
} finally {

0 commit comments

Comments
 (0)