forked from swiftlang/vscode-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebugAdapterFactory.ts
82 lines (76 loc) · 3.1 KB
/
debugAdapterFactory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//===----------------------------------------------------------------------===//
//
// This source file is part of the VS Code Swift open source project
//
// Copyright (c) 2023 the VS Code Swift project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of VS Code Swift project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import * as vscode from "vscode";
import { WorkspaceContext } from "../WorkspaceContext";
import { DebugAdapter } from "./debugAdapter";
export function registerLLDBDebugAdapter(workspaceContext: WorkspaceContext): vscode.Disposable {
class LLDBDebugAdapterExecutableFactory implements vscode.DebugAdapterDescriptorFactory {
createDebugAdapterDescriptor(
_session: vscode.DebugSession,
executable: vscode.DebugAdapterExecutable | undefined
): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {
if (executable) {
// make VS Code launch the debug adapter executable
return executable;
}
return DebugAdapter.debugAdapterPath(workspaceContext.toolchain)
.then(path =>
DebugAdapter.verifyDebugAdapterExists(workspaceContext).then(() => path)
)
.then(path => new vscode.DebugAdapterExecutable(path, [], {}));
}
}
const debugAdpaterFactory = vscode.debug.registerDebugAdapterDescriptorFactory(
"swift-lldb",
new LLDBDebugAdapterExecutableFactory()
);
const debugConfigProvider = vscode.debug.registerDebugConfigurationProvider(
"swift-lldb",
new LLDBDebugConfigurationProvider()
);
return {
dispose: () => {
debugConfigProvider.dispose();
debugAdpaterFactory.dispose();
},
};
}
/** Provide configurations for lldb-vscode/lldb-dap
*
* Converts launch configuration that user supplies into a version that the lldb-vscode/lldb-dap
* debug adapter will use. Primarily it converts the environment variables from Object
* to an array of strings in format "var=value".
*
* This could also be used to augment the configuration with values from the settings
* althought it isn't at the moment.
*/
class LLDBDebugConfigurationProvider implements vscode.DebugConfigurationProvider {
async resolveDebugConfiguration(
folder: vscode.WorkspaceFolder | undefined,
launchConfig: vscode.DebugConfiguration,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
cancellation?: vscode.CancellationToken
): Promise<vscode.DebugConfiguration> {
launchConfig.env = this.convertEnvironmentVariables(launchConfig.env);
return launchConfig;
}
convertEnvironmentVariables(
map: { [key: string]: string } | undefined
): { [key: string]: string } | string[] | undefined {
if (map === undefined) {
return undefined;
}
return Object.entries(map).map(([key, value]) => `${key}=${value}`);
}
}