Skip to content

Commit caf9743

Browse files
committed
Move PowerShellContext creation out of EditorSession
This change moves the creation of PowerShellContext instances outside of the EditorSession class so that runspace creation and configuration can be managed at the host layer.
1 parent 6df8d6d commit caf9743

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/PowerShellEditorServices.Host/EditorServicesHost.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ private EditorSession CreateSession(
271271
bool enableConsoleRepl)
272272
{
273273
EditorSession editorSession = new EditorSession();
274-
editorSession.StartSession(hostDetails, profilePaths, enableConsoleRepl);
274+
editorSession.StartSession(
275+
CreatePowerShellContext(hostDetails, profilePaths, enableConsoleRepl),
276+
enableConsoleRepl);
275277

276278
return editorSession;
277279
}
@@ -282,11 +284,21 @@ private EditorSession CreateDebugSession(
282284
IEditorOperations editorOperations)
283285
{
284286
EditorSession editorSession = new EditorSession();
285-
editorSession.StartDebugSession(hostDetails, profilePaths, editorOperations);
287+
editorSession.StartDebugSession(
288+
CreatePowerShellContext(hostDetails, profilePaths, enableConsoleRepl),
289+
editorOperations);
286290

287291
return editorSession;
288292
}
289293

294+
private PowerShellContext CreatePowerShellContext(
295+
HostDetails hostDetails,
296+
ProfilePaths profilePaths,
297+
bool enableConsoleRepl)
298+
{
299+
return new PowerShellContext(hostDetails, profilePaths, enableConsoleRepl);
300+
}
301+
290302
#if !CoreCLR
291303
static void CurrentDomain_UnhandledException(
292304
object sender,

src/PowerShellEditorServices/Session/EditorSession.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,15 @@ public class EditorSession
7979
/// Starts the session using the provided IConsoleHost implementation
8080
/// for the ConsoleService.
8181
/// </summary>
82-
/// <param name="hostDetails">
83-
/// Provides details about the host application.
84-
/// </param>
85-
/// <param name="profilePaths">
86-
/// An object containing the profile paths for the session.
87-
/// </param>
8882
/// <param name="enableConsoleRepl">
8983
/// Enables a terminal-based REPL for this session.
9084
/// </param>
9185
public void StartSession(
92-
HostDetails hostDetails,
93-
ProfilePaths profilePaths,
86+
PowerShellContext powerShellContext,
9487
bool enableConsoleRepl)
9588
{
9689
// Initialize all services
97-
this.PowerShellContext = new PowerShellContext(hostDetails, profilePaths, enableConsoleRepl);
90+
this.PowerShellContext = powerShellContext;
9891
this.LanguageService = new LanguageService(this.PowerShellContext);
9992
this.ConsoleService = new ConsoleService(this.PowerShellContext);
10093
this.ExtensionService = new ExtensionService(this.PowerShellContext);
@@ -111,22 +104,15 @@ public void StartSession(
111104
/// Starts a debug-only session using the provided IConsoleHost implementation
112105
/// for the ConsoleService.
113106
/// </summary>
114-
/// <param name="hostDetails">
115-
/// Provides details about the host application.
116-
/// </param>
117-
/// <param name="profilePaths">
118-
/// An object containing the profile paths for the session.
119-
/// </param>
120107
/// <param name="editorOperations">
121108
/// An IEditorOperations implementation used to interact with the editor.
122109
/// </param>
123110
public void StartDebugSession(
124-
HostDetails hostDetails,
125-
ProfilePaths profilePaths,
111+
PowerShellContext powerShellContext,
126112
IEditorOperations editorOperations)
127113
{
128114
// Initialize all services
129-
this.PowerShellContext = new PowerShellContext(hostDetails, profilePaths);
115+
this.PowerShellContext = powerShellContext;
130116
this.ConsoleService = new ConsoleService(this.PowerShellContext);
131117
this.RemoteFileManager = new RemoteFileManager(this.PowerShellContext, editorOperations);
132118
this.DebugService = new DebugService(this.PowerShellContext, this.RemoteFileManager);

0 commit comments

Comments
 (0)