Skip to content

Commit dea9d82

Browse files
remote file manager working
1 parent d000616 commit dea9d82

19 files changed

+145
-142
lines changed

src/PowerShellEditorServices.Engine/Server/PsesDebugServer.cs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public async Task StartAsync(IServiceProvider languageServerServiceProvider)
4545
options.Services = new ServiceCollection()
4646
.AddSingleton(languageServerServiceProvider.GetService<PowerShellContextService>())
4747
.AddSingleton(languageServerServiceProvider.GetService<WorkspaceService>())
48+
.AddSingleton(languageServerServiceProvider.GetService<RemoteFileManagerService>())
4849
.AddSingleton<PsesDebugServer>(this)
4950
.AddSingleton<DebugService>()
5051
.AddSingleton<DebugStateService>()

src/PowerShellEditorServices.Engine/Server/PsesLanguageServer.cs

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public async Task StartAsync()
7979
_additionalModules))
8080
.AddSingleton<TemplateService>()
8181
.AddSingleton<EditorOperationsService>()
82+
.AddSingleton<RemoteFileManagerService>()
8283
.AddSingleton<ExtensionService>(
8384
(provider) =>
8485
{

src/PowerShellEditorServices.Engine/Services/DebugAdapter/DebugEventHandlerService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Microsoft.PowerShell.EditorServices.Engine.Services
1515
{
16-
public class DebugEventHandlerService
16+
internal class DebugEventHandlerService
1717
{
1818
private readonly ILogger<DebugEventHandlerService> _logger;
1919
private readonly PowerShellContextService _powerShellContextService;

src/PowerShellEditorServices.Engine/Services/DebugAdapter/DebugService.cs

+82-90
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Microsoft.PowerShell.EditorServices.Engine.Services
2525
/// Provides a high-level service for interacting with the
2626
/// PowerShell debugger in the runspace managed by a PowerShellContext.
2727
/// </summary>
28-
public class DebugService
28+
internal class DebugService
2929
{
3030
#region Fields
3131

@@ -34,14 +34,14 @@ public class DebugService
3434

3535
private readonly ILogger logger;
3636
private readonly PowerShellContextService powerShellContext;
37-
//private RemoteFileManagerService remoteFileManager;
37+
private RemoteFileManagerService remoteFileManager;
3838

3939
// TODO: This needs to be managed per nested session
4040
private readonly Dictionary<string, List<Breakpoint>> breakpointsPerFile =
4141
new Dictionary<string, List<Breakpoint>>();
4242

4343
private int nextVariableId;
44-
private readonly string temporaryScriptListingPath;
44+
private string temporaryScriptListingPath;
4545
private List<VariableDetailsBase> variables;
4646
private VariableContainerDetails globalScopeVariables;
4747
private VariableContainerDetails scriptScopeVariables;
@@ -98,12 +98,12 @@ public class DebugService
9898
/// The PowerShellContext to use for all debugging operations.
9999
/// </param>
100100
//// <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.
102102
//// </param>
103103
/// <param name="logger">An ILogger implementation used for writing log messages.</param>
104104
public DebugService(
105105
PowerShellContextService powerShellContext,
106-
//RemoteFileManager remoteFileManager,
106+
RemoteFileManagerService remoteFileManager,
107107
ILoggerFactory factory)
108108
{
109109
Validate.IsNotNull(nameof(powerShellContext), powerShellContext);
@@ -115,7 +115,7 @@ public DebugService(
115115

116116
this.powerShellContext.BreakpointUpdated += this.OnBreakpointUpdated;
117117

118-
//this.remoteFileManager = remoteFileManager;
118+
this.remoteFileManager = remoteFileManager;
119119

120120
this.invocationTypeScriptPositionProperty =
121121
typeof(InvocationInfo)
@@ -148,16 +148,13 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
148148
.GetCapability<DscBreakpointCapability>();
149149

150150
string scriptPath = scriptFile.FilePath;
151-
//TODO: BRING THIS BACK
152151
// Make sure we're using the remote script path
153-
/*
154152
if (this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.Remote &&
155153
this.remoteFileManager != null)
156154
{
157155
if (!this.remoteFileManager.IsUnderRemoteTempPath(scriptPath))
158156
{
159-
this.logger.Write(
160-
LogLevel.Verbose,
157+
this.logger.LogTrace(
161158
$"Could not set breakpoints for local path '{scriptPath}' in a remote session.");
162159

163160
return resultBreakpointDetails.ToArray();
@@ -170,8 +167,7 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
170167

171168
scriptPath = mappedPath;
172169
}
173-
else */
174-
if (
170+
else if (
175171
this.temporaryScriptListingPath != null &&
176172
this.temporaryScriptListingPath.Equals(scriptPath, StringComparison.CurrentCultureIgnoreCase))
177173
{
@@ -974,16 +970,15 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
974970
{
975971
this.stackFrameDetails[i].ScriptPath = scriptNameOverride;
976972
}
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+
}
987982
}
988983
}
989984

@@ -1201,63 +1196,61 @@ private async void OnDebuggerStopAsync(object sender, DebuggerStopEventArgs e)
12011196
bool noScriptName = false;
12021197
string localScriptPath = e.InvocationInfo.ScriptName;
12031198

1204-
// TODO: BRING THIS BACK
12051199
// 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+
}
12441238

12451239
// Get call stack and variables.
12461240
await this.FetchStackFramesAndVariablesAsync(
12471241
noScriptName ? localScriptPath : null);
12481242

1249-
// TODO: BRING THIS BACK
12501243
// If this is a remote connection and the debugger stopped at a line
12511244
// 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+
}
12611254

12621255
if (this.stackFrameDetails.Length > 0)
12631256
{
@@ -1305,25 +1298,24 @@ private void OnBreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
13051298
if (e.Breakpoint is LineBreakpoint lineBreakpoint)
13061299
{
13071300
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+
}
13271319

13281320
// Normalize the script filename for proper indexing
13291321
string normalizedScriptName = scriptPath.ToLower();

src/PowerShellEditorServices.Engine/Services/DebugAdapter/DebugStateService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Microsoft.PowerShell.EditorServices.Engine.Services
77
{
8-
public class DebugStateService
8+
internal class DebugStateService
99
{
1010
internal bool NoDebug { get; set; }
1111

src/PowerShellEditorServices.Engine/Services/DebugAdapter/Handlers/BreakpointHandlers.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace Microsoft.PowerShell.EditorServices.Engine.Handlers
2121
{
22-
public class SetFunctionBreakpointsHandler : ISetFunctionBreakpointsHandler
22+
internal class SetFunctionBreakpointsHandler : ISetFunctionBreakpointsHandler
2323
{
2424
private readonly ILogger _logger;
2525
private readonly DebugService _debugService;
@@ -76,7 +76,7 @@ await _debugService.SetCommandBreakpointsAsync(
7676
}
7777
}
7878

79-
public class SetExceptionBreakpointsHandler : ISetExceptionBreakpointsHandler
79+
internal class SetExceptionBreakpointsHandler : ISetExceptionBreakpointsHandler
8080
{
8181
private readonly ILogger _logger;
8282
private readonly DebugService _debugService;
@@ -120,7 +120,7 @@ public Task<SetExceptionBreakpointsResponse> Handle(SetExceptionBreakpointsArgum
120120
}
121121
}
122122

123-
public class SetBreakpointsHandler : ISetBreakpointsHandler
123+
internal class SetBreakpointsHandler : ISetBreakpointsHandler
124124
{
125125
private readonly ILogger _logger;
126126
private readonly DebugService _debugService;

src/PowerShellEditorServices.Engine/Services/DebugAdapter/Handlers/ConfigurationDoneHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace Microsoft.PowerShell.EditorServices.Engine.Handlers
1717
{
18-
public class ConfigurationDoneHandler : IConfigurationDoneHandler
18+
internal class ConfigurationDoneHandler : IConfigurationDoneHandler
1919
{
2020
private readonly ILogger _logger;
2121
private readonly IJsonRpcServer _jsonRpcServer;

src/PowerShellEditorServices.Engine/Services/DebugAdapter/Handlers/DebugEvaluateHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace Microsoft.PowerShell.EditorServices.Engine.Handlers
1414
{
15-
public class DebugEvaluateHandler : IEvaluateHandler
15+
internal class DebugEvaluateHandler : IEvaluateHandler
1616
{
1717
private readonly ILogger _logger;
1818
private readonly PowerShellContextService _powerShellContextService;

src/PowerShellEditorServices.Engine/Services/DebugAdapter/Handlers/DebuggerActionHandlers.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Microsoft.PowerShell.EditorServices.Engine.Handlers
1515
{
16-
public class ContinueHandler : IContinueHandler
16+
internal class ContinueHandler : IContinueHandler
1717
{
1818
private readonly ILogger _logger;
1919
private readonly DebugService _debugService;
@@ -33,7 +33,7 @@ public Task<ContinueResponse> Handle(ContinueArguments request, CancellationToke
3333
}
3434
}
3535

36-
public class NextHandler : INextHandler
36+
internal class NextHandler : INextHandler
3737
{
3838
private readonly ILogger _logger;
3939
private readonly DebugService _debugService;
@@ -53,7 +53,7 @@ public Task<NextResponse> Handle(NextArguments request, CancellationToken cancel
5353
}
5454
}
5555

56-
public class PauseHandler : IPauseHandler
56+
internal class PauseHandler : IPauseHandler
5757
{
5858
private readonly ILogger _logger;
5959
private readonly DebugService _debugService;
@@ -73,7 +73,7 @@ public Task<PauseResponse> Handle(PauseArguments request, CancellationToken canc
7373
}
7474
}
7575

76-
public class StepInHandler : IStepInHandler
76+
internal class StepInHandler : IStepInHandler
7777
{
7878
private readonly ILogger _logger;
7979
private readonly DebugService _debugService;
@@ -93,7 +93,7 @@ public Task<StepInResponse> Handle(StepInArguments request, CancellationToken ca
9393
}
9494
}
9595

96-
public class StepOutHandler : IStepOutHandler
96+
internal class StepOutHandler : IStepOutHandler
9797
{
9898
private readonly ILogger _logger;
9999
private readonly DebugService _debugService;

src/PowerShellEditorServices.Engine/Services/DebugAdapter/Handlers/DisconnectHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace Microsoft.PowerShell.EditorServices.Engine.Handlers
1717
{
18-
public class DisconnectHandler : IDisconnectHandler
18+
internal class DisconnectHandler : IDisconnectHandler
1919
{
2020
private readonly ILogger<DisconnectHandler> _logger;
2121
private readonly PowerShellContextService _powerShellContextService;

0 commit comments

Comments
 (0)