Skip to content

Commit

Permalink
Fixed #53 Add a way to print to the console from the debugger.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Feb 29, 2024
1 parent 73252cb commit 0db035a
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Type;
import java.net.URISyntaxException;
import java.util.ArrayList;
Expand Down Expand Up @@ -57,6 +58,7 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
Expand All @@ -66,6 +68,11 @@
import org.eclipse.lsp4e.LSPEclipseUtils;
import org.eclipse.swt.widgets.Display;

/**
* Debugger implementation for Acceleo.
*
* @author <a href="mailto:yvan.lussaud@obeo.fr">Yvan Lussaud</a>
*/
public class AcceleoDebugger extends AbstractDSLDebugger {

/**
Expand Down Expand Up @@ -96,6 +103,9 @@ public void run() {
.getResourceSet().getURIConverter(), new AcceleoWorkspaceURIWriterFactory());
AcceleoUtil.generate(evaluator, queryEnvironment, module, model, strategy,
getDestination(), logURI);
if (evaluator.getGenerationResult().getDiagnostic().getSeverity() != Diagnostic.OK) {
printDiagnostic(evaluator.getGenerationResult().getDiagnostic(), "");
}
}
} finally {
// FIXME workaround: UI jobs are coming from core.debug even if the gen has finished,
Expand Down Expand Up @@ -380,6 +390,9 @@ protected void generateNoDebug(IQualifiedNameQueryEnvironment environment, Modul
.getResourceSet().getURIConverter(), new AcceleoWorkspaceURIWriterFactory());
AcceleoUtil.generate(noDebugEvaluator, environment, module, modelResource, strategy, getDestination(),
logURI);
if (noDebugEvaluator.getGenerationResult().getDiagnostic().getSeverity() != Diagnostic.OK) {
printDiagnostic(noDebugEvaluator.getGenerationResult().getDiagnostic(), "");
}

if (profiler != null) {
try {
Expand Down Expand Up @@ -545,4 +558,39 @@ protected URI getDestination() {
return destination;
}

/**
* Prints the given {@link Diagnostic}.
*
* @param stream
* the {@link PrintStream}
* @param diagnostic
* the {@link Diagnostic}
* @param indentation
* the current indentation
*/
protected void printDiagnostic(Diagnostic diagnostic, String indentation) {
String nextIndentation = indentation;
if (diagnostic.getMessage() != null) {
consolePrint(indentation);
switch (diagnostic.getSeverity()) {
case Diagnostic.INFO:
consolePrint("INFO: ");
break;

case Diagnostic.WARNING:
consolePrint("WARNING: ");
break;

case Diagnostic.ERROR:
consolePrint("ERROR: ");
break;
}
consolePrint(diagnostic.getMessage() + newLine);
nextIndentation += "\t";
}
for (Diagnostic child : diagnostic.getChildren()) {
printDiagnostic(child, nextIndentation);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,19 @@ private static void printDiagnostic(IAcceleoWriter writer, Diagnostic diagnostic
String nextIndentation = indentation;
if (diagnostic.getMessage() != null) {
writer.append(indentation);
switch (diagnostic.getSeverity()) {
case Diagnostic.INFO:
writer.append("INFO: ");
break;

case Diagnostic.WARNING:
writer.append("WARNING: ");
break;

case Diagnostic.ERROR:
writer.append("ERROR: ");
break;
}
writer.append(diagnostic.getMessage() + newLine);
nextIndentation += "\t";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2023 Obeo.
* Copyright (c) 2020, 2024 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -24,6 +24,7 @@
import org.eclipse.acceleo.debug.DSLSource;
import org.eclipse.acceleo.debug.IDSLDebugger;
import org.eclipse.acceleo.debug.event.debugger.BreakpointReply;
import org.eclipse.acceleo.debug.event.debugger.ConsolePrintReply;
import org.eclipse.acceleo.debug.event.debugger.DeleteVariableReply;
import org.eclipse.acceleo.debug.event.debugger.ResumingReply;
import org.eclipse.acceleo.debug.event.debugger.SetCurrentInstructionReply;
Expand Down Expand Up @@ -897,6 +898,15 @@ protected void notifyClientSetVariableValueReply(SetVariableValueReply variableV
// TODO Auto-generated method stub
}

@Override
protected void notifyClientConsolePrintReply(ConsolePrintReply consolePrintReply) {
final OutputEventArguments arg = new OutputEventArguments();

arg.setOutput(consolePrintReply.getText());

client.output(arg);
}

@Override
protected void notifyClientSetCurrentInstructionReply(
SetCurrentInstructionReply setCurrentInstructionReply) {
Expand Down

0 comments on commit 0db035a

Please sign in to comment.