@@ -87,7 +87,7 @@ protected Task LaunchScript(RequestContext<object> requestContext)
87
87
// Is this an untitled script?
88
88
Task launchTask = null ;
89
89
90
- if ( this . scriptToLaunch . StartsWith ( "untitled:" ) )
90
+ if ( ScriptFile . IsUntitledPath ( this . scriptToLaunch ) )
91
91
{
92
92
ScriptFile untitledScript =
93
93
this . editorSession . Workspace . GetFile (
@@ -259,12 +259,12 @@ protected async Task HandleLaunchRequest(
259
259
260
260
// When debugging an "untitled" (unsaved) file - the working dir can't be derived
261
261
// from the Script path. OTOH, if the launch params specifies a Cwd, use it.
262
- if ( workingDir . StartsWith ( "untitled:" ) && string . IsNullOrEmpty ( launchParams . Cwd ) )
262
+ if ( ScriptFile . IsUntitledPath ( workingDir ) && string . IsNullOrEmpty ( launchParams . Cwd ) )
263
263
{
264
264
workingDir = null ;
265
265
}
266
266
267
- if ( workingDir != null )
267
+ if ( ! string . IsNullOrEmpty ( workingDir ) )
268
268
{
269
269
workingDir = PowerShellContext . UnescapePath ( workingDir ) ;
270
270
try
@@ -282,7 +282,7 @@ protected async Task HandleLaunchRequest(
282
282
}
283
283
}
284
284
285
- if ( workingDir == null )
285
+ if ( string . IsNullOrEmpty ( workingDir ) )
286
286
{
287
287
#if CoreCLR
288
288
workingDir = AppContext . BaseDirectory ;
@@ -490,7 +490,12 @@ protected async Task HandleSetBreakpointsRequest(
490
490
// VSCode sends breakpoint requests with the original filename that doesn't exist anymore.
491
491
try
492
492
{
493
- scriptFile = editorSession . Workspace . GetFile ( setBreakpointsParams . Source . Path ) ;
493
+ // When you set a breakpoint in the right pane of a Git diff window on a PS1 file,
494
+ // the Source.Path comes through as Untitled-X.
495
+ if ( ! ScriptFile . IsUntitledPath ( setBreakpointsParams . Source . Path ) )
496
+ {
497
+ scriptFile = editorSession . Workspace . GetFile ( setBreakpointsParams . Source . Path ) ;
498
+ }
494
499
}
495
500
catch ( Exception e ) when ( e is FileNotFoundException || e is DirectoryNotFoundException )
496
501
{
@@ -510,9 +515,34 @@ await requestContext.SendResult(
510
515
Breakpoints = srcBreakpoints . ToArray ( )
511
516
} ) ;
512
517
513
- return ;
514
- }
518
+ return ;
519
+ }
520
+
521
+ // Verify source file is a PowerShell script file.
522
+ string fileExtension = Path . GetExtension ( scriptFile ? . FilePath ?? "" ) ? . ToLower ( ) ;
523
+ if ( string . IsNullOrEmpty ( fileExtension ) || ( ( fileExtension != ".ps1" ) && ( fileExtension != ".psm1" ) ) )
524
+ {
525
+ Logger . Write (
526
+ LogLevel . Warning ,
527
+ $ "Attempted to set breakpoints on a non-PowerShell file: { setBreakpointsParams . Source . Path } ") ;
528
+
529
+ string message = this . noDebug ? string . Empty : "Source is not a PowerShell script, breakpoint not set." ;
530
+
531
+ var srcBreakpoints = setBreakpointsParams . Breakpoints
532
+ . Select ( srcBkpt => Protocol . DebugAdapter . Breakpoint . Create (
533
+ srcBkpt , setBreakpointsParams . Source . Path , message , verified : this . noDebug ) ) ;
534
+
535
+ // Return non-verified breakpoint message.
536
+ await requestContext . SendResult (
537
+ new SetBreakpointsResponseBody
538
+ {
539
+ Breakpoints = srcBreakpoints . ToArray ( )
540
+ } ) ;
541
+
542
+ return ;
543
+ }
515
544
545
+ // At this point, the source file has been verified as a PowerShell script.
516
546
var breakpointDetails = new BreakpointDetails [ setBreakpointsParams . Breakpoints . Length ] ;
517
547
for ( int i = 0 ; i < breakpointDetails . Length ; i ++ )
518
548
{
@@ -541,7 +571,7 @@ await editorSession.DebugService.SetLineBreakpoints(
541
571
catch ( Exception e )
542
572
{
543
573
// Log whatever the error is
544
- Logger . WriteException ( "Caught error while setting breakpoints in SetBreakpoints handler" , e ) ;
574
+ Logger . WriteException ( $ "Caught error while setting breakpoints in SetBreakpoints handler for file { scriptFile ? . FilePath } ", e ) ;
545
575
}
546
576
finally
547
577
{
0 commit comments