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: Append the log message to build output if it's from compilation report. #1490

Merged
merged 2 commits into from
May 24, 2024
Merged
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 @@ -5,6 +5,7 @@
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -32,6 +33,7 @@
import ch.epfl.scala.bsp4j.MessageType;
import ch.epfl.scala.bsp4j.PublishDiagnosticsParams;
import ch.epfl.scala.bsp4j.ShowMessageParams;
import ch.epfl.scala.bsp4j.StatusCode;
import ch.epfl.scala.bsp4j.TaskDataKind;
import ch.epfl.scala.bsp4j.TaskFinishParams;
import ch.epfl.scala.bsp4j.TaskProgressParams;
Expand Down Expand Up @@ -60,6 +62,8 @@ public class GradleBuildClient implements BuildClient {

private final JavaLanguageClient lsClient;

private final LruCache<String> failedTaskCache = new LruCache<>(16);

public GradleBuildClient() {
this.lsClient = JavaLanguageServerPlugin.getProjectsManager().getConnection();
}
Expand All @@ -70,8 +74,12 @@ public void onBuildLogMessage(LogMessageParams params) {
if (type == MessageType.LOG) {
Utils.sendTelemetry(this.lsClient, params.getMessage());
} else {
this.lsClient.sendNotification(new ExecuteCommandParams(CLIENT_BUILD_LOG_CMD,
Arrays.asList(params.getMessage())));
String command = CLIENT_BUILD_LOG_CMD;
if (type == MessageType.ERROR && failedTaskCache.contains(params.getTask().getId())) {
// append the compilation failure message to the build output channel.
command = CLIENT_APPEND_BUILD_LOG_CMD;
}
this.lsClient.sendNotification(new ExecuteCommandParams(command, Arrays.asList(params.getMessage())));
}
}

Expand Down Expand Up @@ -154,6 +162,9 @@ public void onBuildTaskFinish(TaskFinishParams params) {
if (Objects.equals(params.getDataKind(), TaskDataKind.COMPILE_REPORT)) {
String msg = params.getMessage() + "\n------\n";
lsClient.sendNotification(new ExecuteCommandParams(CLIENT_APPEND_BUILD_LOG_CMD, Arrays.asList(msg)));
if (params.getStatus() == StatusCode.ERROR) {
failedTaskCache.addAll((params.getTaskId().getParents()));
}
} else {
Either<String, Integer> id = Either.forLeft(params.getTaskId().getId());
WorkDoneProgressEnd workDoneProgressEnd = new WorkDoneProgressEnd();
Expand All @@ -162,4 +173,22 @@ public void onBuildTaskFinish(TaskFinishParams params) {
lsClient.notifyProgress(new ProgressParams(id, Either.forLeft(workDoneProgressEnd)));
}
}

private class LruCache<T> extends LinkedHashSet<T> {
private final int maxSize;

public LruCache(int maxSize) {
super(maxSize);
this.maxSize = maxSize;
}

@Override
public boolean add(T element) {
if (size() >= maxSize) {
T oldestElement = iterator().next();
remove(oldestElement);
}
return super.add(element);
}
}
}
Loading