Skip to content

Commit cd3a7a9

Browse files
1 parent 4381ece commit cd3a7a9

File tree

91 files changed

+7016
-5625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+7016
-5625
lines changed

Source/extension/api.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

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

6-
import { IExtensionApi } from './apiTypes';
7-
import { getDebugpyLauncherArgs, getDebugpyPackagePath } from './debugger/adapter/remoteLaunchers';
6+
import { IExtensionApi } from "./apiTypes";
7+
import {
8+
getDebugpyLauncherArgs,
9+
getDebugpyPackagePath,
10+
} from "./debugger/adapter/remoteLaunchers";
811

912
export function buildApi(): IExtensionApi {
10-
const api: IExtensionApi = {
11-
debug: {
12-
async getRemoteLauncherCommand(
13-
host: string,
14-
port: number,
15-
waitUntilDebuggerAttaches: boolean = true,
16-
): Promise<string[]> {
17-
return getDebugpyLauncherArgs({
18-
host,
19-
port,
20-
waitUntilDebuggerAttaches,
21-
});
22-
},
23-
async getDebuggerPackagePath(): Promise<string> {
24-
return getDebugpyPackagePath();
25-
},
26-
},
27-
};
13+
const api: IExtensionApi = {
14+
debug: {
15+
async getRemoteLauncherCommand(
16+
host: string,
17+
port: number,
18+
waitUntilDebuggerAttaches: boolean = true,
19+
): Promise<string[]> {
20+
return getDebugpyLauncherArgs({
21+
host,
22+
port,
23+
waitUntilDebuggerAttaches,
24+
});
25+
},
26+
async getDebuggerPackagePath(): Promise<string> {
27+
return getDebugpyPackagePath();
28+
},
29+
},
30+
};
2831

29-
return api;
32+
return api;
3033
}

Source/extension/apiTypes.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
// Licensed under the MIT License.
33

44
export interface IExtensionApi {
5-
debug: {
6-
/**
7-
* Generate an array of strings for commands to pass to the Python executable to launch the debugger for remote debugging.
8-
* Users can append another array of strings of what they want to execute along with relevant arguments to Python.
9-
* E.g `['/Users/..../pythonVSCode/pythonFiles/lib/python/debugpy', '--listen', 'localhost:57039', '--wait-for-client']`
10-
* @param {string} host
11-
* @param {number} port
12-
* @param {boolean} [waitUntilDebuggerAttaches=true]
13-
* @returns {Promise<string[]>}
14-
*/
15-
getRemoteLauncherCommand(host: string, port: number, waitUntilDebuggerAttaches: boolean): Promise<string[]>;
5+
debug: {
6+
/**
7+
* Generate an array of strings for commands to pass to the Python executable to launch the debugger for remote debugging.
8+
* Users can append another array of strings of what they want to execute along with relevant arguments to Python.
9+
* E.g `['/Users/..../pythonVSCode/pythonFiles/lib/python/debugpy', '--listen', 'localhost:57039', '--wait-for-client']`
10+
* @param {string} host
11+
* @param {number} port
12+
* @param {boolean} [waitUntilDebuggerAttaches=true]
13+
* @returns {Promise<string[]>}
14+
*/
15+
getRemoteLauncherCommand(
16+
host: string,
17+
port: number,
18+
waitUntilDebuggerAttaches: boolean,
19+
): Promise<string[]>;
1620

17-
/**
18-
* Gets the path to the debugger package used by the extension.
19-
* @returns {Promise<string>}
20-
*/
21-
getDebuggerPackagePath(): Promise<string | undefined>;
22-
};
21+
/**
22+
* Gets the path to the debugger package used by the extension.
23+
* @returns {Promise<string>}
24+
*/
25+
getDebuggerPackagePath(): Promise<string | undefined>;
26+
};
2327
}
Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,45 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

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

6-
import * as fs from 'fs-extra';
7-
import * as path from 'path';
8-
import { executeCommand } from '../../vscodeapi';
9-
import { getActiveEnvironmentPath, resolveEnvironment } from '../../python';
10-
import { EXTENSION_ROOT_DIR } from '../../constants';
11-
import { getRawVersion } from '../../settings';
12-
import { sendTelemetryEvent } from '../../../telemetry';
13-
import { EventName } from '../../../telemetry/constants';
6+
import * as path from "path";
7+
import * as fs from "fs-extra";
8+
9+
import { sendTelemetryEvent } from "../../../telemetry";
10+
import { EventName } from "../../../telemetry/constants";
11+
import { EXTENSION_ROOT_DIR } from "../../constants";
12+
import { getActiveEnvironmentPath, resolveEnvironment } from "../../python";
13+
import { getRawVersion } from "../../settings";
14+
import { executeCommand } from "../../vscodeapi";
1415

