@@ -25,7 +25,7 @@ namespace Microsoft.PowerShell.EditorServices.Engine.Services
25
25
/// Provides a high-level service for interacting with the
26
26
/// PowerShell debugger in the runspace managed by a PowerShellContext.
27
27
/// </summary>
28
- public class DebugService
28
+ internal class DebugService
29
29
{
30
30
#region Fields
31
31
@@ -34,14 +34,14 @@ public class DebugService
34
34
35
35
private readonly ILogger logger ;
36
36
private readonly PowerShellContextService powerShellContext ;
37
- // private RemoteFileManagerService remoteFileManager;
37
+ private RemoteFileManagerService remoteFileManager ;
38
38
39
39
// TODO: This needs to be managed per nested session
40
40
private readonly Dictionary < string , List < Breakpoint > > breakpointsPerFile =
41
41
new Dictionary < string , List < Breakpoint > > ( ) ;
42
42
43
43
private int nextVariableId ;
44
- private readonly string temporaryScriptListingPath ;
44
+ private string temporaryScriptListingPath ;
45
45
private List < VariableDetailsBase > variables ;
46
46
private VariableContainerDetails globalScopeVariables ;
47
47
private VariableContainerDetails scriptScopeVariables ;
@@ -98,12 +98,12 @@ public class DebugService
98
98
/// The PowerShellContext to use for all debugging operations.
99
99
/// </param>
100
100
//// <param name = "remoteFileManager" >
101
- //// A RemoteFileManager instance to use for accessing files in remote sessions.
101
+ //// A RemoteFileManagerService instance to use for accessing files in remote sessions.
102
102
//// </param>
103
103
/// <param name="logger">An ILogger implementation used for writing log messages.</param>
104
104
public DebugService (
105
105
PowerShellContextService powerShellContext ,
106
- //RemoteFileManager remoteFileManager,
106
+ RemoteFileManagerService remoteFileManager ,
107
107
ILoggerFactory factory )
108
108
{
109
109
Validate . IsNotNull ( nameof ( powerShellContext ) , powerShellContext ) ;
@@ -115,7 +115,7 @@ public DebugService(
115
115
116
116
this . powerShellContext . BreakpointUpdated += this . OnBreakpointUpdated ;
117
117
118
- // this.remoteFileManager = remoteFileManager;
118
+ this . remoteFileManager = remoteFileManager ;
119
119
120
120
this . invocationTypeScriptPositionProperty =
121
121
typeof ( InvocationInfo )
@@ -148,16 +148,13 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
148
148
. GetCapability < DscBreakpointCapability > ( ) ;
149
149
150
150
string scriptPath = scriptFile . FilePath ;
151
- //TODO: BRING THIS BACK
152
151
// Make sure we're using the remote script path
153
- /*
154
152
if ( this . powerShellContext . CurrentRunspace . Location == RunspaceLocation . Remote &&
155
153
this . remoteFileManager != null )
156
154
{
157
155
if ( ! this . remoteFileManager . IsUnderRemoteTempPath ( scriptPath ) )
158
156
{
159
- this.logger.Write(
160
- LogLevel.Verbose,
157
+ this . logger . LogTrace (
161
158
$ "Could not set breakpoints for local path '{ scriptPath } ' in a remote session.") ;
162
159
163
160
return resultBreakpointDetails . ToArray ( ) ;
@@ -170,8 +167,7 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
170
167
171
168
scriptPath = mappedPath ;
172
169
}
173
- else */
174
- if (
170
+ else if (
175
171
this . temporaryScriptListingPath != null &&
176
172
this . temporaryScriptListingPath . Equals ( scriptPath , StringComparison . CurrentCultureIgnoreCase ) )
177
173
{
@@ -974,16 +970,15 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
974
970
{
975
971
this . stackFrameDetails [ i ] . ScriptPath = scriptNameOverride ;
976
972
}
977
- // TODO: BRING THIS BACK
978
- //else if (this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.Remote &&
979
- // this.remoteFileManager != null &&
980
- // !string.Equals(stackFrameScriptPath, StackFrameDetails.NoFileScriptPath))
981
- //{
982
- // this.stackFrameDetails[i].ScriptPath =
983
- // this.remoteFileManager.GetMappedPath(
984
- // stackFrameScriptPath,
985
- // this.powerShellContext.CurrentRunspace);
986
- //}
973
+ else if ( this . powerShellContext . CurrentRunspace . Location == RunspaceLocation . Remote &&
974
+ this . remoteFileManager != null &&
975
+ ! string . Equals ( stackFrameScriptPath , StackFrameDetails . NoFileScriptPath ) )
976
+ {
977
+ this . stackFrameDetails [ i ] . ScriptPath =
978
+ this . remoteFileManager . GetMappedPath (
979
+ stackFrameScriptPath ,
980
+ this . powerShellContext . CurrentRunspace ) ;
981
+ }
987
982
}
988
983
}
989
984
@@ -1201,63 +1196,61 @@ private async void OnDebuggerStopAsync(object sender, DebuggerStopEventArgs e)
1201
1196
bool noScriptName = false ;
1202
1197
string localScriptPath = e . InvocationInfo . ScriptName ;
1203
1198
1204
- // TODO: BRING THIS BACK
1205
1199
// If there's no ScriptName, get the "list" of the current source
1206
- // if (this.remoteFileManager != null && string.IsNullOrEmpty(localScriptPath))
1207
- // {
1208
- // // Get the current script listing and create the buffer
1209
- // PSCommand command = new PSCommand();
1210
- // command.AddScript($"list 1 {int.MaxValue}");
1211
-
1212
- // IEnumerable<PSObject> scriptListingLines =
1213
- // await this.powerShellContext.ExecuteCommandAsync<PSObject>(
1214
- // command, false, false);
1215
-
1216
- // if (scriptListingLines != null)
1217
- // {
1218
- // int linePrefixLength = 0;
1219
-
1220
- // string scriptListing =
1221
- // string.Join(
1222
- // Environment.NewLine,
1223
- // scriptListingLines
1224
- // .Select(o => this.TrimScriptListingLine(o, ref linePrefixLength))
1225
- // .Where(s => s != null));
1226
-
1227
- // this.temporaryScriptListingPath =
1228
- // this.remoteFileManager.CreateTemporaryFile(
1229
- // $"[{this.powerShellContext.CurrentRunspace.SessionDetails.ComputerName}] {TemporaryScriptFileName}",
1230
- // scriptListing,
1231
- // this.powerShellContext.CurrentRunspace);
1232
-
1233
- // localScriptPath =
1234
- // this.temporaryScriptListingPath
1235
- // ?? StackFrameDetails.NoFileScriptPath;
1236
-
1237
- // noScriptName = localScriptPath != null;
1238
- // }
1239
- // else
1240
- // {
1241
- // this.logger.LogWarning($"Could not load script context");
1242
- // }
1243
- // }
1200
+ if ( this . remoteFileManager != null && string . IsNullOrEmpty ( localScriptPath ) )
1201
+ {
1202
+ // Get the current script listing and create the buffer
1203
+ PSCommand command = new PSCommand ( ) ;
1204
+ command . AddScript ( $ "list 1 { int . MaxValue } ") ;
1205
+
1206
+ IEnumerable < PSObject > scriptListingLines =
1207
+ await this . powerShellContext . ExecuteCommandAsync < PSObject > (
1208
+ command , false , false ) ;
1209
+
1210
+ if ( scriptListingLines != null )
1211
+ {
1212
+ int linePrefixLength = 0 ;
1213
+
1214
+ string scriptListing =
1215
+ string . Join (
1216
+ Environment . NewLine ,
1217
+ scriptListingLines
1218
+ . Select ( o => this . TrimScriptListingLine ( o , ref linePrefixLength ) )
1219
+ . Where ( s => s != null ) ) ;
1220
+
1221
+ this . temporaryScriptListingPath =
1222
+ this . remoteFileManager . CreateTemporaryFile (
1223
+ $ "[{ this . powerShellContext . CurrentRunspace . SessionDetails . ComputerName } ] { TemporaryScriptFileName } ",
1224
+ scriptListing ,
1225
+ this . powerShellContext . CurrentRunspace ) ;
1226
+
1227
+ localScriptPath =
1228
+ this . temporaryScriptListingPath
1229
+ ?? StackFrameDetails . NoFileScriptPath ;
1230
+
1231
+ noScriptName = localScriptPath != null ;
1232
+ }
1233
+ else
1234
+ {
1235
+ this . logger . LogWarning ( $ "Could not load script context") ;
1236
+ }
1237
+ }
1244
1238
1245
1239
// Get call stack and variables.
1246
1240
await this . FetchStackFramesAndVariablesAsync (
1247
1241
noScriptName ? localScriptPath : null ) ;
1248
1242
1249
- // TODO: BRING THIS BACK
1250
1243
// If this is a remote connection and the debugger stopped at a line
1251
1244
// in a script file, get the file contents
1252
- // if (this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.Remote &&
1253
- // this.remoteFileManager != null &&
1254
- // !noScriptName)
1255
- // {
1256
- // localScriptPath =
1257
- // await this.remoteFileManager.FetchRemoteFileAsync(
1258
- // e.InvocationInfo.ScriptName,
1259
- // this.powerShellContext.CurrentRunspace);
1260
- // }
1245
+ if ( this . powerShellContext . CurrentRunspace . Location == RunspaceLocation . Remote &&
1246
+ this . remoteFileManager != null &&
1247
+ ! noScriptName )
1248
+ {
1249
+ localScriptPath =
1250
+ await this . remoteFileManager . FetchRemoteFileAsync (
1251
+ e . InvocationInfo . ScriptName ,
1252
+ this . powerShellContext . CurrentRunspace ) ;
1253
+ }
1261
1254
1262
1255
if ( this . stackFrameDetails . Length > 0 )
1263
1256
{
@@ -1305,25 +1298,24 @@ private void OnBreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
1305
1298
if ( e . Breakpoint is LineBreakpoint lineBreakpoint )
1306
1299
{
1307
1300
string scriptPath = lineBreakpoint . Script ;
1308
- // TODO: BRING THIS BACK
1309
- //if (this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.Remote &&
1310
- // this.remoteFileManager != null)
1311
- //{
1312
- // string mappedPath =
1313
- // this.remoteFileManager.GetMappedPath(
1314
- // scriptPath,
1315
- // this.powerShellContext.CurrentRunspace);
1316
-
1317
- // if (mappedPath == null)
1318
- // {
1319
- // this.logger.LogError(
1320
- // $"Could not map remote path '{scriptPath}' to a local path.");
1321
-
1322
- // return;
1323
- // }
1324
-
1325
- // scriptPath = mappedPath;
1326
- //}
1301
+ if ( this . powerShellContext . CurrentRunspace . Location == RunspaceLocation . Remote &&
1302
+ this . remoteFileManager != null )
1303
+ {
1304
+ string mappedPath =
1305
+ this . remoteFileManager . GetMappedPath (
1306
+ scriptPath ,
1307
+ this . powerShellContext . CurrentRunspace ) ;
1308
+
1309
+ if ( mappedPath == null )
1310
+ {
1311
+ this . logger . LogError (
1312
+ $ "Could not map remote path '{ scriptPath } ' to a local path.") ;
1313
+
1314
+ return ;
1315
+ }
1316
+
1317
+ scriptPath = mappedPath ;
1318
+ }
1327
1319
1328
1320
// Normalize the script filename for proper indexing
1329
1321
string normalizedScriptName = scriptPath . ToLower ( ) ;
0 commit comments