Skip to content

Add api and send debugpy path #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/extension/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function buildApi(): IExtensionApi {
waitUntilDebuggerAttaches,
});
},
async getDebuggerPackagePath(): Promise<string | undefined> {
async getDebuggerPackagePath(): Promise<string> {
return getDebugpyPackagePath();
},
},
Expand Down
10 changes: 0 additions & 10 deletions src/extension/apiTypes.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

/*
* Do not introduce any breaking changes to this API.
* This is the public API for other extensions to interact with this extension.
*/

export interface IExtensionApi {
/**
* Promise indicating whether all parts of the extension have completed loading or not.
* @type {Promise<void>}
* @memberof IExtensionApi
*/
debug: {
/**
* Generate an array of strings for commands to pass to the Python executable to launch the debugger for remote debugging.
Expand Down
9 changes: 7 additions & 2 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import { Commands } from './common/constants';
import { registerLogger, traceError, traceLog } from './common/log/logging';
import { sendTelemetryEvent } from './telemetry';
import { EventName } from './telemetry/constants';
import { IExtensionApi } from './apiTypes';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export async function activate(context: IExtensionContext): Promise<void> {
export async function activate(context: IExtensionContext): Promise<IExtensionApi> {
let api: IExtensionApi;
// Setup logging
const outputChannel = createOutputChannel('Python Debugger');
context.subscriptions.push(outputChannel, registerLogger(outputChannel));
Expand All @@ -28,11 +30,14 @@ export async function activate(context: IExtensionContext): Promise<void> {
traceLog(`Module: debugpy`);

try {
await registerDebugger(context);
api = await registerDebugger(context);
sendTelemetryEvent(EventName.DEBUG_SUCCESS_ACTIVATION);
} catch (ex) {
traceError('sendDebugpySuccessActivationTelemetry() failed.', ex);
throw ex; // re-raise
}

return api;
}

// this method is called when your extension is deactivated
Expand Down
6 changes: 5 additions & 1 deletion src/extension/extensionInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
import { getConfigurationsByUri } from './debugger/configuration/launch.json/launchJsonReader';
import { DebugpySocketsHandler } from './debugger/hooks/debugpySocketsHandler';
import { openReportIssue } from './common/application/commands/reportIssueCommand';
import { buildApi } from './api';
import { IExtensionApi } from './apiTypes';

export async function registerDebugger(context: IExtensionContext): Promise<void> {
export async function registerDebugger(context: IExtensionContext): Promise<IExtensionApi> {
const childProcessAttachService = new ChildProcessAttachService();
const childProcessAttachEventHandler = new ChildProcessAttachEventHandler(childProcessAttachService);

Expand Down Expand Up @@ -93,7 +95,7 @@
executeCommand('workbench.action.debug.selectandstart');
} else {
await executeCommand('debug.addConfiguration');
if (file) await window.showTextDocument(file);

Check warning on line 98 in src/extension/extensionInit.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected { after 'if' condition

Check warning on line 98 in src/extension/extensionInit.ts

View workflow job for this annotation

GitHub Actions / Tests (ubuntu-latest, 3.11)

Expected { after 'if' condition

Check warning on line 98 in src/extension/extensionInit.ts

View workflow job for this annotation

GitHub Actions / Tests (ubuntu-latest, 3.10)

Expected { after 'if' condition

Check warning on line 98 in src/extension/extensionInit.ts

View workflow job for this annotation

GitHub Actions / Tests (ubuntu-latest, 3.7)

Expected { after 'if' condition

Check warning on line 98 in src/extension/extensionInit.ts

View workflow job for this annotation

GitHub Actions / Tests (ubuntu-latest, 3.9)

Expected { after 'if' condition

Check warning on line 98 in src/extension/extensionInit.ts

View workflow job for this annotation

GitHub Actions / Tests (ubuntu-latest, 3.8)

Expected { after 'if' condition

Check warning on line 98 in src/extension/extensionInit.ts

View workflow job for this annotation

GitHub Actions / Tests (windows-latest, 3.10)

Expected { after 'if' condition

Check warning on line 98 in src/extension/extensionInit.ts

View workflow job for this annotation

GitHub Actions / Tests (windows-latest, 3.8)

Expected { after 'if' condition

Check warning on line 98 in src/extension/extensionInit.ts

View workflow job for this annotation

GitHub Actions / Tests (windows-latest, 3.11)

Expected { after 'if' condition

Check warning on line 98 in src/extension/extensionInit.ts

View workflow job for this annotation

GitHub Actions / Tests (windows-latest, 3.9)

Expected { after 'if' condition

Check warning on line 98 in src/extension/extensionInit.ts

View workflow job for this annotation

GitHub Actions / Tests (windows-latest, 3.7)

Expected { after 'if' condition
executeCommand('workbench.action.debug.start', file?.toString());
}
}),
Expand Down Expand Up @@ -172,4 +174,6 @@
debugPortAttributesProvider.resetPortAttribute();
}),
);

return buildApi();
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"ES2019",
"ES2020"
],
"typeRoots": ["./node_modules/@types"],
"sourceMap": true,
"typeRoots": [
"./node_modules/@types"
Expand Down
Loading