1516
/**
1617
* Allows the user to report an issue related to the Python Debugger extension using our template.
1718
*/
1819
export async function openReportIssue(): Promise<void> {
19-
const templatePath = path.join(EXTENSION_ROOT_DIR, 'resources', 'report_issue_template.md');
20-
const userDataTemplatePath = path.join(EXTENSION_ROOT_DIR, 'resources', 'report_issue_user_data_template.md');
21-
const template = await fs.readFile(templatePath, 'utf8');
22-
const userTemplate = await fs.readFile(userDataTemplatePath, 'utf8');
23-
const interpreterPath = await getActiveEnvironmentPath();
24-
const interpreter = await resolveEnvironment(interpreterPath);
25-
const virtualEnvKind = interpreter?.environment?.type || 'Unknown';
20+
const templatePath = path.join(
21+
EXTENSION_ROOT_DIR,
22+
"resources",
23+
"report_issue_template.md",
24+
);
25+
const userDataTemplatePath = path.join(
26+
EXTENSION_ROOT_DIR,
27+
"resources",
28+
"report_issue_user_data_template.md",
29+
);
30+
const template = await fs.readFile(templatePath, "utf8");
31+
const userTemplate = await fs.readFile(userDataTemplatePath, "utf8");
32+
const interpreterPath = await getActiveEnvironmentPath();
33+
const interpreter = await resolveEnvironment(interpreterPath);
34+
const virtualEnvKind = interpreter?.environment?.type || "Unknown";
2635

27-
const pythonVersion = getRawVersion(interpreter?.version);
28-
await executeCommand('workbench.action.openIssueReporter', {
29-
extensionId: 'ms-python.debugpy',
30-
issueBody: template,
31-
data: userTemplate.replace('{0}', pythonVersion).replace('{1}', virtualEnvKind),
32-
});
33-
sendTelemetryEvent(EventName.USE_REPORT_ISSUE_COMMAND, undefined, {});
36+
const pythonVersion = getRawVersion(interpreter?.version);
37+
await executeCommand("workbench.action.openIssueReporter", {
38+
extensionId: "ms-python.debugpy",
39+
issueBody: template,
40+
data: userTemplate
41+
.replace("{0}", pythonVersion)
42+
.replace("{1}", virtualEnvKind),
43+
});
44+
sendTelemetryEvent(EventName.USE_REPORT_ISSUE_COMMAND, undefined, {});
3445
}
Lines changed: 74 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,93 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

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

6-
import { DebugAdapterTracker, DebugAdapterTrackerFactory, DebugSession, ProviderResult } from 'vscode';
7-
import { DebugProtocol } from '@vscode/debugprotocol';
8-
import { IEventNamePropertyMapping, sendTelemetryEvent } from '../../telemetry';
9-
import { EventName } from '../../telemetry/constants';
10-
import { TriggerType, AttachRequestArguments, ConsoleType, LaunchRequestArguments } from '../../types';
11-
import { StopWatch } from '../utils/stopWatch';
6+
import { DebugProtocol } from "@vscode/debugprotocol";
7+
import {
8+
DebugAdapterTracker,
9+
DebugAdapterTrackerFactory,
10+
DebugSession,
11+
ProviderResult,
12+
} from "vscode";
13+
14+
import { IEventNamePropertyMapping, sendTelemetryEvent } from "../../telemetry";
15+
import { EventName } from "../../telemetry/constants";
16+
import {
17+
AttachRequestArguments,
18+
ConsoleType,
19+
LaunchRequestArguments,
20+
TriggerType,
21+
} from "../../types";
22+
import { StopWatch } from "../utils/stopWatch";
1223

