Skip to content

Commit 6130119

Browse files
committed
Bring code up to compilation
1 parent ccf64dd commit 6130119

39 files changed

+1011
-820
lines changed

src/PowerShellEditorServices/Server/PsesServiceCollectionExtensions.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
using Microsoft.PowerShell.EditorServices.Services;
1313
using Microsoft.PowerShell.EditorServices.Services.Extension;
1414
using Microsoft.PowerShell.EditorServices.Services.PowerShell;
15+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Debugging;
16+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
17+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Runspace;
1518
using Microsoft.PowerShell.EditorServices.Services.Template;
1619
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1720

@@ -25,12 +28,18 @@ public static IServiceCollection AddPsesLanguageServices(
2528
{
2629
return collection.AddSingleton<WorkspaceService>()
2730
.AddSingleton<SymbolsService>()
28-
.AddSingleton<ConfigurationService>()
29-
.AddSingleton<PowerShellExecutionService>(
30-
(provider) => PowerShellExecutionService.CreateAndStart(
31+
.AddSingleton<EditorServicesConsolePSHost>(
32+
(provider) => EditorServicesConsolePSHost.Create(
3133
provider.GetService<ILoggerFactory>(),
3234
provider.GetService<ILanguageServer>(),
3335
hostStartupInfo))
36+
.AddSingleton<IRunspaceContext>(
37+
(provider) => provider.GetService<EditorServicesConsolePSHost>())
38+
.AddSingleton<PowerShellExecutionService>(
39+
(provider) => provider.GetService<EditorServicesConsolePSHost>().ExecutionService)
40+
.AddSingleton<ConfigurationService>()
41+
.AddSingleton<IPowerShellDebugContext>(
42+
(provider) => provider.GetService<EditorServicesConsolePSHost>().DebugContext)
3443
.AddSingleton<TemplateService>()
3544
.AddSingleton<EditorOperationsService>()
3645
.AddSingleton<RemoteFileManagerService>()

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ internal class DebugService
4343

4444
private readonly EditorServicesConsolePSHost _psesHost;
4545

46+
private readonly IPowerShellDebugContext _debugContext;
47+
4648
private int nextVariableId;
4749
private string temporaryScriptListingPath;
4850
private List<VariableDetailsBase> variables;
@@ -68,7 +70,7 @@ internal class DebugService
6870
/// Gets a boolean that indicates whether the debugger is currently
6971
/// stopped at a breakpoint.
7072
/// </summary>
71-
public bool IsDebuggerStopped => _executionService.DebugContext.IsStopped;
73+
public bool IsDebuggerStopped => _debugContext.IsStopped;
7274

7375
/// <summary>
7476
/// Gets the current DebuggerStoppedEventArgs when the debugger
@@ -106,6 +108,7 @@ internal class DebugService
106108
/// <param name="logger">An ILogger implementation used for writing log messages.</param>
107109
public DebugService(
108110
PowerShellExecutionService executionService,
111+
IPowerShellDebugContext debugContext,
109112
RemoteFileManagerService remoteFileManager,
110113
BreakpointService breakpointService,
111114
EditorServicesConsolePSHost psesHost,
@@ -117,9 +120,10 @@ public DebugService(
117120
_executionService = executionService;
118121
_breakpointService = breakpointService;
119122
_psesHost = psesHost;
120-
_executionService.DebugContext.DebuggerStopped += this.OnDebuggerStopAsync;
121-
_executionService.DebugContext.DebuggerResuming += this.OnDebuggerResuming;
122-
_executionService.DebugContext.BreakpointUpdated += this.OnBreakpointUpdated;
123+
_debugContext = debugContext;
124+
_debugContext.DebuggerStopped += OnDebuggerStopAsync;
125+
_debugContext.DebuggerResuming += OnDebuggerResuming;
126+
_debugContext.BreakpointUpdated += OnBreakpointUpdated;
123127

124128
this.remoteFileManager = remoteFileManager;
125129

@@ -146,11 +150,11 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
146150
BreakpointDetails[] breakpoints,
147151
bool clearExisting = true)
148152
{
149-
DscBreakpointCapability dscBreakpoints = _executionService.CurrentRunspace.DscBreakpointCapability;
153+
DscBreakpointCapability dscBreakpoints = await _debugContext.GetDscBreakpointCapabilityAsync(CancellationToken.None);
150154

151155
string scriptPath = scriptFile.FilePath;
152156
// Make sure we're using the remote script path
153-
if (_psesHost.Runspace.RunspaceIsRemote
157+
if (_psesHost.CurrentRunspace.IsOnRemoteMachine
154158
&& this.remoteFileManager != null)
155159
{
156160
if (!this.remoteFileManager.IsUnderRemoteTempPath(scriptPath))
@@ -164,7 +168,7 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
164168
string mappedPath =
165169
this.remoteFileManager.GetMappedPath(
166170
scriptPath,
167-
_executionService.CurrentRunspace);
171+
_psesHost.CurrentRunspace);
168172

169173
scriptPath = mappedPath;
170174
}
@@ -229,31 +233,31 @@ public async Task<CommandBreakpointDetails[]> SetCommandBreakpointsAsync(
229233
/// </summary>
230234
public void Continue()
231235
{
232-
_executionService.DebugContext.Continue();
236+
_debugContext.Continue();
233237
}
234238

235239
/// <summary>
236240
/// Sends a "step over" action to the debugger when stopped.
237241
/// </summary>
238242
public void StepOver()
239243
{
240-
_executionService.DebugContext.StepOver();
244+
_debugContext.StepOver();
241245
}
242246

243247
/// <summary>
244248
/// Sends a "step in" action to the debugger when stopped.
245249
/// </summary>
246250
public void StepIn()
247251
{
248-
_executionService.DebugContext.StepInto();
252+
_debugContext.StepInto();
249253
}
250254

251255
/// <summary>
252256
/// Sends a "step out" action to the debugger when stopped.
253257
/// </summary>
254258
public void StepOut()
255259
{
256-
_executionService.DebugContext.StepOut();
260+
_debugContext.StepOut();
257261
}
258262

259263
/// <summary>
@@ -263,7 +267,7 @@ public void StepOut()
263267
/// </summary>
264268
public void Break()
265269
{
266-
_executionService.DebugContext.BreakExecution();
270+
_debugContext.BreakExecution();
267271
}
268272

269273
/// <summary>
@@ -272,7 +276,7 @@ public void Break()
272276
/// </summary>
273277
public void Abort()
274278
{
275-
_executionService.DebugContext.Abort();
279+
_debugContext.Abort();
276280
}
277281

278282
/// <summary>
@@ -809,7 +813,7 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
809813

810814
// When debugging, this is the best way I can find to get what is likely the workspace root.
811815
// This is controlled by the "cwd:" setting in the launch config.
812-
string workspaceRootPath = _executionService.PowerShellContext.InitialWorkingDirectory;
816+
string workspaceRootPath = _psesHost.InitialWorkingDirectory;
813817

814818
this.stackFrameDetails[i] =
815819
StackFrameDetails.Create(callStackFrames[i], autoVariables, localVariables, workspaceRootPath);
@@ -820,14 +824,14 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
820824
{
821825
this.stackFrameDetails[i].ScriptPath = scriptNameOverride;
822826
}
823-
else if (_executionService.CurrentRunspace.IsRemote()
827+
else if (_psesHost.CurrentRunspace.IsOnRemoteMachine
824828
&& this.remoteFileManager != null
825829
&& !string.Equals(stackFrameScriptPath, StackFrameDetails.NoFileScriptPath))
826830
{
827831
this.stackFrameDetails[i].ScriptPath =
828832
this.remoteFileManager.GetMappedPath(
829833
stackFrameScriptPath,
830-
_executionService.CurrentRunspace);
834+
_psesHost.CurrentRunspace);
831835
}
832836
}
833837
}
@@ -889,9 +893,9 @@ await _executionService.ExecutePSCommandAsync<PSObject>(
889893

890894
this.temporaryScriptListingPath =
891895
this.remoteFileManager.CreateTemporaryFile(
892-
$"[{_executionService.CurrentRunspace.SessionDetails.ComputerName}] {TemporaryScriptFileName}",
896+
$"[{_psesHost.CurrentRunspace.SessionDetails.ComputerName}] {TemporaryScriptFileName}",
893897
scriptListing,
894-
_executionService.CurrentRunspace);
898+
_psesHost.CurrentRunspace);
895899

896900
localScriptPath =
897901
this.temporaryScriptListingPath
@@ -911,14 +915,14 @@ await this.FetchStackFramesAndVariablesAsync(
911915

912916
// If this is a remote connection and the debugger stopped at a line
913917
// in a script file, get the file contents
914-
if (_executionService.CurrentRunspace.IsRemote()
918+
if (_psesHost.CurrentRunspace.IsOnRemoteMachine
915919
&& this.remoteFileManager != null
916920
&& !noScriptName)
917921
{
918922
localScriptPath =
919923
await this.remoteFileManager.FetchRemoteFileAsync(
920924
e.InvocationInfo.ScriptName,
921-
_executionService.CurrentRunspace).ConfigureAwait(false);
925+
_psesHost.CurrentRunspace).ConfigureAwait(false);
922926
}
923927

924928
if (this.stackFrameDetails.Length > 0)
@@ -938,7 +942,7 @@ await this.remoteFileManager.FetchRemoteFileAsync(
938942
this.CurrentDebuggerStoppedEventArgs =
939943
new DebuggerStoppedEventArgs(
940944
e,
941-
_executionService.CurrentRunspace,
945+
_psesHost.CurrentRunspace,
942946
localScriptPath);
943947

944948
// Notify the host that the debugger is stopped
@@ -967,13 +971,13 @@ private void OnBreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
967971
if (e.Breakpoint is LineBreakpoint lineBreakpoint)
968972
{
969973
string scriptPath = lineBreakpoint.Script;
970-
if (_executionService.CurrentRunspace.IsRemote()
974+
if (_psesHost.CurrentRunspace.IsOnRemoteMachine
971975
&& this.remoteFileManager != null)
972976
{
973977
string mappedPath =
974978
this.remoteFileManager.GetMappedPath(
975979
scriptPath,
976-
_executionService.CurrentRunspace);
980+
_psesHost.CurrentRunspace);
977981

978982
if (mappedPath == null)
979983
{

src/PowerShellEditorServices/Services/DebugAdapter/Debugging/DebuggerStoppedEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal class DebuggerStoppedEventArgs
2929
/// </summary>
3030
public bool IsRemoteSession
3131
{
32-
get => RunspaceInfo.IsRemote();
32+
get => RunspaceInfo.RunspaceOrigin != RunspaceOrigin.Local;
3333
}
3434

3535
/// <summary>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,26 @@
1111
using Microsoft.PowerShell.EditorServices.Services;
1212
using Microsoft.PowerShell.EditorServices.Services.DebugAdapter;
1313
using Microsoft.PowerShell.EditorServices.Services.PowerShell;
14+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Debugging;
1415
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution;
1516

1617
namespace Microsoft.PowerShell.EditorServices.Handlers
1718
{
1819
internal class DebugEvaluateHandler : IEvaluateHandler
1920
{
2021
private readonly ILogger _logger;
22+
private readonly IPowerShellDebugContext _debugContext;
2123
private readonly PowerShellExecutionService _executionService;
2224
private readonly DebugService _debugService;
2325

2426
public DebugEvaluateHandler(
2527
ILoggerFactory factory,
28+
IPowerShellDebugContext debugContext,
2629
PowerShellExecutionService executionService,
2730
DebugService debugService)
2831
{
2932
_logger = factory.CreateLogger<DebugEvaluateHandler>();
33+
_debugContext = debugContext;
3034
_executionService = executionService;
3135
_debugService = debugService;
3236
}
@@ -56,7 +60,7 @@ public async Task<EvaluateResponseBody> Handle(EvaluateRequestArguments request,
5660

5761
// VS Code might send this request after the debugger
5862
// has been resumed, return an empty result in this case.
59-
if (_executionService.DebugContext.IsStopped)
63+
if (_debugContext.IsStopped)
6064
{
6165
// First check to see if the watch expression refers to a naked variable reference.
6266
result =

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using Microsoft.Extensions.Logging;
11+
using Microsoft.PowerShell.EditorServices.Logging;
1112
using Microsoft.PowerShell.EditorServices.Server;
1213
using Microsoft.PowerShell.EditorServices.Services;
1314
using Microsoft.PowerShell.EditorServices.Services.PowerShell;
1415
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution;
16+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
1517
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Runspace;
1618
using OmniSharp.Extensions.DebugAdapter.Protocol.Requests;
1719

@@ -25,17 +27,20 @@ internal class DisconnectHandler : IDisconnectHandler
2527
private readonly DebugStateService _debugStateService;
2628
private readonly DebugEventHandlerService _debugEventHandlerService;
2729
private readonly PsesDebugServer _psesDebugServer;
30+
private readonly IRunspaceContext _runspaceContext;
2831

2932
public DisconnectHandler(
3033
ILoggerFactory factory,
3134
PsesDebugServer psesDebugServer,
35+
IRunspaceContext runspaceContext,
3236
PowerShellExecutionService executionService,
3337
DebugService debugService,
3438
DebugStateService debugStateService,
3539
DebugEventHandlerService debugEventHandlerService)
3640
{
3741
_logger = factory.CreateLogger<DisconnectHandler>();
3842
_psesDebugServer = psesDebugServer;
43+
_runspaceContext = runspaceContext;
3944
_executionService = executionService;
4045
_debugService = debugService;
4146
_debugStateService = debugStateService;
@@ -53,7 +58,7 @@ public async Task<DisconnectResponse> Handle(DisconnectArguments request, Cancel
5358
if (_debugStateService.IsInteractiveDebugSession && _debugStateService.IsAttachSession)
5459
{
5560
// Pop the sessions
56-
if (_executionService.CurrentRunspace.RunspaceOrigin == RunspaceOrigin.EnteredProcess)
61+
if (_runspaceContext.CurrentRunspace.RunspaceOrigin == RunspaceOrigin.EnteredProcess)
5762
{
5863
try
5964
{
@@ -63,7 +68,7 @@ await _executionService.ExecutePSCommandAsync(
6368
CancellationToken.None).ConfigureAwait(false);
6469

6570
if (_debugStateService.IsRemoteAttach &&
66-
_executionService.CurrentRunspace.IsRemote())
71+
_runspaceContext.CurrentRunspace.RunspaceOrigin == RunspaceOrigin.EnteredProcess)
6772
{
6873
await _executionService.ExecutePSCommandAsync(
6974
new PSCommand().AddCommand("Exit-PSSession"),

0 commit comments

Comments
 (0)