Skip to content

Commit f9e98fc

Browse files
Simplify launch debug (#20286)
Closed: #19770
1 parent 71766e3 commit f9e98fc

23 files changed

+154
-177
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ src/client/formatters/baseFormatter.ts
172172
src/client/testing/serviceRegistry.ts
173173
src/client/testing/main.ts
174174
src/client/testing/configurationFactory.ts
175-
src/client/testing/common/debugLauncher.ts
176175
src/client/testing/common/constants.ts
177176
src/client/testing/common/testUtils.ts
178177
src/client/testing/common/socketServer.ts

src/client/common/vscodeApis/windowApis.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ProgressOptions,
1010
QuickPickItem,
1111
QuickPickOptions,
12+
TextEditor,
1213
window,
1314
} from 'vscode';
1415

@@ -61,3 +62,8 @@ export function withProgress<R>(
6162
): Thenable<R> {
6263
return window.withProgress(options, task);
6364
}
65+
66+
export function getActiveTextEditor(): TextEditor | undefined {
67+
const { activeTextEditor } = window;
68+
return activeTextEditor;
69+
}

src/client/common/vscodeApis/workspaceApis.ts

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

4-
import { ConfigurationScope, workspace, WorkspaceConfiguration, WorkspaceFolder } from 'vscode';
4+
import { ConfigurationScope, workspace, WorkspaceConfiguration, WorkspaceEdit, WorkspaceFolder } from 'vscode';
55
import { Resource } from '../types';
66

