Skip to content

Commit 50c6282

Browse files
Update launch resolver
1 parent b9cabd6 commit 50c6282

File tree

5 files changed

+50
-51
lines changed

5 files changed

+50
-51
lines changed

src/client/debugger/extension/configuration/providers/djangoLaunch.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ export async function validateManagePy(
6565
return error;
6666
}
6767
const resolvedPath = resolveVariables(selected, undefined, folder);
68-
69-
if (selected !== defaultValue && !(await fs.pathExists(resolvedPath))) {
70-
return error;
71-
}
72-
if (!resolvedPath.trim().toLowerCase().endsWith('.py')) {
73-
return error;
68+
if (resolvedPath) {
69+
if (selected !== defaultValue && !(await fs.pathExists(resolvedPath))) {
70+
return error;
71+
}
72+
if (!resolvedPath.trim().toLowerCase().endsWith('.py')) {
73+
return error;
74+
}
7475
}
7576
return;
7677
}

src/client/debugger/extension/configuration/providers/pyramidLaunch.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ export async function validateIniPath(
7777
return error;
7878
}
7979
const resolvedPath = resolveVariables(selected, undefined, folder);
80-
if (selected !== defaultValue && !fs.pathExists(resolvedPath)) {
81-
return error;
82-
}
83-
if (!resolvedPath.trim().toLowerCase().endsWith('.ini')) {
84-
return error;
80+
if (resolvedPath) {
81+
if (selected !== defaultValue && !fs.pathExists(resolvedPath)) {
82+
return error;
83+
}
84+
if (!resolvedPath.trim().toLowerCase().endsWith('.ini')) {
85+
return error;
86+
}
8587
}
8688
}
8789

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
import { injectable } from 'inversify';
77
import * as path from 'path';
88
import * as vscode from 'vscode';
9-
import { CancellationToken, DebugConfiguration, Uri, WorkspaceFolder } from 'vscode';
10-
import { IDocumentManager, IWorkspaceService } from '../../../../common/application/types';
9+
import { CancellationToken, DebugConfiguration, Uri, WorkspaceFolder, window } from 'vscode';
1110
import { PYTHON_LANGUAGE } from '../../../../common/constants';
12-
import { IPlatformService } from '../../../../common/platform/types';
1311
import { IConfigurationService } from '../../../../common/types';
1412
import { SystemVariables } from '../../../../common/variables/systemVariables';
1513
import { IInterpreterService } from '../../../../interpreter/contracts';
@@ -20,16 +18,14 @@ import { AttachRequestArguments, DebugOptions, LaunchRequestArguments, PathMappi
2018
import { PythonPathSource } from '../../types';
2119
import { IDebugConfigurationResolver } from '../types';
2220
import { resolveVariables } from '../utils/common';
21+
import { getWorkspaceFolder as getVSCodeWorkspaceFolder } from '../utils/workspaceFolder';
2322

2423
@injectable()
2524
export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
2625
implements IDebugConfigurationResolver<T> {
2726
protected pythonPathSource: PythonPathSource = PythonPathSource.launchJson;
2827

2928
constructor(
30-
protected readonly workspaceService: IWorkspaceService,
31-
protected readonly documentManager: IDocumentManager,
32-
protected readonly platformService: IPlatformService,
3329
protected readonly configurationService: IConfigurationService,
3430
protected readonly interpreterService: IInterpreterService,
3531
) {}
@@ -61,24 +57,25 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
6157
return folder.uri;
6258
}
6359
const program = this.getProgram();
60+
6461
if (!Array.isArray(vscode.workspace.workspaceFolders) || vscode.workspace.workspaceFolders.length === 0) {
6562
return program ? Uri.file(path.dirname(program)) : undefined;
6663
}
6764
if (vscode.workspace.workspaceFolders.length === 1) {
6865
return vscode.workspace.workspaceFolders[0].uri;
6966
}
7067
if (program) {
71-
const workspaceFolder = vscode.workspace.getWorkspaceFolder(Uri.file(program));
68+
const workspaceFolder = getVSCodeWorkspaceFolder(Uri.file(program));
7269
if (workspaceFolder) {
7370
return workspaceFolder.uri;
7471
}
7572
}
7673
}
7774

7875
protected getProgram(): string | undefined {
79-
const editor = this.documentManager.activeTextEditor;
80-
if (editor && editor.document.languageId === PYTHON_LANGUAGE) {
81-
return editor.document.fileName;
76+
const { activeTextEditor } = window;
77+
if (activeTextEditor && activeTextEditor.document.languageId === PYTHON_LANGUAGE) {
78+
return activeTextEditor.document.fileName;
8279
}
8380
}
8481

@@ -111,29 +108,30 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
111108
debugConfiguration: LaunchRequestArguments,
112109
): Promise<void> {
113110
if (!debugConfiguration) {
114-
45;
115111
return;
116112
}
117-
const systemVariables: SystemVariables = new SystemVariables(
118-
undefined,
119-
workspaceFolder?.fsPath,
120-
this.workspaceService,
121-
);
122113
if (debugConfiguration.pythonPath === '${command:python.interpreterPath}' || !debugConfiguration.pythonPath) {
123114
const interpreterPath =
124115
(await this.interpreterService.getActiveInterpreter(workspaceFolder))?.path ??
125116
this.configurationService.getSettings(workspaceFolder).pythonPath;
126117
debugConfiguration.pythonPath = interpreterPath;
127118
} else {
128-
debugConfiguration.pythonPath = systemVariables.resolveAny(debugConfiguration.pythonPath);
119+
debugConfiguration.pythonPath = resolveVariables(
120+
debugConfiguration.pythonPath ? debugConfiguration.pythonPath : undefined,
121+
workspaceFolder?.fsPath,
122+
undefined,
123+
);
129124
}
130125
if (debugConfiguration.python === '${command:python.interpreterPath}' || !debugConfiguration.python) {
131126
this.pythonPathSource = PythonPathSource.settingsJson;
132127
} else {
133128
this.pythonPathSource = PythonPathSource.launchJson;
134129
}
135-
debugConfiguration.python = systemVariables.resolveAny(debugConfiguration.python);
136-
const newDebug = resolveVariables(debugConfiguration.python.pythonPath);
130+
debugConfiguration.python = resolveVariables(
131+
debugConfiguration.python ? debugConfiguration.python : undefined,
132+
workspaceFolder?.fsPath,
133+
undefined,
134+
);
137135
}
138136

