nvs dap
nvs dap is the debug adapter. Your editor starts it when you debug a program. You do not run it yourself.
In VS Code, you add a configuration of type nvs to .vscode/launch.json, or you start one from the Run and Debug view. The configuration names the .nvs file in program. mode is run, test or serve. The default is run.
While the program runs, you can set breakpoints and step through the code. A breakpoint can have a condition, a hit count or a log message. After a step out, the Variables view shows the value the function returned. Uncaught Exceptions stops the program at an exception that no catch handles.
While the program is stopped, the Novis Tasks view in Run and Debug shows each task under the task that started it. For example, the two functions you give to Core\Task::all are shown under the task that called it. Select a task to open its file at the line where it stopped.
What the program prints appears in the debug console as text.
Good to know: nvs dap only starts programs. It cannot attach to a program that is already running, so you cannot debug a production server.
Examples
A breakpoint in a loop
<?nvs// This program shows a loop where a breakpoint with a condition is useful.
int $total = 0;for (int $i = 1; $i <= 5; $i++) { // Set a breakpoint on the next line with the condition `$i == 3`. // The program stops once, and the Variables view shows `$total` is `3`. $total = $total + $i; // A log message `{$i}: {$total}` on this line prints each step in the debug console. echo $i, ' ', $total, "\n";}
echo 'total: ', $total, "\n";1 12 33 64 105 15total: 15The value a function returned
<?nvs// This program shows the value a function returns after you step out of it.
final class Price{ // The return type `int` is written, so the debugger shows the returned value. public static function withShipping(int $cents): int { int $shipping = 200; return $cents + $shipping; }}
// Step into `withShipping`, then step out. The Variables view shows `withShipping() returned` first.// Its value is `1200`.int $total = Price::withShipping(1000);echo $total, "\n";1200Stop at a throw
<?nvs// This program shows how the debugger stops at an exception that a `catch` handles.
final class Stock{ public static function take(int $have, int $want): int { if ($want > $have) { // With *All Exceptions* on, the program stops at this `throw`. // *Uncaught Exceptions* does not stop here, because the `catch` below handles it. throw new RuntimeError('not enough items in stock'); } return $have - $want; }}
echo Stock::take(10, 4), "\n";
try { echo Stock::take(2, 5), "\n";} catch (RuntimeError $error) { echo 'error: ', $error->message, "\n";}6error: not enough items in stock