Search code examples
powershellvisual-studio-code

VSCode Invisible Breakpoint?


When working in visual studio code...I've noticed that some files will always break into them when you're trying to step over them (this is a GIF by the way...click on it to see what I'm talking about in action). Basically

  • breakpoint a line
  • run & hit breakpoint
  • F10 over next line
  • function hits invisible breakpoint anyway
  • curses

InvisibleBreakpoint

This is not specific to any powershell or vscode version...this is something that has been happening in various files with various versions. I've just been too lazy to ask until now. ;)

Anyone have any clue? Cause ¯_(ツ)_/¯


Solution

  • I can't speak to the design rationale, if any, behind the behavior you've observed, but I can clarify when it occurs:

    • It is the fact that a parameter default value in the function being invoked uses @(...), the array-subexpression operator.

    • @(...) - unlike (...), the grouping operator - invariably creates a nested pipeline, which may underlie a potential design decision to consider the (first of the) enclosed statement(s) the next statement to break at.
      However, this is inconsistent with use of $(...), the subexpression operator, which also creates a nested pipeline while not exhibiting the same behavior.

    It is the PSES (PowerShell Editor Services) that underlie the PowerShell debugging experience in Visual Studio Code, via the latter's PowerShell extension.
    However, the behavior originates in PowerShell's built-in debugger itself, which the PSES build on.

    GitHub issue #24067 discusses this surprising behavior and shows a simple way to reproduce it.
    Should a fix be made, only future PowerShell (Core) 7 versions will benefit from it, not also the legacy Windows PowerShell edition (whose latest and last version is 5.1.x).