1324
function isResponse(a: any): a is DebugProtocol.Response {
14-
return a.type === 'response';
25+
return a.type === "response";
1526
}
1627
class TelemetryTracker implements DebugAdapterTracker {
17-
private timer = new StopWatch();
18-
private readonly trigger: TriggerType = 'launch';
19-
private readonly console: ConsoleType | undefined;
28+
private timer = new StopWatch();
29+
private readonly trigger: TriggerType = "launch";
30+
private readonly console: ConsoleType | undefined;
2031

21-
constructor(session: DebugSession) {
22-
this.trigger = session.configuration.request as TriggerType;
23-
const debugConfiguration = session.configuration as Partial<LaunchRequestArguments & AttachRequestArguments>;
24-
this.console = debugConfiguration.console;
25-
}
32+
constructor(session: DebugSession) {
33+
this.trigger = session.configuration.request as TriggerType;
34+
const debugConfiguration = session.configuration as Partial<
35+
LaunchRequestArguments & AttachRequestArguments
36+
>;
37+
this.console = debugConfiguration.console;
38+
}
2639

27-
public onWillStartSession() {
28-
this.sendTelemetry(EventName.DEBUG_SESSION_START);
29-
}
40+
public onWillStartSession() {
41+
this.sendTelemetry(EventName.DEBUG_SESSION_START);
42+
}
3043

31-
public onDidSendMessage(message: any): void {
32-
if (isResponse(message)) {
33-
if (message.command === 'configurationDone') {
34-
// "configurationDone" response is sent immediately after user code starts running.
35-
this.sendTelemetry(EventName.DEBUG_SESSION_USER_CODE_RUNNING);
36-
}
37-
}
38-
}
44+
public onDidSendMessage(message: any): void {
45+
if (isResponse(message)) {
46+
if (message.command === "configurationDone") {
47+
// "configurationDone" response is sent immediately after user code starts running.
48+
this.sendTelemetry(EventName.DEBUG_SESSION_USER_CODE_RUNNING);
49+
}
50+
}
51+
}
3952

40-
public onWillStopSession(): void {
41-
this.sendTelemetry(EventName.DEBUG_SESSION_STOP);
42-
}
53+
public onWillStopSession(): void {
54+
this.sendTelemetry(EventName.DEBUG_SESSION_STOP);
55+
}
4356

44-
public onError?(error: Error): void {
45-
this.sendTelemetry(EventName.DEBUG_SESSION_ERROR, error);
46-
}
57+
public onError?(error: Error): void {
58+
this.sendTelemetry(EventName.DEBUG_SESSION_ERROR, error);
59+
}
4760

48-
private sendTelemetry<P extends IEventNamePropertyMapping, E extends keyof P>(
49-
eventName: EventName,
50-
properties?: P[E],
51-
): void {
52-
if (eventName === EventName.DEBUG_SESSION_START) {
53-
this.timer.reset();
54-
}
55-
const telemetryProps = {
56-
trigger: this.trigger,
57-
console: this.console,
58-
...properties,
59-
};
60-
sendTelemetryEvent(eventName as keyof IEventNamePropertyMapping, this.timer.elapsedTime, telemetryProps);
61-
}
61+
private sendTelemetry<
62+
P extends IEventNamePropertyMapping,
63+
E extends keyof P,
64+
>(eventName: EventName, properties?: P[E]): void {
65+
if (eventName === EventName.DEBUG_SESSION_START) {
66+
this.timer.reset();
67+
}
68+
const telemetryProps = {
69+
trigger: this.trigger,
70+
console: this.console,
71+
...properties,
72+
};
73+
sendTelemetryEvent(
74+
eventName as keyof IEventNamePropertyMapping,
75+
this.timer.elapsedTime,
76+
telemetryProps,
77+
);
78+
}
6279
}
6380

6481
export class DebugSessionTelemetry implements DebugAdapterTrackerFactory {
65-
public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: true };
66-
constructor() {}
82+
public readonly supportedWorkspaceTypes = {
83+
untrustedWorkspace: false,
84+
virtualWorkspace: true,
85+
};
86+
constructor() {}
6787

68-
public createDebugAdapterTracker(session: DebugSession): ProviderResult<DebugAdapterTracker> {
69-
return new TelemetryTracker(session);
70-
}
88+
public createDebugAdapterTracker(
89+
session: DebugSession,
90+
): ProviderResult<DebugAdapterTracker> {
91+
return new TelemetryTracker(session);
92+
}
7193
}

Source/extension/common/constants.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,34 @@
22
// Copyright (c) Microsoft Corporation. All rights reserved.
33
// Licensed under the MIT License.
44

