Skip to content

Commit 97ad6ff

Browse files
committed
Rename PowerShellSession to PowerShellContext
This change renames the PowerShellSession class to PowerShellContext to avoid confusion with the existing concept of a PSSession in PowerShell.
1 parent a101c9e commit 97ad6ff

17 files changed

+145
-146
lines changed

src/PowerShellEditorServices.Host/DebugAdapter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected async Task HandleLaunchRequest(
101101
// Execute the given PowerShell script and send the response.
102102
// Note that we aren't waiting for execution to complete here
103103
// because the debugger could stop while the script executes.
104-
editorSession.PowerShellSession
104+
editorSession.powerShellContext
105105
.ExecuteScriptAtPath(launchParams.Program)
106106
.ContinueWith(
107107
async (t) =>
@@ -138,18 +138,18 @@ protected Task HandleDisconnectRequest(
138138
handler =
139139
async (o, e) =>
140140
{
141-
if (e.NewSessionState == PowerShellSessionState.Ready)
141+
if (e.NewSessionState == PowerShellContextState.Ready)
142142
{
143143
await requestContext.SendResult(null);
144-
editorSession.PowerShellSession.SessionStateChanged -= handler;
144+
editorSession.powerShellContext.SessionStateChanged -= handler;
145145

146146
// TODO: Find a way to exit more gracefully!
147147
Environment.Exit(0);
148148
}
149149
};
150150

151-
editorSession.PowerShellSession.SessionStateChanged += handler;
152-
editorSession.PowerShellSession.AbortExecution();
151+
editorSession.powerShellContext.SessionStateChanged += handler;
152+
editorSession.powerShellContext.AbortExecution();
153153

154154
return Task.FromResult(true);
155155
}

src/PowerShellEditorServices.Host/LanguageServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ protected async Task HandleCompletionResolveRequest(
366366
if (completionItem.Kind == CompletionItemKind.Function)
367367
{
368368
RunspaceHandle runspaceHandle =
369-
await editorSession.PowerShellSession.GetRunspaceHandle();
369+
await editorSession.powerShellContext.GetRunspaceHandle();
370370

371371
// Get the documentation for the function
372372
CommandInfo commandInfo =

src/PowerShellEditorServices.Host/MessageLoop.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async Task ListenForMessages()
129129
// Set up the PowerShell session
130130
this.editorSession = new EditorSession();
131131
this.editorSession.StartSession(this.consoleHost);
132-
this.editorSession.PowerShellSession.OutputWritten += PowerShellSession_OutputWritten;
132+
this.editorSession.powerShellContext.OutputWritten += powerShellContext_OutputWritten;
133133

134134
if (this.runDebugAdapter)
135135
{
@@ -191,7 +191,7 @@ await this.messageWriter.WriteEvent(
191191
}, null);
192192
}
193193

194-
async void PowerShellSession_OutputWritten(object sender, OutputWrittenEventArgs e)
194+
async void powerShellContext_OutputWritten(object sender, OutputWrittenEventArgs e)
195195
{
196196
await this.messageWriter.WriteEvent(
197197
OutputEvent.Type,

src/PowerShellEditorServices/Analysis/AnalysisService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class AnalysisService : IDisposable
3232
/// </summary>
3333
public AnalysisService()
3434
{
35-
// TODO: Share runspace with PowerShellSession? Probably should always
35+
// TODO: Share runspace with PowerShellContext? Probably should always
3636
// run analysis in a local session.
3737
this.analysisRunspace = RunspaceFactory.CreateRunspace(InitialSessionState.CreateDefault2());
3838
this.analysisRunspace.ApartmentState = ApartmentState.STA;

src/PowerShellEditorServices/Debugging/DebugService.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ namespace Microsoft.PowerShell.EditorServices
1414
{
1515
/// <summary>
1616
/// Provides a high-level service for interacting with the
17-
/// PowerShell debugger in the context of a PowerShellSession.
17+
/// PowerShell debugger in the runspace managed by a PowerShellContext.
1818
/// </summary>
1919
public class DebugService
2020
{
2121
#region Fields
2222

23-
private PowerShellSession powerShellSession;
23+
private PowerShellContext powerShellContext;
2424

2525
// TODO: This needs to be managed per nested session
2626
private Dictionary<string, List<Breakpoint>> breakpointsPerFile =
@@ -36,18 +36,18 @@ public class DebugService
3636

3737
/// <summary>
3838
/// Initializes a new instance of the DebugService class and uses
39-
/// the given PowerShellSession for all future operations.
39+
/// the given PowerShellContext for all future operations.
4040
/// </summary>
41-
/// <param name="powerShellSession">
42-
/// The PowerShellSession to use for all debugging operations.
41+
/// <param name="powerShellContext">
42+
/// The PowerShellContext to use for all debugging operations.
4343
/// </param>
44-
public DebugService(PowerShellSession powerShellSession)
44+
public DebugService(PowerShellContext powerShellContext)
4545
{
46-
Validate.IsNotNull("powerShellSession", powerShellSession);
46+
Validate.IsNotNull("powerShellContext", powerShellContext);
4747

48-
this.powerShellSession = powerShellSession;
49-
this.powerShellSession.DebuggerStop += this.OnDebuggerStop;
50-
this.powerShellSession.BreakpointUpdated += this.OnBreakpointUpdated;
48+
this.powerShellContext = powerShellContext;
49+
this.powerShellContext.DebuggerStop += this.OnDebuggerStop;
50+
this.powerShellContext.BreakpointUpdated += this.OnBreakpointUpdated;
5151
}
5252

5353
#endregion
@@ -81,7 +81,7 @@ public async Task<BreakpointDetails[]> SetBreakpoints(
8181
psCommand.AddParameter("Line", lineNumbers.Length > 0 ? lineNumbers : null);
8282

8383
resultBreakpoints =
84-
await this.powerShellSession.ExecuteCommand<Breakpoint>(
84+
await this.powerShellContext.ExecuteCommand<Breakpoint>(
8585
psCommand);
8686

8787
return
@@ -98,7 +98,7 @@ await this.powerShellSession.ExecuteCommand<Breakpoint>(
9898
/// </summary>
9999
public void Continue()
100100
{
101-
this.powerShellSession.ResumeDebugger(
101+
this.powerShellContext.ResumeDebugger(
102102
DebuggerResumeAction.Continue);
103103
}
104104

@@ -107,7 +107,7 @@ public void Continue()
107107
/// </summary>
108108
public void StepOver()
109109
{
110-
this.powerShellSession.ResumeDebugger(
110+
this.powerShellContext.ResumeDebugger(
111111
DebuggerResumeAction.StepOver);
112112
}
113113

@@ -116,7 +116,7 @@ public void StepOver()
116116
/// </summary>
117117
public void StepIn()
118118
{
119-
this.powerShellSession.ResumeDebugger(
119+
this.powerShellContext.ResumeDebugger(
120120
DebuggerResumeAction.StepInto);
121121
}
122122

@@ -125,7 +125,7 @@ public void StepIn()
125125
/// </summary>
126126
public void StepOut()
127127
{
128-
this.powerShellSession.ResumeDebugger(
128+
this.powerShellContext.ResumeDebugger(
129129
DebuggerResumeAction.StepOut);
130130
}
131131

@@ -137,16 +137,16 @@ public void StepOut()
137137
public void Break()
138138
{
139139
// Break execution in the debugger
140-
this.powerShellSession.BreakExecution();
140+
this.powerShellContext.BreakExecution();
141141
}
142142

143143
/// <summary>
144144
/// Aborts execution of the debugger while it is running, even while
145-
/// it is stopped. Equivalent to calling PowerShellSession.AbortExecution.
145+
/// it is stopped. Equivalent to calling PowerShellContext.AbortExecution.
146146
/// </summary>
147147
public void Abort()
148148
{
149-
this.powerShellSession.AbortExecution();
149+
this.powerShellContext.AbortExecution();
150150
}
151151

152152
/// <summary>
@@ -238,15 +238,15 @@ public VariableDetails GetVariableFromExpression(string variableExpression, int
238238
/// <summary>
239239
/// Evaluates an expression in the context of the stopped
240240
/// debugger. This method will execute the specified expression
241-
/// PowerShellSession.
241+
/// PowerShellContext.
242242
/// </summary>
243243
/// <param name="expressionString">The expression string to execute.</param>
244244
/// <param name="stackFrameId">The ID of the stack frame in which the expression should be executed.</param>
245245
/// <returns>A VariableDetails object containing the result.</returns>
246246
public async Task<VariableDetails> EvaluateExpression(string expressionString, int stackFrameId)
247247
{
248248
var results =
249-
await this.powerShellSession.ExecuteScriptString(
249+
await this.powerShellContext.ExecuteScriptString(
250250
expressionString);
251251

252252
// Since this method should only be getting invoked in the debugger,
@@ -302,7 +302,7 @@ private async Task ClearBreakpointsInFile(ScriptFile scriptFile)
302302
psCommand.AddCommand("Remove-PSBreakpoint");
303303
psCommand.AddParameter("Breakpoint", breakpoints.ToArray());
304304

305-
await this.powerShellSession.ExecuteCommand<object>(psCommand);
305+
await this.powerShellContext.ExecuteCommand<object>(psCommand);
306306

307307
// Clear the existing breakpoints list for the file
308308
breakpoints.Clear();
@@ -319,7 +319,7 @@ private async Task FetchVariables()
319319
psCommand.AddCommand("Get-Variable");
320320
psCommand.AddParameter("Scope", "Local");
321321

322-
var results = await this.powerShellSession.ExecuteCommand<PSVariable>(psCommand);
322+
var results = await this.powerShellContext.ExecuteCommand<PSVariable>(psCommand);
323323

324324
foreach (var variable in results)
325325
{
@@ -336,7 +336,7 @@ private async Task FetchStackFrames()
336336
PSCommand psCommand = new PSCommand();
337337
psCommand.AddCommand("Get-PSCallStack");
338338

339-
var results = await this.powerShellSession.ExecuteCommand<CallStackFrame>(psCommand);
339+
var results = await this.powerShellContext.ExecuteCommand<CallStackFrame>(psCommand);
340340

341341
this.callStackFrames =
342342
results

src/PowerShellEditorServices/Language/LanguageService.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class LanguageService
2323
#region Private Fields
2424

2525
private bool areAliasesLoaded;
26-
private PowerShellSession powerShellSession;
26+
private PowerShellContext powerShellContext;
2727
private CompletionResults mostRecentCompletions;
2828
private int mostRecentRequestLine;
2929
private int mostRecentRequestOffest;
@@ -39,14 +39,14 @@ public class LanguageService
3939
/// Constructs an instance of the LanguageService class and uses
4040
/// the given Runspace to execute language service operations.
4141
/// </summary>
42-
/// <param name="powerShellSession">
43-
/// The PowerShellSession in which language service operations will be executed.
42+
/// <param name="powerShellContext">
43+
/// The PowerShellContext in which language service operations will be executed.
4444
/// </param>
45-
public LanguageService(PowerShellSession powerShellSession)
45+
public LanguageService(PowerShellContext powerShellContext)
4646
{
47-
Validate.IsNotNull("powerShellSession", powerShellSession);
47+
Validate.IsNotNull("powerShellContext", powerShellContext);
4848

49-
this.powerShellSession = powerShellSession;
49+
this.powerShellContext = powerShellContext;
5050

5151
this.CmdletToAliasDictionary = new Dictionary<String, List<String>>(StringComparer.OrdinalIgnoreCase);
5252
this.AliasToCmdletDictionary = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
@@ -87,7 +87,7 @@ public async Task<CompletionResults> GetCompletionsInFile(
8787
columnNumber);
8888

8989
RunspaceHandle runspaceHandle =
90-
await this.powerShellSession.GetRunspaceHandle();
90+
await this.powerShellContext.GetRunspaceHandle();
9191

9292
CompletionResults completionResults =
9393
AstOperations.GetCompletions(
@@ -182,7 +182,7 @@ public async Task<SymbolDetails> FindSymbolDetailsAtLocation(
182182
if (symbolReference != null)
183183
{
184184
RunspaceHandle runspaceHandle =
185-
await this.powerShellSession.GetRunspaceHandle();
185+
await this.powerShellContext.GetRunspaceHandle();
186186

187187
symbolReference.FilePath = scriptFile.FilePath;
188188
symbolDetails = new SymbolDetails(symbolReference, runspaceHandle.Runspace);
@@ -432,7 +432,7 @@ private async Task GetAliases()
432432
{
433433
if (!this.areAliasesLoaded)
434434
{
435-
RunspaceHandle runspaceHandle = await this.powerShellSession.GetRunspaceHandle();
435+
RunspaceHandle runspaceHandle = await this.powerShellContext.GetRunspaceHandle();
436436

437437
CommandInvocationIntrinsics invokeCommand = runspaceHandle.Runspace.SessionStateProxy.InvokeCommand;
438438
IEnumerable<CommandInfo> aliases = invokeCommand.GetCommands("*", CommandTypes.Alias, true);
@@ -463,7 +463,7 @@ private async Task<CommandInfo> GetCommandInfo(string commandName)
463463
command.AddCommand("Get-Command");
464464
command.AddArgument(commandName);
465465

466-
var results = await this.powerShellSession.ExecuteCommand<CommandInfo>(command);
466+
var results = await this.powerShellContext.ExecuteCommand<CommandInfo>(command);
467467
return results.FirstOrDefault();
468468
}
469469

src/PowerShellEditorServices/PowerShellEditorServices.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@
9090
<Compile Include="Session\OutputType.cs" />
9191
<Compile Include="Session\OutputWrittenEventArgs.cs" />
9292
<Compile Include="Session\PowerShellExecutionResult.cs" />
93-
<Compile Include="Session\PowerShellSession.cs" />
94-
<Compile Include="Session\PowerShellSessionState.cs" />
93+
<Compile Include="Session\PowerShellContext.cs" />
94+
<Compile Include="Session\PowerShellContextState.cs" />
9595
<Compile Include="Session\ProgressDetails.cs" />
9696
<Compile Include="Session\RunspaceHandle.cs" />
9797
<Compile Include="Session\SessionPSHost.cs" />

src/PowerShellEditorServices/Session/EditorSession.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public class EditorSession
2323
public Workspace Workspace { get; private set; }
2424

2525
/// <summary>
26-
/// Gets the PowerShellSession instance for this session.
26+
/// Gets the PowerShellContext instance for this session.
2727
/// </summary>
28-
public PowerShellSession PowerShellSession { get; private set; }
28+
public PowerShellContext powerShellContext { get; private set; }
2929

3030
/// <summary>
3131
/// Gets the LanguageService instance for this session.
@@ -60,10 +60,10 @@ public void StartSession(IConsoleHost consoleHost)
6060
this.Workspace = new Workspace();
6161

6262
// Initialize all services
63-
this.PowerShellSession = new PowerShellSession();
64-
this.LanguageService = new LanguageService(this.PowerShellSession);
63+
this.powerShellContext = new PowerShellContext();
64+
this.LanguageService = new LanguageService(this.powerShellContext);
6565
this.AnalysisService = new AnalysisService();
66-
this.DebugService = new DebugService(this.PowerShellSession);
66+
this.DebugService = new DebugService(this.powerShellContext);
6767
}
6868

6969
#endregion
@@ -82,10 +82,10 @@ public void Dispose()
8282
this.AnalysisService = null;
8383
}
8484

85-
if (this.PowerShellSession != null)
85+
if (this.powerShellContext != null)
8686
{
87-
this.PowerShellSession.Dispose();
88-
this.PowerShellSession = null;
87+
this.powerShellContext.Dispose();
88+
this.powerShellContext = null;
8989
}
9090
}
9191

0 commit comments

Comments
 (0)