@@ -17,19 +17,76 @@ import * as path from "path";
17
17
import { WorkspaceContext } from "../WorkspaceContext" ;
18
18
import { DebugAdapter , LaunchConfigType } from "./debugAdapter" ;
19
19
import { Version } from "../utilities/version" ;
20
+ import { registerLoggingDebugAdapterTracker } from "./logTracker" ;
21
+ import { SwiftToolchain } from "../toolchain/toolchain" ;
22
+ import { SwiftOutputChannel } from "../ui/SwiftOutputChannel" ;
20
23
21
- export function registerLLDBDebugAdapter ( workspaceContext : WorkspaceContext ) : vscode . Disposable {
24
+ /**
25
+ * Registers the active debugger with the extension, and reregisters it
26
+ * when the debugger settings change.
27
+ * @param workspaceContext The workspace context
28
+ * @returns A disposable to be disposed when the extension is deactivated
29
+ */
30
+ export function registerDebugger ( workspaceContext : WorkspaceContext ) : vscode . Disposable {
31
+ let subscriptions : vscode . Disposable [ ] = [ ] ;
32
+ const register = async ( ) => {
33
+ subscriptions . map ( sub => sub . dispose ( ) ) ;
34
+ subscriptions = [
35
+ registerLoggingDebugAdapterTracker ( workspaceContext . toolchain . swiftVersion ) ,
36
+ registerLLDBDebugAdapter ( workspaceContext . toolchain , workspaceContext . outputChannel ) ,
37
+ ] ;
38
+
39
+ await workspaceContext . setLLDBVersion ( ) ;
40
+
41
+ // Verify that the adapter exists, but only after registration. This async method
42
+ // is basically an unstructured task so we don't want to run it before the adapter
43
+ // registration above as it could cause code executing immediately after register()
44
+ // to use the incorrect adapter.
45
+ DebugAdapter . verifyDebugAdapterExists (
46
+ workspaceContext . toolchain ,
47
+ workspaceContext . outputChannel ,
48
+ true
49
+ ) . catch ( error => {
50
+ workspaceContext . outputChannel . log ( error ) ;
51
+ } ) ;
52
+ } ;
53
+
54
+ const changeMonitor = vscode . workspace . onDidChangeConfiguration ( event => {
55
+ if ( event . affectsConfiguration ( "swift.debugger.useDebugAdapterFromToolchain" ) ) {
56
+ register ( ) ;
57
+ }
58
+ } ) ;
59
+
60
+ // Perform the initial registration, then reregister every time the settings change.
61
+ register ( ) ;
62
+
63
+ return {
64
+ dispose : ( ) => {
65
+ changeMonitor . dispose ( ) ;
66
+ subscriptions . map ( sub => sub . dispose ( ) ) ;
67
+ } ,
68
+ } ;
69
+ }
70
+
71
+ /**
72
+ * Registers the LLDB debug adapter with the VS Code debug adapter descriptor factory.
73
+ * @param workspaceContext The workspace context
74
+ * @returns A disposable to be disposed when the extension is deactivated
75
+ */
76
+ function registerLLDBDebugAdapter (
77
+ toolchain : SwiftToolchain ,
78
+ outputChannel : SwiftOutputChannel
79
+ ) : vscode . Disposable {
22
80
const debugAdpaterFactory = vscode . debug . registerDebugAdapterDescriptorFactory (
23
81
LaunchConfigType . SWIFT_EXTENSION ,
24
- new LLDBDebugAdapterExecutableFactory ( workspaceContext )
82
+ new LLDBDebugAdapterExecutableFactory ( toolchain , outputChannel )
25
83
) ;
84
+
26
85
const debugConfigProvider = vscode . debug . registerDebugConfigurationProvider (
27
86
LaunchConfigType . SWIFT_EXTENSION ,
28
- new LLDBDebugConfigurationProvider (
29
- process . platform ,
30
- workspaceContext . toolchain . swiftVersion
31
- )
87
+ new LLDBDebugConfigurationProvider ( process . platform , toolchain . swiftVersion )
32
88
) ;
89
+
33
90
return {
34
91
dispose : ( ) => {
35
92
debugConfigProvider . dispose ( ) ;
@@ -56,19 +113,18 @@ export function registerLLDBDebugAdapter(workspaceContext: WorkspaceContext): vs
56
113
* @implements {vscode.DebugAdapterDescriptorFactory}
57
114
*/
58
115
export class LLDBDebugAdapterExecutableFactory implements vscode . DebugAdapterDescriptorFactory {
59
- private workspaceContext : WorkspaceContext ;
116
+ private toolchain : SwiftToolchain ;
117
+ private outputChannel : SwiftOutputChannel ;
60
118
61
- constructor ( workspaceContext : WorkspaceContext ) {
62
- this . workspaceContext = workspaceContext ;
119
+ constructor ( toolchain : SwiftToolchain , outputChannel : SwiftOutputChannel ) {
120
+ this . toolchain = toolchain ;
121
+ this . outputChannel = outputChannel ;
63
122
}
64
123
65
- createDebugAdapterDescriptor ( ) : vscode . ProviderResult < vscode . DebugAdapterDescriptor > {
66
- // Use the stored workspaceContext
67
- return DebugAdapter . debugAdapterPath ( this . workspaceContext . toolchain )
68
- . then ( path =>
69
- DebugAdapter . verifyDebugAdapterExists ( this . workspaceContext ) . then ( ( ) => path )
70
- )
71
- . then ( path => new vscode . DebugAdapterExecutable ( path , [ ] , { } ) ) ;
124
+ async createDebugAdapterDescriptor ( ) : Promise < vscode . DebugAdapterDescriptor > {
125
+ const path = await DebugAdapter . debugAdapterPath ( this . toolchain ) ;
126
+ await DebugAdapter . verifyDebugAdapterExists ( this . toolchain , this . outputChannel ) ;
127
+ return new vscode . DebugAdapterExecutable ( path , [ ] , { } ) ;
72
128
}
73
129
}
74
130
0 commit comments