77
export function getWorkspaceFolders(): readonly WorkspaceFolder[] | undefined {
@@ -19,3 +19,7 @@ export function getWorkspaceFolderPaths(): string[] {
1919
export function getConfiguration(section?: string, scope?: ConfigurationScope | null): WorkspaceConfiguration {
2020
return workspace.getConfiguration(section, scope);
2121
}
22+
23+
export function applyEdit(edit: WorkspaceEdit): Thenable<boolean> {
24+
return workspace.applyEdit(edit);
25+
}

src/client/debugger/extension/configuration/launch.json/interpreterPathCommand.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,23 @@
66
import { inject, injectable } from 'inversify';
77
import { Uri } from 'vscode';
88
import { IExtensionSingleActivationService } from '../../../../activation/types';
9-
import { ICommandManager } from '../../../../common/application/types';
109
import { Commands } from '../../../../common/constants';
1110
import { IDisposable, IDisposableRegistry } from '../../../../common/types';
11+
import { registerCommand } from '../../../../common/vscodeApis/commandApis';
1212
import { IInterpreterService } from '../../../../interpreter/contracts';
1313

1414
@injectable()
1515
export class InterpreterPathCommand implements IExtensionSingleActivationService {
1616
public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: false };
1717

1818
constructor(
19-
@inject(ICommandManager) private readonly commandManager: ICommandManager,
2019
@inject(IInterpreterService) private readonly interpreterService: IInterpreterService,
2120
@inject(IDisposableRegistry) private readonly disposables: IDisposable[],
2221
) {}
2322

2423
public async activate(): Promise<void> {
2524
this.disposables.push(
26-
this.commandManager.registerCommand(Commands.GetSelectedInterpreterPath, (args) =>
27-
this._getSelectedInterpreterPath(args),
28-
),
25+
registerCommand(Commands.GetSelectedInterpreterPath, (args) => this._getSelectedInterpreterPath(args)),
2926
);
3027
}
3128

src/client/debugger/extension/configuration/launch.json/launchJsonReader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as path from 'path';
55
import * as fs from 'fs-extra';
66
import { parse } from 'jsonc-parser';
77
import { DebugConfiguration, Uri, WorkspaceFolder } from 'vscode';
8-
import { getWorkspaceFolder } from '../utils/workspaceFolder';
8+
import { getWorkspaceFolder } from '../../../../common/vscodeApis/workspaceApis';
99

1010
export async function getConfigurationsForWorkspace(workspace: WorkspaceFolder): Promise<DebugConfiguration[]> {
1111
const filename = path.join(workspace.uri.fsPath, '.vscode', 'launch.json');

src/client/debugger/extension/configuration/launch.json/updaterService.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import { inject, injectable } from 'inversify';
77
import { IExtensionSingleActivationService } from '../../../../activation/types';
8-
import { ICommandManager } from '../../../../common/application/types';
98
import { IDisposableRegistry } from '../../../../common/types';
9+
import { registerCommand } from '../../../../common/vscodeApis/commandApis';
1010
import { IDebugConfigurationService } from '../../types';
1111
import { LaunchJsonUpdaterServiceHelper } from './updaterServiceHelper';
1212

@@ -15,19 +15,14 @@ export class LaunchJsonUpdaterService implements IExtensionSingleActivationServi
1515
public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: false };
1616

1717
constructor(
18-
@inject(ICommandManager) private readonly commandManager: ICommandManager,
1918
@inject(IDisposableRegistry) private readonly disposableRegistry: IDisposableRegistry,
2019
@inject(IDebugConfigurationService) private readonly configurationProvider: IDebugConfigurationService,
2120
) {}
2221

2322
public async activate(): Promise<void> {
24-
const handler = new LaunchJsonUpdaterServiceHelper(this.commandManager, this.configurationProvider);
23+
const handler = new LaunchJsonUpdaterServiceHelper(this.configurationProvider);
2524
this.disposableRegistry.push(
26-
this.commandManager.registerCommand(
27-
'python.SelectAndInsertDebugConfiguration',
28-
handler.selectAndInsertDebugConfig,
29-
handler,
30-
),
25+
registerCommand('python.SelectAndInsertDebugConfiguration', handler.selectAndInsertDebugConfig, handler),
3126
);
3227
}
3328
}

src/client/debugger/extension/configuration/launch.json/updaterServiceHelper.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@
55

66
import { createScanner, parse, SyntaxKind } from 'jsonc-parser';
77
import { CancellationToken, DebugConfiguration, Position, Range, TextDocument, WorkspaceEdit } from 'vscode';
8-
import { ICommandManager } from '../../../../common/application/types';
98
import { noop } from '../../../../common/utils/misc';
9+
import { executeCommand } from '../../../../common/vscodeApis/commandApis';
10+
import { getActiveTextEditor } from '../../../../common/vscodeApis/windowApis';
11+
import { applyEdit, getWorkspaceFolder } from '../../../../common/vscodeApis/workspaceApis';
1012
import { captureTelemetry } from '../../../../telemetry';
1113
import { EventName } from '../../../../telemetry/constants';
1214
import { IDebugConfigurationService } from '../../types';
13-
import { applyEdit, getActiveTextEditor } from '../utils/common';
14-
import { getWorkspaceFolder } from '../utils/workspaceFolder';
1515

1616
type PositionOfCursor = 'InsideEmptyArray' | 'BeforeItem' | 'AfterItem';
1717
type PositionOfComma = 'BeforeCursor';
1818

1919
export class LaunchJsonUpdaterServiceHelper {
20-
constructor(
21-
private readonly commandManager: ICommandManager,
22-
private readonly configurationProvider: IDebugConfigurationService,
23-
) {}
20+
constructor(private readonly configurationProvider: IDebugConfigurationService) {}
2421

2522
@captureTelemetry(EventName.DEBUGGER_CONFIGURATION_PROMPTS_IN_LAUNCH_JSON)
2623
public async selectAndInsertDebugConfig(
@@ -35,7 +32,7 @@ export class LaunchJsonUpdaterServiceHelper {
3532

3633
if (!token.isCancellationRequested && Array.isArray(configs) && configs.length > 0) {
3734
// Always use the first available debug configuration.
38-
await this.insertDebugConfiguration(document, position, configs[0]);
35+
await LaunchJsonUpdaterServiceHelper.insertDebugConfiguration(document, position, configs[0]);
3936
}
4037
}
4138
}
@@ -49,7 +46,7 @@ export class LaunchJsonUpdaterServiceHelper {
4946
* @returns {Promise<void>}
5047
* @memberof LaunchJsonCompletionItemProvider
5148
*/
52-
public async insertDebugConfiguration(
49+
public static async insertDebugConfiguration(
5350
document: TextDocument,
5451
position: Position,
5552
config: DebugConfiguration,
@@ -68,7 +65,7 @@ export class LaunchJsonUpdaterServiceHelper {
6865
const workspaceEdit = new WorkspaceEdit();
6966
workspaceEdit.insert(document.uri, position, formattedJson);
7067
await applyEdit(workspaceEdit);
71-
this.commandManager.executeCommand('editor.action.formatDocument').then(noop, noop);
68+
executeCommand('editor.action.formatDocument').then(noop, noop);
7269
}
7370

7471
/**

src/client/debugger/extension/configuration/resolvers/base.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import * as path from 'path';
88
import { CancellationToken, DebugConfiguration, Uri, WorkspaceFolder } from 'vscode';
99
import { IConfigurationService } from '../../../../common/types';
1010
import { getOSType, OSType } from '../../../../common/utils/platform';
11+
import {
12+
getWorkspaceFolder as getVSCodeWorkspaceFolder,
13+
getWorkspaceFolders,
14+
} from '../../../../common/vscodeApis/workspaceApis';
1115
import { IInterpreterService } from '../../../../interpreter/contracts';
1216
import { sendTelemetryEvent } from '../../../../telemetry';
1317
import { EventName } from '../../../../telemetry/constants';
@@ -16,7 +20,6 @@ import { AttachRequestArguments, DebugOptions, LaunchRequestArguments, PathMappi
1620
import { PythonPathSource } from '../../types';
1721
import { IDebugConfigurationResolver } from '../types';
1822
import { resolveVariables } from '../utils/common';
19-
import { getWorkspaceFolder as getVSCodeWorkspaceFolder, getWorkspaceFolders } from '../utils/workspaceFolder';
2023
import { getProgram } from './helper';
2124

2225
@injectable()

src/client/debugger/extension/configuration/resolvers/helper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
'use strict';
55

66
import { inject, injectable } from 'inversify';
7-
import { ICurrentProcess, IPathUtils } from '../../../../common/types';
7+
import { ICurrentProcess } from '../../../../common/types';
88
import { EnvironmentVariables, IEnvironmentVariablesService } from '../../../../common/variables/types';
99
import { LaunchRequestArguments } from '../../../types';
10-
import { getActiveTextEditor } from '../utils/common';
1110
import { PYTHON_LANGUAGE } from '../../../../common/constants';
11+
import { getActiveTextEditor } from '../../../../common/vscodeApis/windowApis';
12+
import { getSearchPathEnvVarNames } from '../../../../common/utils/exec';
1213

1314
export const IDebugEnvironmentVariablesService = Symbol('IDebugEnvironmentVariablesService');
1415
export interface IDebugEnvironmentVariablesService {
@@ -19,12 +20,11 @@ export interface IDebugEnvironmentVariablesService {
1920
export class DebugEnvironmentVariablesHelper implements IDebugEnvironmentVariablesService {
2021
constructor(
2122
@inject(IEnvironmentVariablesService) private envParser: IEnvironmentVariablesService,
22-
@inject(IPathUtils) private pathUtils: IPathUtils,
2323
@inject(ICurrentProcess) private process: ICurrentProcess,
2424
) {}
2525

2626
public async getEnvironmentVariables(args: LaunchRequestArguments): Promise<EnvironmentVariables> {
27-
const pathVariableName = this.pathUtils.getPathVariableName();
27+
const pathVariableName = getSearchPathEnvVarNames()[0];
2828

2929
// Merge variables from both .env file and env json variables.
3030
const debugLaunchEnvVars: Record<string, string> =

src/client/debugger/extension/configuration/utils/common.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
'use strict';
88

9-
import { WorkspaceFolder, window, TextEditor, WorkspaceEdit, workspace } from 'vscode';
10-
import { getWorkspaceFolder } from './workspaceFolder';
9+
import { WorkspaceFolder } from 'vscode';
10+
import { getWorkspaceFolder } from '../../../../common/vscodeApis/workspaceApis';
1111

1212
/**
1313
* @returns whether the provided parameter is a JavaScript String or not.
@@ -41,12 +41,3 @@ export function resolveVariables(
4141
}
4242
return value;
4343
}
44-
45-
export function getActiveTextEditor(): TextEditor | undefined {
46-
const { activeTextEditor } = window;
47-
return activeTextEditor;
48-
}
49-
50-
export function applyEdit(edit: WorkspaceEdit): Thenable<boolean> {
51-
return workspace.applyEdit(edit);
52-
}

0 commit comments

Comments
 (0)