Skip to content

Commit 9f3cf01

Browse files
new new breakpoint apis
1 parent 1b4a357 commit 9f3cf01

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointApiUtils.cs

+11-21
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ internal static class BreakpointApiUtils
2727

2828
private static readonly Lazy<Func<Debugger, int?, List<Breakpoint>>> s_getBreakpointsLazy;
2929

30-
private static readonly Lazy<Action<Debugger, IEnumerable<Breakpoint>, int?>> s_setBreakpointsLazy;
31-
3230
private static readonly Lazy<Func<Debugger, Breakpoint, int?, bool>> s_removeBreakpointLazy;
3331

3432
private static int breakpointHitCounter;
@@ -39,16 +37,17 @@ internal static class BreakpointApiUtils
3937

4038
static BreakpointApiUtils()
4139
{
42-
// If this version of PowerShell does not support the new Breakpoint APIs introduced in PowerShell 7.0.0-preview.4,
40+
// If this version of PowerShell does not support the new Breakpoint APIs introduced in PowerShell 7.0.0,
4341
// do nothing as this class will not get used.
44-
if (typeof(Debugger).GetMethod("SetLineBreakpoint", BindingFlags.Public | BindingFlags.Instance) == null)
42+
if (!SupportsBreakpointApis)
4543
{
4644
return;
4745
}
4846

4947
s_setLineBreakpointLazy = new Lazy<Func<Debugger, string, int, int, ScriptBlock, int?, LineBreakpoint>>(() =>
5048
{
51-
MethodInfo setLineBreakpointMethod = typeof(Debugger).GetMethod("SetLineBreakpoint", BindingFlags.Public | BindingFlags.Instance);
49+
Type[] setLineBreakpointParameters = new[] { typeof(string), typeof(int), typeof(int), typeof(ScriptBlock), typeof(int?) };
50+
MethodInfo setLineBreakpointMethod = typeof(Debugger).GetMethod("SetLineBreakpoint", setLineBreakpointParameters);
5251

5352
return (Func<Debugger, string, int, int, ScriptBlock, int?, LineBreakpoint>)Delegate.CreateDelegate(
5453
typeof(Func<Debugger, string, int, int, ScriptBlock, int?, LineBreakpoint>),
@@ -58,7 +57,8 @@ static BreakpointApiUtils()
5857

5958
s_setCommandBreakpointLazy = new Lazy<Func<Debugger, string, ScriptBlock, string, int?, CommandBreakpoint>>(() =>
6059
{
61-
MethodInfo setCommandBreakpointMethod = typeof(Debugger).GetMethod("SetCommandBreakpoint", BindingFlags.Public | BindingFlags.Instance);
60+
Type[] setCommandBreakpointParameters = new[] { typeof(string), typeof(ScriptBlock), typeof(string), typeof(int?) };
61+
MethodInfo setCommandBreakpointMethod = typeof(Debugger).GetMethod("SetCommandBreakpoint", setCommandBreakpointParameters);
6262

6363
return (Func<Debugger, string, ScriptBlock, string, int?, CommandBreakpoint>)Delegate.CreateDelegate(
6464
typeof(Func<Debugger, string, ScriptBlock, string, int?, CommandBreakpoint>),
@@ -68,27 +68,19 @@ static BreakpointApiUtils()
6868

6969
s_getBreakpointsLazy = new Lazy<Func<Debugger, int?, List<Breakpoint>>>(() =>
7070
{
71-
MethodInfo removeBreakpointMethod = typeof(Debugger).GetMethod("GetBreakpoints", BindingFlags.Public | BindingFlags.Instance);
71+
Type[] getBreakpointsParameters = new[] { typeof(int?) };
72+
MethodInfo getBreakpointsMethod = typeof(Debugger).GetMethod("GetBreakpoints", getBreakpointsParameters);
7273

7374
return (Func<Debugger, int?, List<Breakpoint>>)Delegate.CreateDelegate(
7475
typeof(Func<Debugger, int?, List<Breakpoint>>),
7576
firstArgument: null,
76-
removeBreakpointMethod);
77-
});
78-
79-
s_setBreakpointsLazy = new Lazy<Action<Debugger, IEnumerable<Breakpoint>, int?>>(() =>
80-
{
81-
MethodInfo removeBreakpointMethod = typeof(Debugger).GetMethod("SetBreakpoints", BindingFlags.Public | BindingFlags.Instance);
82-
83-
return (Action<Debugger, IEnumerable<Breakpoint>, int?>)Action.CreateDelegate(
84-
typeof(Action<Debugger, IEnumerable<Breakpoint>, int?>),
85-
firstArgument: null,
86-
removeBreakpointMethod);
77+
getBreakpointsMethod);
8778
});
8879

8980
s_removeBreakpointLazy = new Lazy<Func<Debugger, Breakpoint, int?, bool>>(() =>
9081
{
91-
MethodInfo removeBreakpointMethod = typeof(Debugger).GetMethod("RemoveBreakpoint", BindingFlags.Public | BindingFlags.Instance);
82+
Type[] removeBreakpointParameters = new[] { typeof(Breakpoint), typeof(int?) };
83+
MethodInfo removeBreakpointMethod = typeof(Debugger).GetMethod("RemoveBreakpoint", removeBreakpointParameters);
9284

9385
return (Func<Debugger, Breakpoint, int?, bool>)Delegate.CreateDelegate(
9486
typeof(Func<Debugger, Breakpoint, int?, bool>),
@@ -107,8 +99,6 @@ static BreakpointApiUtils()
10799

108100
private static Func<Debugger, int?, List<Breakpoint>> GetBreakpointsDelegate => s_getBreakpointsLazy.Value;
109101

110-
private static Action<Debugger, IEnumerable<Breakpoint>, int?> SetBreakpointsDelegate => s_setBreakpointsLazy.Value;
111-
112102
private static Func<Debugger, Breakpoint, int?, bool> RemoveBreakpointDelegate => s_removeBreakpointLazy.Value;
113103

114104
#endregion

0 commit comments

Comments
 (0)