Skip to content

Commit ccf64dd

Browse files
committed
Migrate runspace pieces
1 parent 6b12e7b commit ccf64dd

File tree

71 files changed

+1554
-1531
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1554
-1531
lines changed

src/PowerShellEditorServices/Extensions/Api/EditorContextService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System;
77
using System.Threading;
88
using System.Threading.Tasks;
9-
using Microsoft.PowerShell.EditorServices.Handlers;
9+
using Microsoft.PowerShell.EditorServices.Services.Extension;
1010
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1111

1212
namespace Microsoft.PowerShell.EditorServices.Extensions.Services

src/PowerShellEditorServices/Extensions/Api/EditorExtensionServiceProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Reflection;
99
using Microsoft.Extensions.DependencyInjection;
1010
using Microsoft.PowerShell.EditorServices.Services;
11+
using Microsoft.PowerShell.EditorServices.Services.Extension;
1112
using Microsoft.PowerShell.EditorServices.Utility;
1213
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1314

src/PowerShellEditorServices/Extensions/Api/EditorUIService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using System.Linq;
99
using System.Threading;
1010
using System.Threading.Tasks;
11-
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
11+
using Microsoft.PowerShell.EditorServices.Services.Extension;
1212
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1313

1414
namespace Microsoft.PowerShell.EditorServices.Extensions.Services

src/PowerShellEditorServices/Extensions/Api/ExtensionCommandService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//
55

66
using Microsoft.PowerShell.EditorServices.Services;
7+
using Microsoft.PowerShell.EditorServices.Services.Extension;
78
using System;
89
using System.Collections.Generic;
910
using System.Threading.Tasks;

src/PowerShellEditorServices/Extensions/EditorFileRanges.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6-
using Microsoft.PowerShell.EditorServices.Handlers;
6+
using Microsoft.PowerShell.EditorServices.Services.Extension;
77
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
88
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
99
using System;

src/PowerShellEditorServices/Extensions/EditorObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Reflection;
88
using System.Threading.Tasks;
99
using Microsoft.PowerShell.EditorServices.Extensions.Services;
10-
using Microsoft.PowerShell.EditorServices.Services;
10+
using Microsoft.PowerShell.EditorServices.Services.Extension;
1111

