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 for extra whitespace around info messages #1879

Merged
merged 2 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions cli/base/src/main/java/org/lflang/cli/CliBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,19 @@ public void validateResource(Resource resource) {
try {
path = FileUtil.toPath(uri);
} catch (IllegalArgumentException e) {
reporter.printError("Unable to convert '" + uri + "' to path." + e);
reporter.printError("Unable to convert '" + uri + "' to path. " + e);
}
}
issueCollector.accept(
new LfIssue(
issue.getMessage(),
issue.getSeverity(),
path,
issue.getLineNumber(),
issue.getColumn(),
issue.getLineNumberEnd(),
issue.getColumnEnd(),
issue.getLength(),
path));
issue.getLength()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@
public class StandaloneIssueAcceptor implements ValidationMessageAcceptor {

@Inject private IssueCollector collector;
@Inject private ReportingBackend backend;

boolean getErrorsOccurred() {
return collector.getErrorsOccurred();
}

void accept(LfIssue lfIssue) {
collector.accept(lfIssue);
if (lfIssue.getSeverity() == Severity.INFO) {
// print info statements instead of collecting them
backend.printIssue(lfIssue);
} else {
collector.accept(lfIssue);
}
}

void accept(
Expand All @@ -37,12 +43,12 @@ void accept(
new LfIssue(
message,
severity,
getPath(diagnostic),
diagnostic.getLine(),
diagnostic.getColumn(),
diagnostic.getLineEnd(),
diagnostic.getColumnEnd(),
diagnostic.getLength(),
getPath(diagnostic));
diagnostic.getLength());

accept(lfIssue);
}
Expand Down
27 changes: 13 additions & 14 deletions cli/base/src/main/kotlin/org/lflang/cli/ReportingUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ class Io @JvmOverloads constructor(
data class LfIssue(
val message: String,
val severity: Severity,
val line: Int?,
val column: Int?,
val endLine: Int?,
val endColumn: Int?,
val length: Int?,
val file: Path?
val file: Path? = null,
val line: Int? = null,
val column: Int? = null,
val endLine: Int? = null,
val endColumn: Int? = null,
val length: Int? = null,
) : Comparable<LfIssue> {

constructor(
Expand Down Expand Up @@ -199,7 +199,7 @@ class IssueCollector {
*
* @author Clément Fournier
*/
class ReportingBackend constructor(
class ReportingBackend(
/** Environment of the process, contains IO streams. */
private val io: Io,
/** Header for all messages. */
Expand Down Expand Up @@ -253,18 +253,18 @@ class ReportingBackend constructor(

/** Print an error message to [Io.err]. */
fun printError(message: String) {
io.err.println(header + colors.redAndBold("error: ") + message)
printIssue(LfIssue(message, Severity.ERROR))
errorsOccurred = true
}

/** Print a warning message to [Io.err]. */
fun printWarning(message: String) {
io.err.println(header + colors.yellowAndBold("warning: ") + message)
printIssue(LfIssue(message, Severity.WARNING))
}

/** Print an informational message to [Io.out]. */
fun printInfo(message: String) {
io.out.println(header + colors.bold("info: ") + message)
printIssue(LfIssue(message, Severity.INFO))
}

/**
Expand All @@ -277,18 +277,17 @@ class ReportingBackend constructor(

val header = severity.name.lowercase(Locale.ROOT)

var fullMessage: String = this.header + colors.severityColors(header, severity) + colors.bold(": " + issue.message) + System.lineSeparator()
var fullMessage: String = this.header + colors.severityColors(header, severity) + colors.bold(": " + issue.message)
val snippet: String? = filePath?.let { formatIssue(issue, filePath) }

if (snippet == null) {
filePath?.let { io.wd.relativize(it) }?.let {
fullMessage += " --> " + it + ":" + issue.line + ":" + issue.column + " - "
fullMessage += "\n --> " + it + ":" + issue.line + ":" + issue.column + " - \n"
}
} else {
fullMessage += snippet
fullMessage += "\n" + snippet + "\n"
}
io.err.println(fullMessage)
io.err.println()
}

private fun formatIssue(issue: LfIssue, path: Path): String? {
Expand Down
2 changes: 1 addition & 1 deletion cli/lfc/src/main/java/org/lflang/cli/Lfc.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private void invokeGenerator(List<Path> files, Path root, Properties properties)
// Print all other issues (not errors).
issueCollector.getAllIssues().forEach(reporter::printIssue);

this.io.getOut().println("Code generation finished.");
messageReporter.nowhere().info("Code generation finished.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion cli/lff/src/test/java/org/lflang/cli/LffCliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void testFormatDirectoryVerbose(@TempDir Path tempDir) throws IOException

result.checkOk();

result.checkStdOut(containsString("Formatted src" + File.separator + "File.lf"));
result.checkStdErr(containsString("Formatted src" + File.separator + "File.lf"));
dirChecker(tempDir).checkContentsOf("src/File.lf", equalTo(FILE_AFTER_REFORMAT));
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/lflang/generator/GeneratorBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,10 @@ public void printInfo(LFGeneratorContext.Mode mode) {
messageReporter
.nowhere()
.info("Generating code for: " + context.getFileConfig().resource.getURI().toString());
messageReporter.nowhere().info("******** mode: " + mode);
messageReporter.nowhere().info("Generation mode: " + mode);
messageReporter
.nowhere()
.info("******** generated sources: " + context.getFileConfig().getSrcGenPath());
.info("Generating sources into: " + context.getFileConfig().getSrcGenPath());
}

/** Get the buffer type used for network messages */
Expand Down