Skip to content

Commit 6a5fad1

Browse files
Nikola HristovNikola Hristov
authored andcommitted
1 parent 9c300e4 commit 6a5fad1

File tree

15 files changed

+980
-12327
lines changed

15 files changed

+980
-12327
lines changed

Source/extension/debugger/adapter/factory.ts

Lines changed: 180 additions & 255 deletions
Large diffs are not rendered by default.

Source/extension/debugger/configuration/debugConfigurationService.ts

Lines changed: 171 additions & 263 deletions
Large diffs are not rendered by default.
Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
"use strict";
5-
6-
import { inject, injectable } from "inversify";
7-
import { DebugConfiguration, DebugSessionCustomEvent } from "vscode";
8-
9-
import { swallowExceptions } from "../../common/utils/decorators";
10-
import { DebuggerTypeName } from "../../constants";
11-
import { AttachRequestArguments } from "../../types";
12-
import { DebuggerEvents } from "./constants";
13-
import {
14-
IChildProcessAttachService,
15-
IDebugSessionEventHandlers,
16-
} from "./types";
4+
import { DebugConfiguration, DebugSessionCustomEvent } from 'vscode';
5+
import { swallowExceptions } from '../../common/utils/decorators';
6+
import { AttachRequestArguments } from '../../types';
7+
import { DebuggerEvents } from './constants';
8+
import { IChildProcessAttachService, IDebugSessionEventHandlers } from './types';
9+
import { DebuggerTypeName } from '../../constants';
1710

