Skip to content

Commit

Permalink
Inform clients when Preview support enabled for an incompatible version.
Browse files Browse the repository at this point in the history
Signed-off-by: Roland Grunberg <[email protected]>
  • Loading branch information
rgrunber committed Aug 14, 2024
1 parent 0375248 commit cc5a6d6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
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

0 comments on commit cc5a6d6

Please sign in to comment.