From 768cd6fda1ab71642bb4129505780b1a539599cb Mon Sep 17 00:00:00 2001
From: dgelessus <dgelessus@users.noreply.github.com>
Date: Wed, 9 Sep 2020 15:56:35 +0200
Subject: [PATCH] Fix error highlighting being applied to external files

At the moment error highlighting is only supported for the
machine/formula in the current cell.
---
 src/main/java/de/prob2/jupyter/ProBKernel.java               | 3 ++-
 src/main/java/de/prob2/jupyter/commands/LoadCellCommand.java | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/main/java/de/prob2/jupyter/ProBKernel.java b/src/main/java/de/prob2/jupyter/ProBKernel.java
index be18d8a..57a2a23 100644
--- a/src/main/java/de/prob2/jupyter/ProBKernel.java
+++ b/src/main/java/de/prob2/jupyter/ProBKernel.java
@@ -124,6 +124,7 @@ public final class ProBKernel extends BaseKernel {
 	
 	private static final @NotNull Logger LOGGER = LoggerFactory.getLogger(ProBKernel.class);
 	
+	public static final String LOAD_CELL_MACHINE_NAME = "(machine from Jupyter cell)";
 	private static final @NotNull Pattern COMMAND_PATTERN = Pattern.compile("\\s*(\\:[^\\s]*)(?:\\h*(.*))?", Pattern.DOTALL);
 	private static final @NotNull Pattern MACHINE_CODE_PATTERN = Pattern.compile("MACHINE\\W.*", Pattern.DOTALL);
 	private static final @NotNull Pattern BSYMB_COMMAND_PATTERN = Pattern.compile("\\\\([a-z]+)");
@@ -617,7 +618,7 @@ public final class ProBKernel extends BaseKernel {
 	}
 	
 	private @NotNull List<@NotNull String> formatErrorSource(final @NotNull List<@NotNull String> sourceLines, final @NotNull ErrorItem.Location location) {
-		if (sourceLines.isEmpty()) {
+		if (sourceLines.isEmpty() || (!location.getFilename().isEmpty() && !Paths.get(location.getFilename()).getFileName().toString().equals(LOAD_CELL_MACHINE_NAME + ".mch"))) {
 			return Collections.singletonList(this.errorStyler.primary("// Source code not known"));
 		}
 		
diff --git a/src/main/java/de/prob2/jupyter/commands/LoadCellCommand.java b/src/main/java/de/prob2/jupyter/commands/LoadCellCommand.java
index b0525f6..b9661e7 100644
--- a/src/main/java/de/prob2/jupyter/commands/LoadCellCommand.java
+++ b/src/main/java/de/prob2/jupyter/commands/LoadCellCommand.java
@@ -80,7 +80,7 @@ public final class LoadCellCommand implements Command {
 		this.proBKernelProvider.get().switchMachine(Paths.get(""), stateSpace -> {
 			stateSpace.changePreferences(preferences);
 			CommandUtils.withSourceCode(body, () ->
-				this.classicalBFactory.create("(machine from Jupyter cell)", body).loadIntoStateSpace(stateSpace)
+				this.classicalBFactory.create(ProBKernel.LOAD_CELL_MACHINE_NAME, body).loadIntoStateSpace(stateSpace)
 			);
 			return new Trace(stateSpace);
 		});
-- 
GitLab