1811
/**
1912
* This class is responsible for automatically attaching the debugger to any
@@ -22,35 +15,28 @@ import {
2215
* @class ChildProcessAttachEventHandler
2316
* @implements {IDebugSessionEventHandlers}
2417
*/
25-
@injectable()
26-
export class ChildProcessAttachEventHandler
27-
implements IDebugSessionEventHandlers
28-
{
29-
constructor(
30-
@inject(IChildProcessAttachService)
31-
private readonly childProcessAttachService: IChildProcessAttachService,
32-
) {}
3318

34-
@swallowExceptions("Handle child process launch")
35-
public async handleCustomEvent(
36-
event: DebugSessionCustomEvent,
37-
): Promise<void> {
38-
if (!event || event.session.configuration.type !== DebuggerTypeName) {
39-
return;
40-
}
19+
export class ChildProcessAttachEventHandler implements IDebugSessionEventHandlers {
20+
constructor(private readonly childProcessAttachService: IChildProcessAttachService) {}
21+
22+
@swallowExceptions('Handle child process launch')
23+
public async handleCustomEvent(event: DebugSessionCustomEvent): Promise<void> {
24+
if (!event || event.session.configuration.type !== DebuggerTypeName) {
25+
return;
26+
}
4127

42-
let data: AttachRequestArguments & DebugConfiguration;
43-
if (
44-
event.event === DebuggerEvents.PtvsdAttachToSubprocess ||
45-
event.event === DebuggerEvents.DebugpyAttachToSubprocess
46-
) {
47-
data = event.body as AttachRequestArguments & DebugConfiguration;
48-
} else {
49-
return;
50-
}
28+
let data: AttachRequestArguments & DebugConfiguration;
29+
if (
30+
event.event === DebuggerEvents.PtvsdAttachToSubprocess ||
31+
event.event === DebuggerEvents.DebugpyAttachToSubprocess
32+
) {
33+
data = event.body as AttachRequestArguments & DebugConfiguration;
34+
} else {
35+
return;
36+
}
5137

52-
if (Object.keys(data).length > 0) {
53-
await this.childProcessAttachService.attach(data, event.session);
54-
}
55-
}
38+
if (Object.keys(data).length > 0) {
39+
await this.childProcessAttachService.attach(data, event.session);
40+
}
41+
}
5642
}
Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,41 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

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

6-
import { inject, injectable } from "inversify";
7-
import { DebugSessionCustomEvent } from "vscode";
8-
9-
import { traceLog } from "../../common/log/logging";
10-
import { swallowExceptions } from "../../common/utils/decorators";
11-
import { DebuggerTypeName } from "../../constants";
12-
import { DebugPortAttributesProvider } from "../debugPort/portAttributesProvider";
13-
import { DebuggerEvents } from "./constants";
14-
import { IDebugSessionEventHandlers } from "./types";
6+
import { DebugSessionCustomEvent } from 'vscode';
7+
import { swallowExceptions } from '../../common/utils/decorators';
8+
import { DebuggerEvents } from './constants';
9+
import { DebuggerTypeName } from '../../constants';
10+
import { DebugPortAttributesProvider } from '../debugPort/portAttributesProvider';
11+
import { IDebugSessionEventHandlers } from './types';
12+
import { traceLog } from '../../common/log/logging';
1513

1614
/**
1715
* This class is responsible for register ports using by debugpy in the portProvider.
1816
* @export
1917
* @class ChildProcessAttachEventHandler
2018
* @implements {IDebugSessionEventHandlers}
2119
*/
22-
@injectable()
2320
export class DebugpySocketsHandler implements IDebugSessionEventHandlers {
24-
constructor(
25-
@inject(DebugPortAttributesProvider)
26-
private readonly debugPortAttributesProvider: DebugPortAttributesProvider,
27-
) {}
21+
constructor(private readonly debugPortAttributesProvider: DebugPortAttributesProvider) {}
2822

29-
@swallowExceptions("Handle child process launch")
30-
public async handleCustomEvent(
31-
event: DebugSessionCustomEvent,
32-
): Promise<void> {
33-
if (!event || event.session.configuration.type !== DebuggerTypeName) {
34-
return;
35-
}
23+
@swallowExceptions('Handle child process launch')
24+
public async handleCustomEvent(event: DebugSessionCustomEvent): Promise<void> {
25+
if (!event || event.session.configuration.type !== DebuggerTypeName) {
26+
return;
27+
}
3628

37-
if (event.event === DebuggerEvents.DebugpySockets) {
38-
traceLog("Received 'debugpySockets' event from debugpy.");
39-
let portSocket = event.body.sockets.find(
40-
(socket: { [x: string]: any }) => {
41-
return socket["internal"] === false;
42-
},
43-
);
44-
if (portSocket !== undefined) {
45-
this.debugPortAttributesProvider.setPortAttribute(
46-
portSocket.port,
47-
);
48-
}
49-
} else {
50-
return;
51-
}
52-
}
29+
if (event.event === DebuggerEvents.DebugpySockets) {
30+
traceLog("Received 'debugpySockets' event from debugpy.");
31+
let portSocket = event.body.sockets.find((socket: { [x: string]: any }) => {
32+
return socket['internal'] === false;
33+
});
34+
if (portSocket !== undefined) {
35+
this.debugPortAttributesProvider.setPortAttribute(portSocket.port);
36+
}
37+
} else {
38+
return;
39+
}
40+
}
5341
}

Source/extension/extension.ts

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,25 @@
1-
"use strict";
2-
3-
// import * as vscode from 'vscode';
4-
5-
// This line should always be right on top.
6-
import { IExtensionApi } from "./apiTypes";
7-
import { Commands } from "./common/constants";
8-
import { registerLogger, traceError, traceLog } from "./common/log/logging";
9-
import { IExtensionContext } from "./common/types";
10-
import { createOutputChannel, registerCommand } from "./common/vscodeapi";
11-
import { registerDebugger } from "./extensionInit";
12-
import { sendTelemetryEvent } from "./telemetry";
13-
import { EventName } from "./telemetry/constants";
14-
15-
if ((Reflect as any).metadata === undefined) {
16-
require("reflect-metadata");
1+
'use strict';
2+
3+
import { registerDebugger } from './extensionInit';
4+
import { IExtensionContext } from './common/types';
5+
import { createOutputChannel, registerCommand } from './common/vscodeapi';
6+
import { Commands } from './common/constants';
7+
import { registerLogger, traceError } from './common/log/logging';
8+
import { sendTelemetryEvent } from './telemetry';
9+
import { EventName } from './telemetry/constants';
10+
import { IExtensionApi } from './apiTypes';
11+
12+
export async function activate(context: IExtensionContext): Promise<IExtensionApi | undefined> {
13+
const outputChannel = createOutputChannel('Python Debugger');
14+
context.subscriptions.push(outputChannel, registerLogger(outputChannel));
15+
context.subscriptions.push(registerCommand(Commands.ViewOutput, () => outputChannel.show()));
16+
17+
try {
18+
const api = await registerDebugger(context);
19+
sendTelemetryEvent(EventName.DEBUG_SUCCESS_ACTIVATION);
20+
return api;
21+
} catch (ex) {
22+
traceError('sendDebugpySuccessActivationTelemetry() failed.', ex);
23+
throw ex; // re-raise
24+
}
1725
}
18-
19-
// this method is called when your extension is activated
20-
// your extension is activated the very first time the command is executed
21-
export async function activate(
22-
context: IExtensionContext,
23-
): Promise<IExtensionApi> {
24-
let api: IExtensionApi;
25-
// Setup logging
26-
const outputChannel = createOutputChannel("Python Debugger");
27-
context.subscriptions.push(outputChannel, registerLogger(outputChannel));
28-
context.subscriptions.push(
29-
registerCommand(Commands.ViewOutput, () => outputChannel.show()),
30-
);
31-
32-
traceLog(`Name: Python Debugger`);
33-
traceLog(`Module: debugpy`);
34-
35-
try {
36-
api = await registerDebugger(context);
37-
sendTelemetryEvent(EventName.DEBUG_SUCCESS_ACTIVATION);
38-
} catch (ex) {
39-
traceError("sendDebugpySuccessActivationTelemetry() failed.", ex);
40-
throw ex; // re-raise
41-
}
42-
43-
return api;
44-
}
45-
46-
// this method is called when your extension is deactivated
47-
export function deactivate() {}

0 commit comments

Comments
 (0)