File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed
Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Threading . Tasks ;
3+ using Microsoft . VisualStudio . Shell ;
4+ using Microsoft . VisualStudio . Shell . Interop ;
5+
6+ namespace Community . VisualStudio . Toolkit
7+ {
8+ /// <summary>
9+ /// Handles debugging.
10+ /// </summary>
11+ public class Debugger
12+ {
13+ /// <summary>
14+ /// The mode of the debugger.
15+ /// </summary>
16+ public enum DebugMode
17+ {
18+ /// <summary>The debugger is not attached.</summary>
19+ NotDebugging ,
20+ /// <summary>The debugger is stopped at a breakpoint.</summary>
21+ AtBreakpoint ,
22+ /// <summary>The debugger is attached and running.</summary>
23+ Running
24+ }
25+
26+ /// <summary>
27+ /// Checks if the debugger is attached.
28+ /// </summary>
29+ public async Task < bool > IsDebuggingAsync ( )
30+ {
31+ DebugMode debugMode = await GetDebugModeAsync ( ) ;
32+ return debugMode != DebugMode . NotDebugging ;
33+ }
34+
35+ /// <summary>
36+ /// Returns the current mode for the debugger.
37+ /// </summary>
38+ public async Task < DebugMode > GetDebugModeAsync ( )
39+ {
40+ await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
41+
42+ DBGMODE dbgMode = VsShellUtilities . GetDebugMode ( ServiceProvider . GlobalProvider ) & ~ DBGMODE . DBGMODE_EncMask ;
43+
44+ return dbgMode switch
45+ {
46+ DBGMODE . DBGMODE_Design => DebugMode . NotDebugging ,
47+ DBGMODE . DBGMODE_Break => DebugMode . AtBreakpoint ,
48+ DBGMODE . DBGMODE_Run => DebugMode . Running ,
49+ _ => throw new InvalidOperationException ( $ "Unexpected { nameof ( DebugMode ) } ")
50+ } ;
51+ }
52+ }
53+ }
Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ public static class VS
2121 /// <summary>A collection of services related to the command system.</summary>
2222 public static Commands Commands => _commands ??= new ( ) ;
2323
24+ private static Debugger ? _debugger ;
25+ /// <summary>A collection of services related to the debugger.</summary>
26+ public static Debugger Debugger => _debugger ??= new ( ) ;
27+
2428 private static Documents ? _documents ;
2529 /// <summary>Contains helper methods for dealing with documents.</summary>
2630 public static Documents Documents => _documents ??= new ( ) ;
Original file line number Diff line number Diff line change 99 <Import_RootNamespace >Community.VisualStudio.Toolkit.Shared</Import_RootNamespace >
1010 </PropertyGroup >
1111 <ItemGroup >
12+ <Compile Include =" $(MSBuildThisFileDirectory)Debugger\Debugger.cs" />
1213 <Compile Include =" $(MSBuildThisFileDirectory)\Attributes\ProvideBraceCompletionAttribute.cs" />
1314 <Compile Include =" $(MSBuildThisFileDirectory)\Attributes\ProvideFileIconAttribute.cs" />
1415 <Compile Include =" $(MSBuildThisFileDirectory)\Attributes\ProvideGalleryFeedAttribute.cs" />
You can’t perform that action at this time.
0 commit comments