Skip to content

Commit 2ffce92

Browse files
Rewrote debugger events
/cc #63
1 parent 88de2f0 commit 2ffce92

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using Microsoft;
3+
using Microsoft.VisualStudio;
4+
using Microsoft.VisualStudio.Shell;
5+
using Microsoft.VisualStudio.Shell.Interop;
6+
7+
namespace Community.VisualStudio.Toolkit
8+
{
9+
/// <summary>
10+
/// Events related to the selection in Visusal Studio.
11+
/// </summary>
12+
public class DebuggerEvents : IVsDebuggerEvents
13+
{
14+
internal DebuggerEvents()
15+
{
16+
ThreadHelper.ThrowIfNotOnUIThread();
17+
var svc = (IVsDebugger)ServiceProvider.GlobalProvider.GetService(typeof(IVsDebugger));
18+
Assumes.Present(svc);
19+
svc.AdviseDebuggerEvents(this, out _);
20+
}
21+
22+
/// <summary>
23+
/// Fires when entering break mode.
24+
/// </summary>
25+
public event EventHandler? EnterBreakMode;
26+
27+
/// <summary>
28+
/// Fired when the debugger enters run mode.
29+
/// </summary>
30+
public event EventHandler? EnterRunMode;
31+
32+
/// <summary>
33+
/// Fired when leaving run mode or debug mode, and when the debugger establishes design mode after debugging.
34+
/// </summary>
35+
public event EventHandler? EnterDesignMode;
36+
37+
/// <summary>
38+
/// Fires when entering Edit &amp; Continue mode.
39+
/// </summary>
40+
public event EventHandler? EnterEditAndContinueMode;
41+
42+
int IVsDebuggerEvents.OnModeChange(DBGMODE dbgmodeNew)
43+
{
44+
switch (dbgmodeNew)
45+
{
46+
case DBGMODE.DBGMODE_Design:
47+
EnterDesignMode?.Invoke(this, EventArgs.Empty);
48+
break;
49+
case DBGMODE.DBGMODE_Break:
50+
EnterBreakMode?.Invoke(this, EventArgs.Empty);
51+
break;
52+
case DBGMODE.DBGMODE_Run:
53+
EnterRunMode?.Invoke(this, EventArgs.Empty);
54+
break;
55+
case DBGMODE.DBGMODE_Enc:
56+
EnterEditAndContinueMode?.Invoke(this, EventArgs.Empty);
57+
break;
58+
}
59+
60+
return VSConstants.S_OK;
61+
}
62+
}
63+
}

src/Community.VisualStudio.Toolkit.Shared/Events/Events.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ internal Events()
3232
public CommandEvents? CommandEvents => _commandEvents ??= _events?.CommandEvents;
3333

3434

35-
private DebuggerEvents? _debuggerEvents;
36-
public DebuggerEvents? DebuggerEvents => _debuggerEvents ??= _events?.DebuggerEvents;
35+
/// <summary>
36+
/// Events related to the selection in Visusal Studio.
37+
/// </summary>
38+
public DebuggerEvents DebuggerEvents => new();
3739

3840

3941
private DebuggerExpressionEvaluationEvents? _debuggerExpressionEvaluationEvents;

src/Community.VisualStudio.Toolkit.Shared/Services/Debugger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal Debugger()
1010
{ }
1111

1212
/// <summary>Provides access to the current debugger so that the package can listen for debugger events.</summary>
13-
public Task<IVsDebugger> GetDebuggerAsync() => VS.GetRequiredServiceAsync<SVsShell, IVsDebugger>();
13+
public Task<IVsDebugger> GetDebuggerAsync() => VS.GetRequiredServiceAsync<IVsDebugger, IVsDebugger>();
1414

1515
/// <summary>Used to launch the debugger.</summary>
1616
public Task<IVsDebugLaunch> GetDebugLaunchAsync() => VS.GetRequiredServiceAsync<SVsDebugLaunch, IVsDebugLaunch>();

src/Community.VisualStudio.Toolkit.Shared/VSSDK.Helpers.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<Compile Include="$(MSBuildThisFileDirectory)Commands\CommandAttribute.cs" />
1313
<Compile Include="$(MSBuildThisFileDirectory)Editor\WpfTextViewCreationListener.cs" />
1414
<Compile Include="$(MSBuildThisFileDirectory)Events\BuildEvents.cs" />
15+
<Compile Include="$(MSBuildThisFileDirectory)Events\DebuggerEvents.cs" />
1516
<Compile Include="$(MSBuildThisFileDirectory)Events\SelectionEvents.cs" />
1617
<Compile Include="$(MSBuildThisFileDirectory)Events\SolutionEvents.cs" />
1718
<Compile Include="$(MSBuildThisFileDirectory)Events\DocumentEvents.cs" />

0 commit comments

Comments
 (0)