5-
import * as path from 'path';
5+
import * as path from "path";
66

7-
export const PYTHON_LANGUAGE = 'python';
7+
export const PYTHON_LANGUAGE = "python";
88
const folderName = path.basename(__dirname);
99
export const EXTENSION_ROOT_DIR =
10-
folderName === 'common' ? path.dirname(path.dirname(path.dirname(__dirname))) : path.dirname(__dirname);
11-
export const BUNDLED_PYTHON_SCRIPTS_DIR = path.join(EXTENSION_ROOT_DIR, 'bundled');
12-
export const SERVER_SCRIPT_PATH = path.join(BUNDLED_PYTHON_SCRIPTS_DIR, 'tool', `server.py`);
13-
export const DEBUG_SERVER_SCRIPT_PATH = path.join(BUNDLED_PYTHON_SCRIPTS_DIR, 'tool', `_debug_server.py`);
10+
folderName === "common"
11+
? path.dirname(path.dirname(path.dirname(__dirname)))
12+
: path.dirname(__dirname);
13+
export const BUNDLED_PYTHON_SCRIPTS_DIR = path.join(
14+
EXTENSION_ROOT_DIR,
15+
"bundled",
16+
);
17+
export const SERVER_SCRIPT_PATH = path.join(
18+
BUNDLED_PYTHON_SCRIPTS_DIR,
19+
"tool",
20+
`server.py`,
21+
);
22+
export const DEBUG_SERVER_SCRIPT_PATH = path.join(
23+
BUNDLED_PYTHON_SCRIPTS_DIR,
24+
"tool",
25+
`_debug_server.py`,
26+
);
1427

15-
export const AppinsightsKey = '0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-fc2a58ae4d14-7255';
28+
export const AppinsightsKey =
29+
"0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-fc2a58ae4d14-7255";
1630

1731
export function isTestExecution(): boolean {
18-
return process.env.VSC_PYTHON_CI_TEST === '1' || isUnitTestExecution();
32+
return process.env.VSC_PYTHON_CI_TEST === "1" || isUnitTestExecution();
1933
}
2034

2135
/**
@@ -25,21 +39,22 @@ export function isTestExecution(): boolean {
2539
* @returns {boolean}
2640
*/
2741
export function isUnitTestExecution(): boolean {
28-
return process.env.VSC_PYTHON_UNIT_TEST === '1';
42+
return process.env.VSC_PYTHON_UNIT_TEST === "1";
2943
}
3044

3145
export namespace Commands {
32-
export const Debug_In_Terminal = 'debugpy.debugInTerminal';
33-
export const Debug_Using_Launch_Config = 'debugpy.debugUsingLaunchConfig';
34-
export const TriggerEnvironmentSelection = 'debugpy.triggerEnvSelection';
35-
export const PickLocalProcess = 'debugpy.pickLocalProcess';
36-
export const PickArguments = 'debugpy.pickArgs';
37-
export const ViewOutput = 'debugpy.viewOutput';
38-
export const ClearStorage = 'debugpy.clearCacheAndReload';
39-
export const Enable_SourceMap_Support = 'debugpy.enableSourceMapSupport';
40-
export const SelectDebugConfig = 'debugpy.SelectAndInsertDebugConfiguration';
41-
export const Set_Interpreter = 'python.setInterpreter';
42-
export const ReportIssue = 'debugpy.reportIssue';
46+
export const Debug_In_Terminal = "debugpy.debugInTerminal";
47+
export const Debug_Using_Launch_Config = "debugpy.debugUsingLaunchConfig";
48+
export const TriggerEnvironmentSelection = "debugpy.triggerEnvSelection";
49+
export const PickLocalProcess = "debugpy.pickLocalProcess";
50+
export const PickArguments = "debugpy.pickArgs";
51+
export const ViewOutput = "debugpy.viewOutput";
52+
export const ClearStorage = "debugpy.clearCacheAndReload";
53+
export const Enable_SourceMap_Support = "debugpy.enableSourceMapSupport";
54+
export const SelectDebugConfig =
55+
"debugpy.SelectAndInsertDebugConfiguration";
56+
export const Set_Interpreter = "python.setInterpreter";
57+
export const ReportIssue = "debugpy.reportIssue";
4358
}
4459

45-
export type Channel = 'stable' | 'insiders';
60+
export type Channel = "stable" | "insiders";

0 commit comments

Comments
 (0)