Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Better handling the import error hint #747

Merged
merged 2 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -296,25 +296,29 @@ public static String getModuleName(IJavaProject project) {

public static boolean checkImportStatus() {
IProject[] projects = ProjectUtils.getAllProjects();
boolean hasError = false;
for (IProject project : projects) {
if (ProjectsManager.DEFAULT_PROJECT_NAME.equals(project.getName())) {
continue;
}

// if a Java project found, we think it as success import now.
if (ProjectUtils.isJavaProject(project)) {
return false;
}

try {
List<IMarker> markers = ResourceUtils.getErrorMarkers(project);
if (markers != null) {
boolean hasError = markers.stream().anyMatch(m -> {
return m.getAttribute(IMarker.SEVERITY, 0) == IMarker.SEVERITY_ERROR;
});
if (hasError) {
return true;
}
int maxProblemSeverity = project.findMaxProblemSeverity(null, true, IResource.DEPTH_ONE);
if (maxProblemSeverity == IMarker.SEVERITY_ERROR) {
hasError = true;
break;
}
} catch (CoreException e) {
JdtlsExtActivator.log(e);
}
}
return false;

return hasError;
}

private static void reportExportJarMessage(String terminalId, int severity, String message) {
Expand Down
13 changes: 7 additions & 6 deletions src/views/dependencyDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
return this._rootItems;
}

const hasJavaError: boolean = await Jdtls.checkImportStatus();
if (hasJavaError) {
contextManager.setContextValue(Context.IMPORT_FAILED, true);
return [];
}

const rootItems: ExplorerNode[] = [];
const folders = workspace.workspaceFolders;
if (folders && folders.length) {
Expand All @@ -192,12 +198,7 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
}
}
if (_.isEmpty(rootItems)) {
const hasJavaError: boolean = await Jdtls.checkImportStatus();
if (hasJavaError) {
contextManager.setContextValue(Context.IMPORT_FAILED, true);
} else {
contextManager.setContextValue(Context.NO_JAVA_PROJECT, true);
}
contextManager.setContextValue(Context.NO_JAVA_PROJECT, true);
}
return rootItems;
} finally {
Expand Down