Skip to content

Commit ce6a11d

Browse files
committed
Handle debug in terminai with undefined uri (#17375)
1 parent ca3bcc1 commit ce6a11d

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

news/2 Fixes/17374.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix to handle undefined uri in debug in terminal command.

src/client/debugger/extension/configuration/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ export interface IDebugConfigurationProviderFactory {
2929
export const ILaunchJsonReader = Symbol('ILaunchJsonReader');
3030
export interface ILaunchJsonReader {
3131
getConfigurationsForWorkspace(workspace: WorkspaceFolder): Promise<DebugConfiguration[]>;
32-
getConfigurationsByUri(uri: Uri): Promise<DebugConfiguration[]>;
32+
getConfigurationsByUri(uri?: Uri): Promise<DebugConfiguration[]>;
3333
}

src/client/debugger/extension/debugCommands.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class DebugCommands implements IExtensionSingleActivationService {
2424

2525
public activate(): Promise<void> {
2626
this.disposables.push(
27-
this.commandManager.registerCommand(Commands.Debug_In_Terminal, async (file: Uri) => {
27+
this.commandManager.registerCommand(Commands.Debug_In_Terminal, async (file?: Uri) => {
2828
sendTelemetryEvent(EventName.DEBUG_IN_TERMINAL_BUTTON);
2929
const config = await this.getDebugConfiguration(file);
3030
this.debugService.startDebugging(undefined, config);
@@ -33,13 +33,13 @@ export class DebugCommands implements IExtensionSingleActivationService {
3333
return Promise.resolve();
3434
}
3535

36-
private async getDebugConfiguration(uri: Uri): Promise<DebugConfiguration> {
36+
private async getDebugConfiguration(uri?: Uri): Promise<DebugConfiguration> {
3737
const configs = (await this.launchJsonReader.getConfigurationsByUri(uri)).filter((c) => c.request === 'launch');
3838
for (const config of configs) {
3939
if ((config as LaunchRequestArguments).purpose?.includes(DebugPurpose.DebugInTerminal)) {
4040
if (!config.program && !config.module && !config.code) {
4141
// This is only needed if people reuse debug-test for debug-in-terminal
42-
config.program = uri.fsPath;
42+
config.program = uri?.fsPath ?? '${file}';
4343
}
4444
// Ensure that the purpose is cleared, this is so we can track if people accidentally
4545
// trigger this via F5 or Start with debugger.
@@ -48,10 +48,10 @@ export class DebugCommands implements IExtensionSingleActivationService {
4848
}
4949
}
5050
return {
51-
name: `Debug ${path.basename(uri.fsPath)}`,
51+
name: `Debug ${uri ? path.basename(uri.fsPath) : 'File'}`,
5252
type: 'python',
5353
request: 'launch',
54-
program: uri.fsPath,
54+
program: uri?.fsPath ?? '${file}',
5555
console: 'integratedTerminal',
5656
};
5757
}

0 commit comments

Comments
 (0)