139137
protected debugOption(debugOptions: DebugOptions[], debugOption: DebugOptions) {
@@ -179,7 +177,7 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
179177

180178
// If on Windows, lowercase the drive letter for path mappings.
181179
// TODO: Apply even if no localRoot?
182-
if (this.platformService.isWindows) {
180+
if (/^win/.test(process.platform)) {
183181
// TODO: Apply to remoteRoot too?
184182
pathMappings = pathMappings.map(({ localRoot: windowsLocalRoot, remoteRoot }) => {
185183
let localRoot = windowsLocalRoot;

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { inject, injectable, named } from 'inversify';
77
import { CancellationToken, Uri, WorkspaceFolder } from 'vscode';
88
import { InvalidPythonPathInDebuggerServiceId } from '../../../../application/diagnostics/checks/invalidPythonPathInDebugger';
99
import { IDiagnosticsService, IInvalidPythonPathInDebuggerService } from '../../../../application/diagnostics/types';
10-
import { IDocumentManager, IWorkspaceService } from '../../../../common/application/types';
11-
import { IPlatformService } from '../../../../common/platform/types';
1210
import { IConfigurationService } from '../../../../common/types';
1311
import { IInterpreterService } from '../../../../interpreter/contracts';
1412
import { DebuggerTypeName } from '../../../constants';
@@ -19,17 +17,14 @@ import { IDebugEnvironmentVariablesService } from './helper';
1917
@injectable()
2018
export class LaunchConfigurationResolver extends BaseConfigurationResolver<LaunchRequestArguments> {
2119
constructor(
22-
@inject(IWorkspaceService) workspaceService: IWorkspaceService,
23-
@inject(IDocumentManager) documentManager: IDocumentManager,
2420
@inject(IDiagnosticsService)
2521
@named(InvalidPythonPathInDebuggerServiceId)
2622
private readonly invalidPythonPathInDebuggerService: IInvalidPythonPathInDebuggerService,
27-
@inject(IPlatformService) platformService: IPlatformService,
2823
@inject(IConfigurationService) configurationService: IConfigurationService,
2924
@inject(IDebugEnvironmentVariablesService) private readonly debugEnvHelper: IDebugEnvironmentVariablesService,
3025
@inject(IInterpreterService) interpreterService: IInterpreterService,
3126
) {
32-
super(workspaceService, documentManager, platformService, configurationService, interpreterService);
27+
super(configurationService, interpreterService);
3328
}
3429

3530
public async resolveDebugConfiguration(
@@ -153,7 +148,7 @@ export class LaunchConfigurationResolver extends BaseConfigurationResolver<Launc
153148
if (debugConfiguration.subProcess === true) {
154149
this.debugOption(debugOptions, DebugOptions.SubProcess);
155150
}
156-
if (this.platformService.isWindows) {
151+
if (/^win/.test(process.platform)) {
157152
this.debugOption(debugOptions, DebugOptions.FixFilePathCase);
158153
}
159154
const isFastAPI = this.isDebuggingFastAPI(debugConfiguration);

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,23 @@ function isString(str: any): str is string {
2121
}
2222

2323
export function resolveVariables(
24-
value: string,
24+
value: string | undefined,
2525
rootFolder: string | undefined,
2626
folder: WorkspaceFolder | undefined,
27-
): string {
28-
const workspace = folder ? getWorkspaceFolder(folder.uri) : undefined;
29-
const variablesObject: { [key: string]: any } = {};
30-
variablesObject.workspaceFolder = workspace ? workspace.uri.fsPath : rootFolder;
27+
): string | undefined {
28+
if (value) {
29+
const workspace = folder ? getWorkspaceFolder(folder.uri) : undefined;
30+
const variablesObject: { [key: string]: any } = {};
31+
variablesObject.workspaceFolder = workspace ? workspace.uri.fsPath : rootFolder;
3132

32-
const regexp = /\$\{(.*?)\}/g;
33-
return value.replace(regexp, (match: string, name: string) => {
34-
const newValue = variablesObject[name];
35-
if (isString(newValue)) {
36-
return newValue;
37-
}
38-
return match && (match.indexOf('env.') > 0 || match.indexOf('env:') > 0) ? '' : match;
39-
});
33+
const regexp = /\$\{(.*?)\}/g;
34+
return value.replace(regexp, (match: string, name: string) => {
35+
const newValue = variablesObject[name];
36+
if (isString(newValue)) {
37+
return newValue;
38+
}
39+
return match && (match.indexOf('env.') > 0 || match.indexOf('env:') > 0) ? '' : match;
40+
});
41+
}
42+
return value;
4043
}

0 commit comments

Comments
 (0)