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

Multilined Conditional + Order Debug Fix #7431

Open
wants to merge 5 commits into
base: dev/feature
Choose a base branch
from
Open
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
32 changes: 14 additions & 18 deletions src/main/java/ch/njol/skript/ScriptLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.Statement;
import ch.njol.skript.lang.TriggerItem;
import ch.njol.skript.lang.TriggerSection;
import ch.njol.skript.lang.function.EffFunctionCall;
import ch.njol.skript.lang.parser.ParserInstance;
import ch.njol.skript.log.*;
import ch.njol.skript.sections.SecLoop;
import ch.njol.skript.log.CountingLogHandler;
import ch.njol.skript.log.LogEntry;
import ch.njol.skript.log.RetainingLogHandler;
import ch.njol.skript.log.SkriptLogger;
import ch.njol.skript.structures.StructOptions.OptionsData;
import ch.njol.skript.test.runner.TestMode;
import ch.njol.skript.util.ExceptionUtils;
import ch.njol.skript.util.SkriptColor;
import ch.njol.skript.util.Task;
import ch.njol.skript.util.Timespan;
import ch.njol.skript.variables.TypeHints;
import ch.njol.util.Kleenean;
import ch.njol.util.NonNullPair;
import ch.njol.util.OpenCloseable;
import ch.njol.util.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.script.Script;
Expand All @@ -41,11 +39,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -968,7 +962,7 @@ public static ArrayList<TriggerItem> loadItems(SectionNode node) {
if (!SkriptParser.validateLine(expr))
continue;

TriggerItem item;
TriggerItem item = null;
if (subNode instanceof SimpleNode) {
long start = System.currentTimeMillis();
item = Statement.parse(expr, items, "Can't understand this condition/effect: " + expr);
Expand All @@ -988,21 +982,21 @@ public static ArrayList<TriggerItem> loadItems(SectionNode node) {
Skript.debug(SkriptColor.replaceColorChar(parser.getIndentation() + item.toString(null, true)));

items.add(item);
} else if (subNode instanceof SectionNode) {
} else if (subNode instanceof SectionNode subSection) {
TypeHints.enterScope(); // Begin conditional type hints

RetainingLogHandler handler = SkriptLogger.startRetainingLog();
find_section:
try {
item = Section.parse(expr, "Can't understand this section: " + expr, (SectionNode) subNode, items);
item = Section.parse(expr, "Can't understand this section: " + expr, subSection, items);
if (item != null)
break find_section;

// back up the failure log
RetainingLogHandler backup = handler.backup();
handler.clear();

item = Statement.parse(expr, "Can't understand this condition/effect: " + expr, (SectionNode) subNode, items);
item = Statement.parse(expr, "Can't understand this condition/effect: " + expr, subSection, items);

if (item != null)
break find_section;
Expand All @@ -1019,12 +1013,14 @@ public static ArrayList<TriggerItem> loadItems(SectionNode node) {
}
continue;
} finally {
RetainingLogHandler afterParse = handler.backup();
handler.clear();
handler.printLog();
if (item != null && (Skript.debug() || subNode.debug()))
Skript.debug(SkriptColor.replaceColorChar(parser.getIndentation() + item.toString(null, true)));
afterParse.printLog();
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}

if (Skript.debug() || subNode.debug())
Skript.debug(SkriptColor.replaceColorChar(parser.getIndentation() + item.toString(null, true)));

items.add(item);

// Destroy these conditional type hints
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/ch/njol/skript/sections/SecConditional.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import ch.njol.skript.patterns.PatternCompiler;
import ch.njol.skript.patterns.SkriptPattern;
import ch.njol.skript.util.Patterns;
import ch.njol.skript.util.SkriptColor;
import ch.njol.util.Kleenean;
import com.google.common.collect.Iterables;
import org.bukkit.event.Event;
Expand Down Expand Up @@ -203,6 +204,17 @@ public boolean init(Expression<?>[] exprs,
if (conditionals.isEmpty())
return false;

/*
This allows the embedded multilined conditions to be properly debugged.
Debugs are caught within the RetainingLogHandler in ScriptLoader#loadItems
Which will be printed after the debugged section (e.g 'if all')
*/
if ((Skript.debug() || sectionNode.debug()) && conditionals.size() > 1) {
String indentation = getParser().getIndentation() + " ";
for (Conditional<?> condition : conditionals)
Skript.debug(indentation + SkriptColor.replaceColorChar(condition.toString(null, true)));
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}

conditional = Conditional.compound(ifAny ? Operator.OR : Operator.AND, conditionals);
}

Expand Down
Loading