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 LS fast-run to show compiler diagnostics and fail-fast on compilation errors #43735

Prev Previous commit
Make restart requests synchronous
NipunaRanasinghe committed Jan 9, 2025
commit cbab642d3ec1bb8f6a4eb850e36b9fdbf1077155
Original file line number Diff line number Diff line change
@@ -449,23 +449,21 @@

@Override
public CompletableFuture<Void> restart(RestartArguments args) {
return CompletableFuture.supplyAsync(() -> {
if (context.getDebugMode() == ExecutionContext.DebugMode.ATTACH) {
outputLogger.sendErrorOutput("Restart operation is not supported in remote debug mode.");
return null;
}
if (context.getDebugMode() == ExecutionContext.DebugMode.ATTACH) {
outputLogger.sendErrorOutput("Restart operation is not supported in remote debug mode.");

Check warning on line 453 in misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java

Codecov / codecov/patch

misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java#L453

Added line #L453 was not covered by tests
return CompletableFuture.completedFuture(null);
}

try {
resetServer();
launchDebuggeeProgram();
} catch (Exception e) {
LOGGER.error("Failed to restart the Ballerina program due to: {}", e.getMessage(), e);
outputLogger.sendErrorOutput("Failed to restart the Ballerina program");
terminateDebugSession(context.getDebuggeeVM() != null, true);
}
try {
resetServer();
launchDebuggeeProgram();
} catch (Exception e) {
LOGGER.error("Failed to restart the Ballerina program due to: {}", e.getMessage(), e);
outputLogger.sendErrorOutput("Failed to restart the Ballerina program");

Check warning on line 462 in misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java

Codecov / codecov/patch

misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java#L461-L462

Added lines #L461 - L462 were not covered by tests
terminateDebugSession(context.getDebuggeeVM() != null, true);
}

return null;
});
return CompletableFuture.completedFuture(null);
}

private void launchDebuggeeProgram() throws Exception {

Unchanged files with check annotations Beta

Process process = runResult.process();
if (Objects.isNull(process)) {
return false;

Check warning on line 91 in language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/executors/RunExecutor.java

Codecov / codecov/patch

language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/executors/RunExecutor.java#L91

Added line #L91 was not covered by tests
}
listenOutputAsync(context.getLanguageClient(), process::getInputStream, OUT_CHANNEL);
listenOutputAsync(context.getLanguageClient(), process::getErrorStream, ERROR_CHANNEL);
return true;
} catch (BLangCompilerException e) {
LogTraceParams error = new LogTraceParams(e.getMessage(), ERROR_CHANNEL);
context.getLanguageClient().logTrace(error);

Check warning on line 99 in language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/executors/RunExecutor.java

Codecov / codecov/patch

language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/executors/RunExecutor.java#L97-L99

Added lines #L97 - L99 were not covered by tests
} catch (IOException e) {
LogTraceParams error = new LogTraceParams("Error while running the program in fast-run mode: " +
e.getMessage(), ERROR_CHANNEL);
e.getMessage(), ERROR_CHANNEL);
context.getLanguageClient().logTrace(error);
}
return false;

Check warning on line 109 in language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/executors/RunExecutor.java

Codecov / codecov/patch

language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/executors/RunExecutor.java#L109

Added line #L109 was not covered by tests
}
private RunContext getWorkspaceRunContext(ExecuteCommandContext context) {
Path projectRoot = projectRoot(executionContext.balSourcePath());
Optional<ProjectContext> projectContext = validateProjectContext(projectRoot);
if (projectContext.isEmpty()) {
return new RunResult(null, Collections.emptyList());

Check warning on line 604 in language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java

Codecov / codecov/patch

language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java#L604

Added line #L604 was not covered by tests
}
if (!stopProject(projectContext.get())) {
logError("Run command execution aborted because couldn't stop the previous run");
return new RunResult(null, Collections.emptyList());

Check warning on line 609 in language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java

Codecov / codecov/patch

language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java#L608-L609

Added lines #L608 - L609 were not covered by tests
}
Project project = projectContext.get().project();
Optional<PackageCompilation> packageCompilation = waitAndGetPackageCompilation(project.sourceRoot(), true);
if (packageCompilation.isEmpty()) {
logError("Run command execution aborted because package compilation failed");
return new RunResult(null, Collections.emptyList());

Check warning on line 616 in language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java

Codecov / codecov/patch

language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java#L615-L616

Added lines #L615 - L616 were not covered by tests
}
JBallerinaBackend jBallerinaBackend = execBackend(projectContext.get(), packageCompilation.get());