6
6
import { injectable } from 'inversify' ;
7
7
import * as path from 'path' ;
8
8
import { CancellationToken , DebugConfiguration , Uri , WorkspaceFolder } from 'vscode' ;
9
- import { IDocumentManager , IWorkspaceService } from '../../../../common/application/types' ;
10
9
import { PYTHON_LANGUAGE } from '../../../../common/constants' ;
11
- import { IPlatformService } from '../../../../common/platform/types' ;
12
10
import { IConfigurationService } from '../../../../common/types' ;
13
- import { SystemVariables } from '../../../../common/variables/systemVariables ' ;
11
+ import { getOSType , OSType } from '../../../../common/utils/platform ' ;
14
12
import { IInterpreterService } from '../../../../interpreter/contracts' ;
15
13
import { sendTelemetryEvent } from '../../../../telemetry' ;
16
14
import { EventName } from '../../../../telemetry/constants' ;
17
15
import { DebuggerTelemetry } from '../../../../telemetry/types' ;
18
16
import { AttachRequestArguments , DebugOptions , LaunchRequestArguments , PathMapping } from '../../../types' ;
19
17
import { PythonPathSource } from '../../types' ;
20
18
import { IDebugConfigurationResolver } from '../types' ;
19
+ import { getActiveTextEditor , resolveVariables } from '../utils/common' ;
20
+ import { getWorkspaceFolder as getVSCodeWorkspaceFolder , getWorkspaceFolders } from '../utils/workspaceFolder' ;
21
21
22
22
@injectable ( )
23
23
export abstract class BaseConfigurationResolver < T extends DebugConfiguration >
24
24
implements IDebugConfigurationResolver < T > {
25
25
protected pythonPathSource : PythonPathSource = PythonPathSource . launchJson ;
26
26
27
27
constructor (
28
- protected readonly workspaceService : IWorkspaceService ,
29
- protected readonly documentManager : IDocumentManager ,
30
- protected readonly platformService : IPlatformService ,
31
28
protected readonly configurationService : IConfigurationService ,
32
29
protected readonly interpreterService : IInterpreterService ,
33
30
) { }
@@ -59,27 +56,26 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
59
56
return folder . uri ;
60
57
}
61
58
const program = this . getProgram ( ) ;
62
- if (
63
- ! Array . isArray ( this . workspaceService . workspaceFolders ) ||
64
- this . workspaceService . workspaceFolders . length === 0
65
- ) {
59
+ let workspaceFolders = getWorkspaceFolders ( ) ;
60
+
61
+ if ( ! Array . isArray ( workspaceFolders ) || workspaceFolders . length === 0 ) {
66
62
return program ? Uri . file ( path . dirname ( program ) ) : undefined ;
67
63
}
68
- if ( this . workspaceService . workspaceFolders . length === 1 ) {
69
- return this . workspaceService . workspaceFolders [ 0 ] . uri ;
64
+ if ( workspaceFolders . length === 1 ) {
65
+ return workspaceFolders [ 0 ] . uri ;
70
66
}
71
67
if ( program ) {
72
- const workspaceFolder = this . workspaceService . getWorkspaceFolder ( Uri . file ( program ) ) ;
68
+ const workspaceFolder = getVSCodeWorkspaceFolder ( Uri . file ( program ) ) ;
73
69
if ( workspaceFolder ) {
74
70
return workspaceFolder . uri ;
75
71
}
76
72
}
77
73
}
78
74
79
75
protected getProgram ( ) : string | undefined {
80
- const editor = this . documentManager . activeTextEditor ;
81
- if ( editor && editor . document . languageId === PYTHON_LANGUAGE ) {
82
- return editor . document . fileName ;
76
+ const activeTextEditor = getActiveTextEditor ( ) ;
77
+ if ( activeTextEditor && activeTextEditor . document . languageId === PYTHON_LANGUAGE ) {
78
+ return activeTextEditor . document . fileName ;
83
79
}
84
80
}
85
81
@@ -99,11 +95,11 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
99
95
return ;
100
96
}
101
97
if ( debugConfiguration . envFile && ( workspaceFolder || debugConfiguration . cwd ) ) {
102
- const systemVariables = new SystemVariables (
103
- undefined ,
98
+ debugConfiguration . envFile = resolveVariables (
99
+ debugConfiguration . envFile ,
104
100
( workspaceFolder ? workspaceFolder . fsPath : undefined ) || debugConfiguration . cwd ,
101
+ undefined ,
105
102
) ;
106
- debugConfiguration . envFile = systemVariables . resolveAny ( debugConfiguration . envFile ) ;
107
103
}
108
104
}
109
105
@@ -114,25 +110,28 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
114
110
if ( ! debugConfiguration ) {
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 ) ;
130
+ debugConfiguration . python = resolveVariables (
131
+ debugConfiguration . python ? debugConfiguration . python : undefined ,
132
+ workspaceFolder ?. fsPath ,
133
+ undefined ,
134
+ ) ;
136
135
}
137
136
138
137
protected debugOption ( debugOptions : DebugOptions [ ] , debugOption : DebugOptions ) {
@@ -168,17 +167,19 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
168
167
] ;
169
168
} else {
170
169
// Expand ${workspaceFolder} variable first if necessary.
171
- const systemVariables = new SystemVariables ( undefined , defaultLocalRoot ) ;
172
- pathMappings = pathMappings . map ( ( { localRoot : mappedLocalRoot , remoteRoot } ) => ( {
173
- localRoot : systemVariables . resolveAny ( mappedLocalRoot ) ,
174
- // TODO: Apply to remoteRoot too?
175
- remoteRoot,
176
- } ) ) ;
170
+ pathMappings = pathMappings . map ( ( { localRoot : mappedLocalRoot , remoteRoot } ) => {
171
+ let resolvedLocalRoot = resolveVariables ( mappedLocalRoot , defaultLocalRoot , undefined ) ;
172
+ return {
173
+ localRoot : resolvedLocalRoot ? resolvedLocalRoot : '' ,
174
+ // TODO: Apply to remoteRoot too?
175
+ remoteRoot,
176
+ } ;
177
+ } ) ;
177
178
}
178
179
179
180
// If on Windows, lowercase the drive letter for path mappings.
180
181
// TODO: Apply even if no localRoot?
181
- if ( this . platformService . isWindows ) {
182
+ if ( getOSType ( ) == OSType . Windows ) {
182
183
// TODO: Apply to remoteRoot too?
183
184
pathMappings = pathMappings . map ( ( { localRoot : windowsLocalRoot , remoteRoot } ) => {
184
185
let localRoot = windowsLocalRoot ;
0 commit comments