@@ -36,6 +36,7 @@ public class DebugAdapter
36
36
private IMessageSender messageSender ;
37
37
private IMessageHandlers messageHandlers ;
38
38
private bool isInteractiveDebugSession ;
39
+ private bool setBreakpointInProgress ;
39
40
private RequestContext < object > disconnectRequestContext = null ;
40
41
41
42
public DebugAdapter (
@@ -522,10 +523,24 @@ await requestContext.SendResult(
522
523
BreakpointDetails [ ] updatedBreakpointDetails = breakpointDetails ;
523
524
if ( ! this . noDebug )
524
525
{
525
- updatedBreakpointDetails =
526
- await editorSession . DebugService . SetLineBreakpoints (
527
- scriptFile ,
528
- breakpointDetails ) ;
526
+ this . setBreakpointInProgress = true ;
527
+
528
+ try
529
+ {
530
+ updatedBreakpointDetails =
531
+ await editorSession . DebugService . SetLineBreakpoints (
532
+ scriptFile ,
533
+ breakpointDetails ) ;
534
+ }
535
+ catch ( Exception e )
536
+ {
537
+ // Log whatever the error is
538
+ Logger . WriteException ( "Caught error while setting breakpoints in SetBreakpoints handler" , e ) ;
539
+ }
540
+ finally
541
+ {
542
+ this . setBreakpointInProgress = false ;
543
+ }
529
544
}
530
545
531
546
await requestContext . SendResult (
@@ -855,13 +870,15 @@ await this.messageSender.SendEvent(
855
870
private void RegisterEventHandlers ( )
856
871
{
857
872
this . editorSession . PowerShellContext . RunspaceChanged += this . powerShellContext_RunspaceChanged ;
873
+ this . editorSession . DebugService . BreakpointUpdated += DebugService_BreakpointUpdated ;
858
874
this . editorSession . DebugService . DebuggerStopped += this . DebugService_DebuggerStopped ;
859
875
this . editorSession . PowerShellContext . DebuggerResumed += this . powerShellContext_DebuggerResumed ;
860
876
}
861
877
862
878
private void UnregisterEventHandlers ( )
863
879
{
864
880
this . editorSession . PowerShellContext . RunspaceChanged -= this . powerShellContext_RunspaceChanged ;
881
+ this . editorSession . DebugService . BreakpointUpdated -= DebugService_BreakpointUpdated ;
865
882
this . editorSession . DebugService . DebuggerStopped -= this . DebugService_DebuggerStopped ;
866
883
this . editorSession . PowerShellContext . DebuggerResumed -= this . powerShellContext_DebuggerResumed ;
867
884
}
@@ -940,6 +957,42 @@ await this.messageSender.SendEvent(
940
957
} ) ;
941
958
}
942
959
960
+ private async void DebugService_BreakpointUpdated ( object sender , BreakpointUpdatedEventArgs e )
961
+ {
962
+ string reason = "changed" ;
963
+
964
+ if ( this . setBreakpointInProgress )
965
+ {
966
+ // Don't send breakpoint update notifications when setting
967
+ // breakpoints on behalf of the client.
968
+ return ;
969
+ }
970
+
971
+ switch ( e . UpdateType )
972
+ {
973
+ case BreakpointUpdateType . Set :
974
+ reason = "new" ;
975
+ break ;
976
+
977
+ case BreakpointUpdateType . Removed :
978
+ reason = "removed" ;
979
+ break ;
980
+ }
981
+
982
+ var breakpoint = Protocol . DebugAdapter . Breakpoint . Create (
983
+ BreakpointDetails . Create ( e . Breakpoint ) ) ;
984
+
985
+ breakpoint . Verified = e . UpdateType != BreakpointUpdateType . Disabled ;
986
+
987
+ await this . messageSender . SendEvent (
988
+ BreakpointEvent . Type ,
989
+ new BreakpointEvent
990
+ {
991
+ Reason = reason ,
992
+ Breakpoint = breakpoint
993
+ } ) ;
994
+ }
995
+
943
996
#endregion
944
997
945
998
#region Events
0 commit comments