Skip to content

Commit 73b80cf

Browse files
1 parent 993efea commit 73b80cf

Some content is hidden

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

59 files changed

+4236
-3325
lines changed
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
}
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import * as util from 'util';
5-
import { Disposable, LogOutputChannel } from 'vscode';
4+
import * as util from "util";
5+
import { Disposable, LogOutputChannel } from "vscode";
66

77
export type Arguments = unknown[];
88

99
class OutputChannelLogger {
10-
constructor(private readonly channel: LogOutputChannel) {}
10+
constructor(private readonly channel: LogOutputChannel) {}
1111

12-
public traceLog(...data: Arguments): void {
13-
this.channel.appendLine(util.format(...data));
14-
}
12+
public traceLog(...data: Arguments): void {
13+
this.channel.appendLine(util.format(...data));
14+
}
1515

16-
public traceError(...data: Arguments): void {
17-
this.channel.error(util.format(...data));
18-
}
16+
public traceError(...data: Arguments): void {
17+
this.channel.error(util.format(...data));
18+
}
1919

20-
public traceWarn(...data: Arguments): void {
21-
this.channel.warn(util.format(...data));
22-
}
20+
public traceWarn(...data: Arguments): void {
21+
this.channel.warn(util.format(...data));
22+
}
2323

24-
public traceInfo(...data: Arguments): void {
25-
this.channel.info(util.format(...data));
26-
}
24+
public traceInfo(...data: Arguments): void {
25+
this.channel.info(util.format(...data));
26+
}
2727

28-
public traceVerbose(...data: Arguments): void {
29-
this.channel.debug(util.format(...data));
30-
}
28+
public traceVerbose(...data: Arguments): void {
29+
this.channel.debug(util.format(...data));
30+
}
3131
}
3232

3333
let channel: OutputChannelLogger | undefined;
3434
export function registerLogger(logChannel: LogOutputChannel): Disposable {
35-
channel = new OutputChannelLogger(logChannel);
36-
return {
37-
dispose: () => {
38-
channel = undefined;
39-
},
40-
};
35+
channel = new OutputChannelLogger(logChannel);
36+
return {
37+
dispose: () => {
38+
channel = undefined;
39+
},
40+
};
4141
}
4242

4343
export function traceLog(...args: Arguments): void {
44-
channel?.traceLog(...args);
44+
channel?.traceLog(...args);
4545
}
4646

4747
export function traceError(...args: Arguments): void {
48-
channel?.traceError(...args);
48+
channel?.traceError(...args);
4949
}
5050

5151
export function traceWarn(...args: Arguments): void {
52-
channel?.traceWarn(...args);
52+
channel?.traceWarn(...args);
5353
}
5454

5555
export function traceInfo(...args: Arguments): void {
56-
channel?.traceInfo(...args);
56+
channel?.traceInfo(...args);
5757
}
5858

5959
export function traceVerbose(...args: Arguments): void {
60-
channel?.traceVerbose(...args);
60+
channel?.traceVerbose(...args);
6161
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
export const DEFAULT_ENCODING = 'utf8';
4+
export const DEFAULT_ENCODING = "utf8";
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import * as iconv from 'iconv-lite';
5-
import { DEFAULT_ENCODING } from './constants';
4+
import * as iconv from "iconv-lite";
65

7-
export function decodeBuffer(buffers: Buffer[], encoding: string = DEFAULT_ENCODING): string {
8-
encoding = iconv.encodingExists(encoding) ? encoding : DEFAULT_ENCODING;
9-
return iconv.decode(Buffer.concat(buffers), encoding);
6+
import { DEFAULT_ENCODING } from "./constants";
7+
8+
export function decodeBuffer(
9+
buffers: Buffer[],
10+
encoding: string = DEFAULT_ENCODING,
11+
): string {
12+
encoding = iconv.encodingExists(encoding) ? encoding : DEFAULT_ENCODING;
13+
return iconv.decode(Buffer.concat(buffers), encoding);
1014
}

0 commit comments

Comments
 (0)