UndertaleModTool
UndertaleModTool copied to clipboard
Add #line directive when running scripts
According to https://www.michalkomorowski.com/2016/10/roslyn-how-to-create-custom-debuggable_27.html, we can add #line directive to let the debugger know where the exception occurs
Before, the debugger doesn't point to the exact line in the custom script:

After, now the line is highlighted:

Can you add this to the CLI as well?
🤯
I've tried to make it work like this some time ago, but I've only managed to make it emit a debug info, so you can see the stacktrace of an exception in the error message box, and the code context (see "Locals" window at the bottom of the screenshots).
Added to CLI as well
Before:
Trying to load file: 'C:\Users\User\Desktop\game.ios'
System.NullReferenceException: Object reference not set to an instance of an object.
at Submission#0.addObjCustomDog() in :line 61
at Submission#0.<<Initialize>>d__0.MoveNext() in :line 23
--- End of stack trace from previous location ---
at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Scripting.Script`1.RunSubmissionsAsync(ScriptExecutionState executionState, ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Scripting.ScriptStateTaskExtensions.GetEvaluationResultAsync[T](Task`1 task)
at UndertaleModCli.Program.RunCSharpCode(String code, String scriptFile) in C:\Users\User\source\repos\UndertaleModTool\UndertaleModCli\Program.cs:line 724
After:
Trying to load file: 'C:\Users\User\Desktop\game.ios'
System.NullReferenceException: Object reference not set to an instance of an object.
at Submission#0.addObjCustomDog() in C:\Users\User\source\repos\UndertaleModTool\UndertaleModTool\Scripts\Community Scripts\AddObjCustomDog.csx:line 61
at Submission#0.<<Initialize>>d__0.MoveNext() in C:\Users\User\source\repos\UndertaleModTool\UndertaleModTool\Scripts\Community Scripts\AddObjCustomDog.csx:line 23
--- End of stack trace from previous location ---
at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Scripting.Script`1.RunSubmissionsAsync(ScriptExecutionState executionState, ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Scripting.ScriptStateTaskExtensions.GetEvaluationResultAsync[T](Task`1 task)
at UndertaleModCli.Program.RunCSharpCode(String code, String scriptFile) in C:\Users\User\source\repos\UndertaleModTool\UndertaleModCli\Program.cs:line 724