1212
namespace Microsoft.PowerShell.EditorServices.Extensions
1313
{

src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Serilog;
1515
using Serilog.Events;
1616
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
17+
using Microsoft.PowerShell.EditorServices.Services.Extension;
1718

1819
#if DEBUG
1920
using Serilog.Debugging;

src/PowerShellEditorServices/PowerShellEditorServices.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,9 @@
5454

5555
<ItemGroup>
5656
<Compile Remove="Extensions\Api\DocumentSymbolService.cs" />
57+
<Compile Remove="Services\Extension\Templating\**" />
58+
<Compile Remove="Services\PowerShellContext\**\*.cs" />
59+
<EmbeddedResource Remove="Services\Extension\Templating\**" />
60+
<None Remove="Services\Extension\Templating\**" />
5761
</ItemGroup>
5862
</Project>

src/PowerShellEditorServices/Server/PsesLanguageServer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
using Microsoft.PowerShell.EditorServices.Handlers;
1313
using Microsoft.PowerShell.EditorServices.Hosting;
1414
using Microsoft.PowerShell.EditorServices.Services;
15+
using Microsoft.PowerShell.EditorServices.Services.Extension;
1516
using Microsoft.PowerShell.EditorServices.Services.PowerShell;
1617
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution;
18+
using Microsoft.PowerShell.EditorServices.Services.Template;
1719
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1820
using OmniSharp.Extensions.LanguageServer.Server;
1921
using Serilog;

src/PowerShellEditorServices/Server/PsesServiceCollectionExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
using Microsoft.Extensions.Logging;
1111
using Microsoft.PowerShell.EditorServices.Hosting;
1212
using Microsoft.PowerShell.EditorServices.Services;
13+
using Microsoft.PowerShell.EditorServices.Services.Extension;
1314
using Microsoft.PowerShell.EditorServices.Services.PowerShell;
15+
using Microsoft.PowerShell.EditorServices.Services.Template;
1416
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1517

1618
namespace Microsoft.PowerShell.EditorServices.Server
@@ -32,7 +34,7 @@ public static IServiceCollection AddPsesLanguageServices(
3234
.AddSingleton<TemplateService>()
3335
.AddSingleton<EditorOperationsService>()
3436
.AddSingleton<RemoteFileManagerService>()
35-
.AddSingleton<ExtensionService>(
37+
.AddSingleton(
3638
(provider) =>
3739
{
3840
var extensionService = new ExtensionService(

src/PowerShellEditorServices/Services/DebugAdapter/DebugEventHandlerService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Microsoft.Extensions.Logging;
88
using Microsoft.PowerShell.EditorServices.Services.DebugAdapter;
99
using Microsoft.PowerShell.EditorServices.Services.PowerShell;
10-
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
10+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Runspace;
1111
using Microsoft.PowerShell.EditorServices.Utility;
1212
using OmniSharp.Extensions.DebugAdapter.Protocol.Events;
1313
using OmniSharp.Extensions.JsonRpc;
@@ -38,15 +38,15 @@ public DebugEventHandlerService(
3838

3939
internal void RegisterEventHandlers()
4040
{
41-
//_powerShellContextService.RunspaceChanged += PowerShellContext_RunspaceChanged;
41+
_executionService.RunspaceChanged += ExecutionService_RunspaceChanged;
4242
_debugService.BreakpointUpdated += DebugService_BreakpointUpdated;
4343
_debugService.DebuggerStopped += DebugService_DebuggerStopped;
4444
//_powerShellContextService.DebuggerResumed += PowerShellContext_DebuggerResumed;
4545
}
4646

4747
internal void UnregisterEventHandlers()
4848
{
49-
//_powerShellContextService.RunspaceChanged -= PowerShellContext_RunspaceChanged;
49+
_executionService.RunspaceChanged -= ExecutionService_RunspaceChanged;
5050
_debugService.BreakpointUpdated -= DebugService_BreakpointUpdated;
5151
_debugService.DebuggerStopped -= DebugService_DebuggerStopped;
5252
//_powerShellContextService.DebuggerResumed -= PowerShellContext_DebuggerResumed;
@@ -88,11 +88,11 @@ e.OriginalEvent.Breakpoints[0] is CommandBreakpoint
8888
});
8989
}
9090

91-
private void PowerShellContext_RunspaceChanged(object sender, RunspaceChangedEventArgs e)
91+
private void ExecutionService_RunspaceChanged(object sender, RunspaceChangedEventArgs e)
9292
{
9393
if (_debugStateService.WaitingForAttach &&
9494
e.ChangeAction == RunspaceChangeAction.Enter &&
95-
e.NewRunspace.Context == RunspaceOrigin.DebuggedRunspace)
95+
e.NewRunspace.RunspaceOrigin == RunspaceOrigin.DebuggedRunspace)
9696
{
9797
// Send the InitializedEvent so that the debugger will continue
9898
// sending configuration requests

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using System.Management.Automation;
1010
using System.Management.Automation.Language;
1111
using System.Reflection;
12-
using System.Text;
1312
using System.Threading.Tasks;
1413
using Microsoft.PowerShell.EditorServices.Utility;
1514
using System.Threading;
@@ -19,6 +18,8 @@
1918
using Microsoft.PowerShell.EditorServices.Services.PowerShell;
2019
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution;
2120
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
21+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Debugging;
22+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Runspace;
2223

2324
namespace Microsoft.PowerShell.EditorServices.Services
2425
{
@@ -67,7 +68,7 @@ internal class DebugService
6768
/// Gets a boolean that indicates whether the debugger is currently
6869
/// stopped at a breakpoint.
6970
/// </summary>
70-
public bool IsDebuggerStopped => _executionService.IsDebuggerStopped;
71+
public bool IsDebuggerStopped => _executionService.DebugContext.IsStopped;
7172

7273
/// <summary>
7374
/// Gets the current DebuggerStoppedEventArgs when the debugger
@@ -116,9 +117,9 @@ public DebugService(
116117
_executionService = executionService;
117118
_breakpointService = breakpointService;
118119
_psesHost = psesHost;
119-
_executionService.DebuggerStopped += this.OnDebuggerStopAsync;
120-
_executionService.DebuggerResuming += this.OnDebuggerResuming;
121-
_executionService.BreakpointUpdated += this.OnBreakpointUpdated;
120+
_executionService.DebugContext.DebuggerStopped += this.OnDebuggerStopAsync;
121+
_executionService.DebugContext.DebuggerResuming += this.OnDebuggerResuming;
122+
_executionService.DebugContext.BreakpointUpdated += this.OnBreakpointUpdated;
122123

123124
this.remoteFileManager = remoteFileManager;
124125

@@ -145,10 +146,7 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
145146
BreakpointDetails[] breakpoints,
146147
bool clearExisting = true)
147148
{
148-
var dscBreakpoints =
149-
this.powerShellContext
150-
.CurrentRunspace
151-
.GetCapability<DscBreakpointCapability>();
149+
DscBreakpointCapability dscBreakpoints = _executionService.CurrentRunspace.DscBreakpointCapability;
152150

153151
string scriptPath = scriptFile.FilePath;
154152
// Make sure we're using the remote script path
@@ -166,7 +164,7 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
166164
string mappedPath =
167165
this.remoteFileManager.GetMappedPath(
168166
scriptPath,
169-
this.powerShellContext.CurrentRunspace);
167+
_executionService.CurrentRunspace);
170168

171169
scriptPath = mappedPath;
172170
}
@@ -182,8 +180,7 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
182180

183181
// Fix for issue #123 - file paths that contain wildcard chars [ and ] need to
184182
// quoted and have those wildcard chars escaped.
185-
string escapedScriptPath =
186-
PowerShellContextService.WildcardEscapePath(scriptPath);
183+
string escapedScriptPath = PathUtils.WildcardEscape(scriptPath);
187184

188185
if (dscBreakpoints == null || !dscBreakpoints.IsDscResourcePath(escapedScriptPath))
189186
{
@@ -232,35 +229,31 @@ public async Task<CommandBreakpointDetails[]> SetCommandBreakpointsAsync(
232229
/// </summary>
233230
public void Continue()
234231
{
235-
this.powerShellContext.ResumeDebugger(
236-
DebuggerResumeAction.Continue);
232+
_executionService.DebugContext.Continue();
237233
}
238234

239235
/// <summary>
240236
/// Sends a "step over" action to the debugger when stopped.
241237
/// </summary>
242238
public void StepOver()
243239
{
244-
this.powerShellContext.ResumeDebugger(
245-
DebuggerResumeAction.StepOver);
240+
_executionService.DebugContext.StepOver();
246241
}
247242

248243
/// <summary>
249244
/// Sends a "step in" action to the debugger when stopped.
250245
/// </summary>
251246
public void StepIn()
252247
{
253-
this.powerShellContext.ResumeDebugger(
254-
DebuggerResumeAction.StepInto);
248+
_executionService.DebugContext.StepInto();
255249
}
256250

257251
/// <summary>
258252
/// Sends a "step out" action to the debugger when stopped.
259253
/// </summary>
260254
public void StepOut()
261255
{
262-
this.powerShellContext.ResumeDebugger(
263-
DebuggerResumeAction.StepOut);
256+
_executionService.DebugContext.StepOut();
264257
}
265258

266259
/// <summary>
@@ -270,8 +263,7 @@ public void StepOut()
270263
/// </summary>
271264
public void Break()
272265
{
273-
// Break execution in the debugger
274-
this.powerShellContext.BreakExecution();
266+
_executionService.DebugContext.BreakExecution();
275267
}
276268

277269
/// <summary>
@@ -280,7 +272,7 @@ public void Break()
280272
/// </summary>
281273
public void Abort()
282274
{
283-
this.powerShellContext.AbortExecution(shouldAbortDebugSession: true);
275+
_executionService.DebugContext.Abort();
284276
}
285277

286278
/// <summary>
@@ -817,7 +809,7 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
817809

818810
// When debugging, this is the best way I can find to get what is likely the workspace root.
819811
// This is controlled by the "cwd:" setting in the launch config.
820-
string workspaceRootPath = this.powerShellContext.InitialWorkingDirectory;
812+
string workspaceRootPath = _executionService.PowerShellContext.InitialWorkingDirectory;
821813

822814
this.stackFrameDetails[i] =
823815
StackFrameDetails.Create(callStackFrames[i], autoVariables, localVariables, workspaceRootPath);
@@ -828,14 +820,14 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
828820
{
829821
this.stackFrameDetails[i].ScriptPath = scriptNameOverride;
830822
}
831-
else if (this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.Remote &&
832-
this.remoteFileManager != null &&
833-
!string.Equals(stackFrameScriptPath, StackFrameDetails.NoFileScriptPath))
823+
else if (_executionService.CurrentRunspace.IsRemote()
824+
&& this.remoteFileManager != null
825+
&& !string.Equals(stackFrameScriptPath, StackFrameDetails.NoFileScriptPath))
834826
{
835827
this.stackFrameDetails[i].ScriptPath =
836828
this.remoteFileManager.GetMappedPath(
837829
stackFrameScriptPath,
838-
this.powerShellContext.CurrentRunspace);
830+
_executionService.CurrentRunspace);
839831
}
840832
}
841833
}
@@ -897,9 +889,9 @@ await _executionService.ExecutePSCommandAsync<PSObject>(
897889

898890
this.temporaryScriptListingPath =
899891
this.remoteFileManager.CreateTemporaryFile(
900-
$"[{this.powerShellContext.CurrentRunspace.SessionDetails.ComputerName}] {TemporaryScriptFileName}",
892+
$"[{_executionService.CurrentRunspace.SessionDetails.ComputerName}] {TemporaryScriptFileName}",
901893
scriptListing,
902-
this.powerShellContext.CurrentRunspace);
894+
_executionService.CurrentRunspace);
903895

904896
localScriptPath =
905897
this.temporaryScriptListingPath
@@ -919,14 +911,14 @@ await this.FetchStackFramesAndVariablesAsync(
919911

920912
// If this is a remote connection and the debugger stopped at a line
921913
// in a script file, get the file contents
922-
if (this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.Remote &&
923-
this.remoteFileManager != null &&
924-
!noScriptName)
914+
if (_executionService.CurrentRunspace.IsRemote()
915+
&& this.remoteFileManager != null
916+
&& !noScriptName)
925917
{
926918
localScriptPath =
927919
await this.remoteFileManager.FetchRemoteFileAsync(
928920
e.InvocationInfo.ScriptName,
929-
powerShellContext.CurrentRunspace).ConfigureAwait(false);
921+
_executionService.CurrentRunspace).ConfigureAwait(false);
930922
}
931923

932924
if (this.stackFrameDetails.Length > 0)
@@ -946,7 +938,7 @@ await this.remoteFileManager.FetchRemoteFileAsync(
946938
this.CurrentDebuggerStoppedEventArgs =
947939
new DebuggerStoppedEventArgs(
948940
e,
949-
this.powerShellContext.CurrentRunspace,
941+
_executionService.CurrentRunspace,
950942
localScriptPath);
951943

952944
// Notify the host that the debugger is stopped
@@ -975,13 +967,13 @@ private void OnBreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
975967
if (e.Breakpoint is LineBreakpoint lineBreakpoint)
976968
{
977969
string scriptPath = lineBreakpoint.Script;
978-
if (this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.Remote &&
979-
this.remoteFileManager != null)
970+
if (_executionService.CurrentRunspace.IsRemote()
971+
&& this.remoteFileManager != null)
980972
{
981973
string mappedPath =
982974
this.remoteFileManager.GetMappedPath(
983975
scriptPath,
984-
this.powerShellContext.CurrentRunspace);
976+
_executionService.CurrentRunspace);
985977

986978
if (mappedPath == null)
987979
{

0 commit comments

Comments
 (0)