Skip to content

Commit a082360

Browse files
Nikola HristovNikola Hristov
authored andcommitted
1 parent 3044d8f commit a082360

File tree

12 files changed

+1369
-2962
lines changed

12 files changed

+1369
-2962
lines changed

.vscode/launch.json

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 117 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -1,185 +1,124 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
"use strict";
4+
'use strict';
55

6-
import { CancellationToken, Uri, WorkspaceFolder } from "vscode";
7-
8-
import { traceLog } from "../../../common/log/logging";
9-
import { getOSType, OSType } from "../../../common/platform";
10-
import { getConfiguration } from "../../../common/vscodeapi";
11-
import {
12-
AttachRequestArguments,
13-
DebugOptions,
14-
PathMapping,
15-
} from "../../../types";
16-
import { BaseConfigurationResolver } from "./base";
6+
import { CancellationToken, Uri, WorkspaceFolder } from 'vscode';
7+
import { getOSType, OSType } from '../../../common/platform';
8+
import { AttachRequestArguments, DebugOptions, PathMapping } from '../../../types';
9+
import { BaseConfigurationResolver } from './base';
10+
import { getConfiguration } from '../../../common/vscodeapi';
11+
import { traceLog } from '../../../common/log/logging';
1712

1813
export class AttachConfigurationResolver extends BaseConfigurationResolver<AttachRequestArguments> {
19-
public async resolveDebugConfigurationWithSubstitutedVariables(
20-
folder: WorkspaceFolder | undefined,
21-
debugConfiguration: AttachRequestArguments,
22-
_token?: CancellationToken,
23-
): Promise<AttachRequestArguments | undefined> {
24-
traceLog("Resolving attach configuration with substituted variables");
25-
26-
const workspaceFolder =
27-
AttachConfigurationResolver.getWorkspaceFolder(folder);
28-
29-
await this.provideAttachDefaults(
30-
workspaceFolder,
31-
debugConfiguration as AttachRequestArguments,
32-
);
33-
34-
const dbgConfig = debugConfiguration;
35-
36-
if (Array.isArray(dbgConfig.debugOptions)) {
37-
dbgConfig.debugOptions = dbgConfig.debugOptions!.filter(
38-
(item, pos) => dbgConfig.debugOptions!.indexOf(item) === pos,
39-
);
40-
}
41-
42-
if (debugConfiguration.clientOS === undefined) {
43-
debugConfiguration.clientOS =
44-
getOSType() === OSType.Windows ? "windows" : "unix";
45-
}
46-
47-
return debugConfiguration;
48-
}
49-
50-
protected async provideAttachDefaults(
51-
workspaceFolder: Uri | undefined,
52-
debugConfiguration: AttachRequestArguments,
53-
): Promise<void> {
54-
if (!Array.isArray(debugConfiguration.debugOptions)) {
55-
debugConfiguration.debugOptions = [];
56-
}
57-
58-
if (
59-
!(debugConfiguration.connect || debugConfiguration.listen) &&
60-
!debugConfiguration.host
61-
) {
62-
// Connect and listen cannot be mixed with host property.
63-
debugConfiguration.host = "localhost";
64-
}
65-
66-
if (debugConfiguration.justMyCode === undefined) {
67-
debugConfiguration.justMyCode = getConfiguration(
68-
"debugpy",
69-
workspaceFolder,
70-
).get<boolean>("debugJustMyCode", true);
71-
}
72-
73-
debugConfiguration.showReturnValue =
74-
debugConfiguration.showReturnValue !== false;
75-
// Pass workspace folder so we can get this when we get debug events firing.
76-
debugConfiguration.workspaceFolder = workspaceFolder
77-
? workspaceFolder.fsPath
78-
: undefined;
79-
80-
const debugOptions = debugConfiguration.debugOptions!;
81-
82-
if (debugConfiguration.django) {
83-
AttachConfigurationResolver.debugOption(
84-
debugOptions,
85-
DebugOptions.Django,
86-
);
87-
}
88-
89-
if (debugConfiguration.jinja) {
90-
AttachConfigurationResolver.debugOption(
91-
debugOptions,
92-
DebugOptions.Jinja,
93-
);
94-
}
95-
96-
if (debugConfiguration.subProcess === true) {
97-
AttachConfigurationResolver.debugOption(
98-
debugOptions,
99-
DebugOptions.SubProcess,
100-
);
101-
}
102-
103-
if (
104-
debugConfiguration.pyramid &&
105-
debugOptions.indexOf(DebugOptions.Jinja) === -1 &&
106-
debugConfiguration.jinja !== false
107-
) {
108-
AttachConfigurationResolver.debugOption(
109-
debugOptions,
110-
DebugOptions.Jinja,
111-
);
112-
}
113-
114-
if (
115-
debugConfiguration.redirectOutput ||
116-
debugConfiguration.redirectOutput === undefined
117-
) {
118-
AttachConfigurationResolver.debugOption(
119-
debugOptions,
120-
DebugOptions.RedirectOutput,
121-
);
122-
}
123-
124-
// We'll need paths to be fixed only in the case where local and remote hosts are the same
125-
// I.e. only if hostName === 'localhost' or '127.0.0.1' or ''
126-
const isLocalHost = AttachConfigurationResolver.isLocalHost(
127-
debugConfiguration.host,
128-
);
129-
130-
if (getOSType() === OSType.Windows && isLocalHost) {
131-
AttachConfigurationResolver.debugOption(
132-
debugOptions,
133-
DebugOptions.FixFilePathCase,
134-
);
135-
}
136-
137-
if (debugConfiguration.clientOS === undefined) {
138-
debugConfiguration.clientOS =
139-
getOSType() === OSType.Windows ? "windows" : "unix";
140-
}
141-
142-
if (debugConfiguration.showReturnValue) {
143-
AttachConfigurationResolver.debugOption(
144-
debugOptions,
145-
DebugOptions.ShowReturnValue,
146-
);
147-
}
148-
149-
debugConfiguration.pathMappings = this.resolvePathMappings(
150-
debugConfiguration.pathMappings || [],
151-
debugConfiguration.host,
152-
debugConfiguration.localRoot,
153-
debugConfiguration.remoteRoot,
154-
workspaceFolder,
155-
);
156-
157-
AttachConfigurationResolver.sendTelemetry("attach", debugConfiguration);
158-
}
159-
160-
// eslint-disable-next-line class-methods-use-this
161-
private resolvePathMappings(
162-
pathMappings: PathMapping[],
163-
host?: string,
164-
localRoot?: string,
165-
remoteRoot?: string,
166-
workspaceFolder?: Uri,
167-
) {
168-
// This is for backwards compatibility.
169-
if (localRoot && remoteRoot) {
170-
pathMappings.push({
171-
localRoot,
172-
remoteRoot,
173-
});
174-
}
175-
// If attaching to local host, then always map local root and remote roots.
176-
if (AttachConfigurationResolver.isLocalHost(host)) {
177-
pathMappings = AttachConfigurationResolver.fixUpPathMappings(
178-
pathMappings,
179-
workspaceFolder ? workspaceFolder.fsPath : "",
180-
);
181-
}
182-
183-
return pathMappings.length > 0 ? pathMappings : undefined;
184-
}
14+
public async resolveDebugConfigurationWithSubstitutedVariables(
15+
folder: WorkspaceFolder | undefined,
16+
debugConfiguration: AttachRequestArguments,
17+
_token?: CancellationToken,
18+
): Promise<AttachRequestArguments | undefined> {
19+
traceLog('Resolving attach configuration with substituted variables');
20+
const workspaceFolder = AttachConfigurationResolver.getWorkspaceFolder(folder);
21+
22+
await this.provideAttachDefaults(workspaceFolder, debugConfiguration as AttachRequestArguments);
23+
24+
const dbgConfig = debugConfiguration;
25+
if (Array.isArray(dbgConfig.debugOptions)) {
26+
dbgConfig.debugOptions = dbgConfig.debugOptions!.filter(
27+
(item, pos) => dbgConfig.debugOptions!.indexOf(item) === pos,
28+
);
29+
}
30+
if (!debugConfiguration.clientOS) {
31+
debugConfiguration.clientOS = getOSType() === OSType.Windows ? 'windows' : 'unix';
32+
}
33+
return debugConfiguration;
34+
}
35+
36+
protected async provideAttachDefaults(
37+
workspaceFolder: Uri | undefined,
38+
debugConfiguration: AttachRequestArguments,
39+
): Promise<void> {
40+
if (!Array.isArray(debugConfiguration.debugOptions)) {
41+
debugConfiguration.debugOptions = [];
42+
}
43+
if (!(debugConfiguration.connect || debugConfiguration.listen) && !debugConfiguration.host) {
44+
// Connect and listen cannot be mixed with host property.
45+
debugConfiguration.host = 'localhost';
46+
}
47+
if (debugConfiguration.justMyCode === undefined) {
48+
debugConfiguration.justMyCode = getConfiguration('debugpy', workspaceFolder).get<boolean>(
49+
'debugJustMyCode',
50+
true,
51+
);
52+
}
53+
debugConfiguration.showReturnValue = debugConfiguration.showReturnValue !== false;
54+
// Pass workspace folder so we can get this when we get debug events firing.
55+
debugConfiguration.workspaceFolder = workspaceFolder ? workspaceFolder.fsPath : undefined;
56+
const debugOptions = debugConfiguration.debugOptions!;
57+
if (debugConfiguration.django) {
58+
AttachConfigurationResolver.debugOption(debugOptions, DebugOptions.Django);
59+
}
60+
if (debugConfiguration.jinja) {
61+
AttachConfigurationResolver.debugOption(debugOptions, DebugOptions.Jinja);
62+
}
63+
if (debugConfiguration.subProcess === true) {
64+
AttachConfigurationResolver.debugOption(debugOptions, DebugOptions.SubProcess);
65+
}
66+
if (
67+
debugConfiguration.pyramid &&
68+
debugOptions.indexOf(DebugOptions.Jinja) === -1 &&
69+
debugConfiguration.jinja !== false
70+
) {
71+
AttachConfigurationResolver.debugOption(debugOptions, DebugOptions.Jinja);
72+
}
73+
if (debugConfiguration.redirectOutput || debugConfiguration.redirectOutput === undefined) {
74+
AttachConfigurationResolver.debugOption(debugOptions, DebugOptions.RedirectOutput);
75+
}
76+
77+
// We'll need paths to be fixed only in the case where local and remote hosts are the same
78+
// I.e. only if hostName === 'localhost' or '127.0.0.1' or ''
79+
const isLocalHost = AttachConfigurationResolver.isLocalHost(debugConfiguration.host);
80+
if (getOSType() === OSType.Windows && isLocalHost) {
81+
AttachConfigurationResolver.debugOption(debugOptions, DebugOptions.FixFilePathCase);
82+
}
83+
if (!debugConfiguration.clientOS) {
84+
debugConfiguration.clientOS = getOSType() === OSType.Windows ? 'windows' : 'unix';
85+
}
86+
if (debugConfiguration.showReturnValue) {
87+
AttachConfigurationResolver.debugOption(debugOptions, DebugOptions.ShowReturnValue);
88+
}
89+
90+
debugConfiguration.pathMappings = this.resolvePathMappings(
91+
debugConfiguration.pathMappings || [],
92+
debugConfiguration.host,
93+
debugConfiguration.localRoot,
94+
debugConfiguration.remoteRoot,
95+
workspaceFolder,
96+
);
97+
AttachConfigurationResolver.sendTelemetry('attach', debugConfiguration);
98+
}
99+
100+
// eslint-disable-next-line class-methods-use-this
101+
private resolvePathMappings(
102+
pathMappings: PathMapping[],
103+
host?: string,
104+
localRoot?: string,
105+
remoteRoot?: string,
106+
workspaceFolder?: Uri,
107+
) {
108+
// This is for backwards compatibility.
109+
if (localRoot && remoteRoot) {
110+
pathMappings.push({
111+
localRoot,
112+
remoteRoot,
113+
});
114+
}
115+
// If attaching to local host, then always map local root and remote roots.
116+
if (AttachConfigurationResolver.isLocalHost(host)) {
117+
pathMappings = AttachConfigurationResolver.fixUpPathMappings(
118+
pathMappings,
119+
workspaceFolder ? workspaceFolder.fsPath : '',
120+
);
121+
}
122+
return pathMappings.length > 0 ? pathMappings : undefined;
123+
}
185124
}

0 commit comments

Comments
 (0)