6
6
import { injectable } from 'inversify' ;
7
7
import * as path from 'path' ;
8
8
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' ;
11
10
import { PYTHON_LANGUAGE } from '../../../../common/constants' ;
12
- import { IPlatformService } from '../../../../common/platform/types' ;
13
11
import { IConfigurationService } from '../../../../common/types' ;
14
12
import { SystemVariables } from '../../../../common/variables/systemVariables' ;
15
13
import { IInterpreterService } from '../../../../interpreter/contracts' ;
@@ -20,16 +18,14 @@ import { AttachRequestArguments, DebugOptions, LaunchRequestArguments, PathMappi
20
18
import { PythonPathSource } from '../../types' ;
21
19
import { IDebugConfigurationResolver } from '../types' ;
22
20
import { resolveVariables } from '../utils/common' ;
21
+ import { getWorkspaceFolder as getVSCodeWorkspaceFolder } from '../utils/workspaceFolder' ;
23
22
24
23
@injectable ( )
25
24
export abstract class BaseConfigurationResolver < T extends DebugConfiguration >
26
25
implements IDebugConfigurationResolver < T > {
27
26
protected pythonPathSource : PythonPathSource = PythonPathSource . launchJson ;
28
27
29
28
constructor (
30
- protected readonly workspaceService : IWorkspaceService ,
31
- protected readonly documentManager : IDocumentManager ,
32
- protected readonly platformService : IPlatformService ,
33
29
protected readonly configurationService : IConfigurationService ,
34
30
protected readonly interpreterService : IInterpreterService ,
35
31
) { }
@@ -61,24 +57,25 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
61
57
return folder . uri ;
62
58
}
63
59
const program = this . getProgram ( ) ;
60
+
64
61
if ( ! Array . isArray ( vscode . workspace . workspaceFolders ) || vscode . workspace . workspaceFolders . length === 0 ) {
65
62
return program ? Uri . file ( path . dirname ( program ) ) : undefined ;
66
63
}
67
64
if ( vscode . workspace . workspaceFolders . length === 1 ) {
68
65
return vscode . workspace . workspaceFolders [ 0 ] . uri ;
69
66
}
70
67
if ( program ) {
71
- const workspaceFolder = vscode . workspace . getWorkspaceFolder ( Uri . file ( program ) ) ;
68
+ const workspaceFolder = getVSCodeWorkspaceFolder ( Uri . file ( program ) ) ;
72
69
if ( workspaceFolder ) {
73
70
return workspaceFolder . uri ;
74
71
}
75
72
}
76
73
}
77
74
78
75
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 ;
82
79
}
83
80
}
84
81
@@ -111,29 +108,30 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
111
108
debugConfiguration : LaunchRequestArguments ,
112
109
) : Promise < void > {
113
110
if ( ! debugConfiguration ) {
114
- 45 ;
115
111
return ;
116
112
}
117
- const systemVariables : SystemVariables = new SystemVariables (
118
- undefined ,
119
- workspaceFolder ?. fsPath ,
120
- this . workspaceService ,
121
- ) ;
122
113
if ( debugConfiguration . pythonPath === '${command:python.interpreterPath}' || ! debugConfiguration . pythonPath ) {
123
114
const interpreterPath =
124
115
( await this . interpreterService . getActiveInterpreter ( workspaceFolder ) ) ?. path ??
125
116
this . configurationService . getSettings ( workspaceFolder ) . pythonPath ;
126
117
debugConfiguration . pythonPath = interpreterPath ;
127
118
} else {
128
- debugConfiguration . pythonPath = systemVariables . resolveAny ( debugConfiguration . pythonPath ) ;
119
+ debugConfiguration . pythonPath = resolveVariables (
120
+ debugConfiguration . pythonPath ? debugConfiguration . pythonPath : undefined ,
121
+ workspaceFolder ?. fsPath ,
122
+ undefined ,
123
+ ) ;
129
124
}
130
125
if ( debugConfiguration . python === '${command:python.interpreterPath}' || ! debugConfiguration . python ) {
131
126
this . pythonPathSource = PythonPathSource . settingsJson ;
132
127
} else {
133
128
this . pythonPathSource = PythonPathSource . launchJson ;
134
129
}
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
+ ) ;
137
135
}
138
136
139
137
protected debugOption ( debugOptions : DebugOptions [ ] , debugOption : DebugOptions ) {
@@ -179,7 +177,7 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
179
177
180
178
// If on Windows, lowercase the drive letter for path mappings.
181
179
// TODO: Apply even if no localRoot?
182
- if ( this . platformService . isWindows ) {
180
+ if ( / ^ w i n / . test ( process . platform ) ) {
183
181
// TODO: Apply to remoteRoot too?
184
182
pathMappings = pathMappings . map ( ( { localRoot : windowsLocalRoot , remoteRoot } ) => {
185
183
let localRoot = windowsLocalRoot ;
0 commit comments