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

Inform clients when Preview support enabled for an incompatible version. #3137

Merged
merged 1 commit into from
Aug 14, 2024
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 @@ -40,7 +40,12 @@ public enum EventType {
/**
* Source attachments have been updated for some jar libraries.
*/
SourceInvalidated(500);
SourceInvalidated(500),

/**
* Incompatibility between release version and preview features
*/
PreviewFeaturesNotAllowed(600);

private final int value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public BuildWorkspaceStatus buildWorkspace(boolean forceReBuild, IProgressMonito
if (errors.isEmpty()) {
return BuildWorkspaceStatus.SUCCEED;
} else {
WorkspaceDiagnosticsHandler.checkPreviewFeatureValidity(problemMarkers);
// for default project, problem markers aren't sent. Add logs here for trouble shooting.
String newline = System.getProperty("line.separator");
logError("Error occured while building workspace. Details: " + newline + String.join(newline, errors));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.ls.core.internal.EventNotification;
import org.eclipse.jdt.ls.core.internal.EventType;
import org.eclipse.jdt.ls.core.internal.JDTUtils;
import org.eclipse.jdt.ls.core.internal.JavaClientConnection;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
Expand All @@ -62,6 +64,9 @@
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.internal.Messages;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

/**
* Listens to the resource change events and converts {@link IMarker}s to {@link Diagnostic}s.
*
Expand Down Expand Up @@ -342,6 +347,31 @@ private void publishDiagnostics(List<IMarker> markers) {
connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), diagnostics));
}
}

checkPreviewFeatureValidity(markers);
}

public static void checkPreviewFeatureValidity(List<IMarker> problemMarkers) {
// Preview feature support enabled on incompatible release version
List<IMarker> previewFeatureMarkers = problemMarkers.stream().filter(m -> m.getAttribute(IJavaModelMarker.ID, 0) == IProblem.PreviewFeaturesNotAllowed).collect(Collectors.toList());
JsonArray errorList = new JsonArray();
if (!previewFeatureMarkers.isEmpty()) {
for (IMarker marker : previewFeatureMarkers) {
// error message mentions invalid release level, and the supported level
String errorMessage = ResourceUtils.getMessage(marker);
String projectUri = JDTUtils.getFileURI(marker.getResource().getProject());
JsonObject entry = new JsonObject();
entry.addProperty("uri", projectUri);
entry.addProperty("message", errorMessage);
if (!errorList.contains(entry)) {
errorList.add(entry);
}
}
if (JavaLanguageServerPlugin.getProjectsManager().getConnection() != null) {
EventNotification prevFeatNotAllowedNotification = new EventNotification().withType(EventType.PreviewFeaturesNotAllowed).withData(errorList);
JavaLanguageServerPlugin.getProjectsManager().getConnection().sendEventNotification(prevFeatNotAllowedNotification);
}
}
}

@Deprecated
Expand Down
Loading