forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonV2Provider.ts
More file actions
109 lines (104 loc) · 5.43 KB
/
Copy pathpythonV2Provider.ts
File metadata and controls
109 lines (104 loc) · 5.43 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import { Uri } from 'vscode';
import { IPlatformService } from '../../common/platform/types';
import { IServiceContainer } from '../../ioc/types';
import { AttachRequestArguments, DebugOptions, LaunchRequestArguments } from '../Common/Contracts';
import { BaseConfigurationProvider, PythonAttachDebugConfiguration, PythonLaunchDebugConfiguration } from './baseProvider';
import { IConfigurationProviderUtils } from './types';
@injectable()
export class PythonV2DebugConfigurationProvider extends BaseConfigurationProvider<LaunchRequestArguments, AttachRequestArguments> {
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
super('pythonExperimental', serviceContainer);
}
protected async provideLaunchDefaults(workspaceFolder: Uri | undefined, debugConfiguration: PythonLaunchDebugConfiguration<LaunchRequestArguments>): Promise<void> {
await super.provideLaunchDefaults(workspaceFolder, debugConfiguration);
const debugOptions = debugConfiguration.debugOptions!;
if (debugConfiguration.debugStdLib) {
this.debugOption(debugOptions, DebugOptions.DebugStdLib);
}
if (debugConfiguration.django) {
this.debugOption(debugOptions, DebugOptions.Django);
}
if (debugConfiguration.jinja) {
this.debugOption(debugOptions, DebugOptions.Jinja);
}
if (debugConfiguration.redirectOutput || debugConfiguration.redirectOutput === undefined) {
this.debugOption(debugOptions, DebugOptions.RedirectOutput);
}
if (debugConfiguration.sudo) {
this.debugOption(debugOptions, DebugOptions.Sudo);
}
if (this.serviceContainer.get<IPlatformService>(IPlatformService).isWindows) {
this.debugOption(debugOptions, DebugOptions.FixFilePathCase);
}
const isFlask = debugConfiguration.module && debugConfiguration.module.toUpperCase() === 'FLASK';
if ((debugConfiguration.pyramid || isFlask)
&& debugOptions.indexOf(DebugOptions.Jinja) === -1
&& debugConfiguration.jinja !== false) {
this.debugOption(debugOptions, DebugOptions.Jinja);
}
if (debugConfiguration.pyramid) {
const utils = this.serviceContainer.get<IConfigurationProviderUtils>(IConfigurationProviderUtils);
debugConfiguration.program = (await utils.getPyramidStartupScriptFilePath(workspaceFolder))!;
}
}
// tslint:disable-next-line:cyclomatic-complexity
protected async provideAttachDefaults(workspaceFolder: Uri | undefined, debugConfiguration: PythonAttachDebugConfiguration<AttachRequestArguments>): Promise<void> {
await super.provideAttachDefaults(workspaceFolder, debugConfiguration);
const debugOptions = debugConfiguration.debugOptions!;
if (debugConfiguration.debugStdLib) {
this.debugOption(debugOptions, DebugOptions.DebugStdLib);
}
if (debugConfiguration.django) {
this.debugOption(debugOptions, DebugOptions.Django);
}
if (debugConfiguration.jinja) {
this.debugOption(debugOptions, DebugOptions.Jinja);
}
if (debugConfiguration.pyramid
&& debugOptions.indexOf(DebugOptions.Jinja) === -1
&& debugConfiguration.jinja !== false) {
this.debugOption(debugOptions, DebugOptions.Jinja);
}
if (debugConfiguration.redirectOutput || debugConfiguration.redirectOutput === undefined) {
this.debugOption(debugOptions, DebugOptions.RedirectOutput);
}
// We'll need paths to be fixed only in the case where local and remote hosts are the same
// I.e. only if hostName === 'localhost' or '127.0.0.1' or ''
const isLocalHost = !debugConfiguration.host || debugConfiguration.host === 'localhost' || debugConfiguration.host === '127.0.0.1';
if (this.serviceContainer.get<IPlatformService>(IPlatformService).isWindows && isLocalHost) {
this.debugOption(debugOptions, DebugOptions.FixFilePathCase);
}
if (this.serviceContainer.get<IPlatformService>(IPlatformService).isWindows) {
this.debugOption(debugOptions, DebugOptions.WindowsClient);
}
if (!debugConfiguration.pathMappings) {
debugConfiguration.pathMappings = [];
}
// This is for backwards compatibility.
if (debugConfiguration.localRoot && debugConfiguration.remoteRoot) {
debugConfiguration.pathMappings!.push({
localRoot: debugConfiguration.localRoot,
remoteRoot: debugConfiguration.remoteRoot
});
}
// If attaching to local host, then always map local root and remote roots.
if (workspaceFolder && debugConfiguration.host &&
debugConfiguration.pathMappings!.length === 0 &&
['LOCALHOST', '127.0.0.1', '::1'].indexOf(debugConfiguration.host.toUpperCase()) >= 0) {
debugConfiguration.pathMappings!.push({
localRoot: workspaceFolder.fsPath,
remoteRoot: workspaceFolder.fsPath
});
}
}
private debugOption(debugOptions: DebugOptions[], debugOption: DebugOptions) {
if (debugOptions.indexOf(debugOption) >= 0) {
return;
}
debugOptions.push(debugOption);
}
}