Signed-off-by: Sheng Chen <sheche@microsoft.com>
This commit is contained in:
Sheng Chen 2023-08-04 09:20:59 +08:00
Родитель 7fe5ca7327
Коммит fb2b42b7d6
2 изменённых файлов: 36 добавлений и 3 удалений

Просмотреть файл

@ -14,6 +14,7 @@ import org.eclipse.jdt.ls.core.internal.JavaClientConnection.JavaLanguageClient;
import ch.epfl.scala.bsp4j.BuildClient;
import ch.epfl.scala.bsp4j.DidChangeBuildTarget;
import ch.epfl.scala.bsp4j.LogMessageParams;
import ch.epfl.scala.bsp4j.MessageType;
import ch.epfl.scala.bsp4j.PublishDiagnosticsParams;
import ch.epfl.scala.bsp4j.ShowMessageParams;
import ch.epfl.scala.bsp4j.TaskDataKind;
@ -23,7 +24,21 @@ import ch.epfl.scala.bsp4j.TaskStartParams;
public class GradleBuildClient implements BuildClient {
/**
* Client command to append build logs to the output channel.
*/
private static final String CLIENT_APPEND_BUILD_LOG_CMD = "_java.gradle.buildServer.appendBuildLog";
/**
* Client command to append event logs to the output channel.
*/
private static final String CLIENT_BUILD_LOG_CMD = "_java.gradle.buildServer.log";
/**
* Client command to send telemetry data to the LS client.
*/
private static final String CLIENT_BUILD_SEND_TELEMETRY = "_java.gradle.buildServer.sendTelemetry";
private ConcurrentHashMap<String, ProgressReport> taskMap = new ConcurrentHashMap<>();
private final JavaLanguageClient lsClient;
@ -33,9 +48,10 @@ public class GradleBuildClient implements BuildClient {
}
@Override
public void onBuildLogMessage(LogMessageParams arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'onBuildLogMessage'");
public void onBuildLogMessage(LogMessageParams params) {
MessageType type = params.getType();
String cmd = type == MessageType.LOG ? CLIENT_BUILD_SEND_TELEMETRY : CLIENT_BUILD_LOG_CMD;
this.lsClient.sendNotification(new ExecuteCommandParams(cmd, Arrays.asList(params.getMessage())));
}
@Override

Просмотреть файл

@ -1,13 +1,19 @@
import { Disposable, ExtensionContext, OutputChannel, commands, languages, window } from "vscode";
import { GradleBuildLinkProvider } from "./GradleBuildLinkProvider";
import { sendInfo } from "vscode-extension-telemetry-wrapper";
const APPEND_BUILD_LOG_CMD = "_java.gradle.buildServer.appendBuildLog";
const LOG_CMD = "_java.gradle.buildServer.log";
const SEND_TELEMETRY_CMD = "_java.gradle.buildServer.sendTelemetry";
export class BuildServerController implements Disposable {
private disposable: Disposable;
private buildOutputChannel: OutputChannel;
private logOutputChannel: OutputChannel;
public constructor(readonly context: ExtensionContext) {
this.buildOutputChannel = window.createOutputChannel("Build Server for Gradle (Build)", "gradle-build");
this.logOutputChannel = window.createOutputChannel("Build Server for Gradle (Log)");
this.disposable = Disposable.from(
this.buildOutputChannel,
languages.registerDocumentLinkProvider({ language: "gradle-build", scheme: 'output' }, new GradleBuildLinkProvider()),
@ -19,6 +25,17 @@ export class BuildServerController implements Disposable {
}
}
}),
this.logOutputChannel,
commands.registerCommand(LOG_CMD, (msg: string) => {
if (msg) {
this.logOutputChannel.appendLine(msg);
}
}),
commands.registerCommand(SEND_TELEMETRY_CMD, (jsonString: string) => {
const log = JSON.parse(jsonString);
sendInfo("", log);
}),
);
}