forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathdebugConfigurationService.ts
63 lines (58 loc) · 2.72 KB
/
debugConfigurationService.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable, named } from 'inversify';
import { CancellationToken, DebugConfiguration, WorkspaceFolder } from 'vscode';
import { AttachRequestArguments, LaunchRequestArguments } from '../../types';
import { IDebugConfigurationService } from '../types';
import { IDebugConfigurationResolver } from './types';
@injectable()
export class PythonDebugConfigurationService implements IDebugConfigurationService {
constructor(
@inject(IDebugConfigurationResolver)
@named('attach')
private readonly attachResolver: IDebugConfigurationResolver<AttachRequestArguments>,
@inject(IDebugConfigurationResolver)
@named('launch')
private readonly launchResolver: IDebugConfigurationResolver<LaunchRequestArguments>,
) {}
public async resolveDebugConfiguration(
folder: WorkspaceFolder | undefined,
debugConfiguration: DebugConfiguration,
token?: CancellationToken,
): Promise<DebugConfiguration | undefined> {
if (debugConfiguration.request === 'attach') {
return this.attachResolver.resolveDebugConfiguration(
folder,
debugConfiguration as AttachRequestArguments,
token,
);
}
if (debugConfiguration.request === 'test') {
// `"request": "test"` is now deprecated. But some users might have it in their
// launch config. We get here if they triggered it using F5 or start with debugger.
throw Error(
'This configuration can only be used by the test debugging commands. `"request": "test"` is deprecated, please keep as `"request": "launch"` and add `"purpose": ["debug-test"]` instead.',
);
} else {
if (Object.keys(debugConfiguration).length === 0) {
return undefined;
}
return this.launchResolver.resolveDebugConfiguration(
folder,
debugConfiguration as LaunchRequestArguments,
token,
);
}
}
public async resolveDebugConfigurationWithSubstitutedVariables(
folder: WorkspaceFolder | undefined,
debugConfiguration: DebugConfiguration,
token?: CancellationToken,
): Promise<DebugConfiguration | undefined> {
function resolve<T extends DebugConfiguration>(resolver: IDebugConfigurationResolver<T>) {
return resolver.resolveDebugConfigurationWithSubstitutedVariables(folder, debugConfiguration as T, token);
}
return debugConfiguration.request === 'attach' ? resolve(this.attachResolver) : resolve(this.launchResolver);
}
}