Skip to content

Commit 9902562

Browse files
committed
Merge PS context into execution service, make REPL service a subcomponent
1 parent 9036dc8 commit 9902562

13 files changed

+461
-505
lines changed

ex.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function run(timeout, count) {
2+
let i = 0;
3+
function inner() {
4+
if (i === count) {
5+
return;
6+
}
7+
console.log(i);
8+
i++;
9+
setTimeout(inner, timeout);
10+
}
11+
inner();
12+
}
13+

src/PowerShellEditorServices/Server/PsesLanguageServer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ public async Task StartAsync()
102102
{
103103
IServiceProvider serviceProvider = languageServer.Services;
104104

105-
serviceProvider.GetService<PowerShellConsoleService>().StartRepl();
106-
107105
var workspaceService = serviceProvider.GetService<WorkspaceService>();
108106

109107
// Grab the workspace path from the parameters

src/PowerShellEditorServices/Server/PsesServiceCollectionExtensions.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ public static IServiceCollection AddPsesLanguageServices(
2929
provider.GetService<ILoggerFactory>(),
3030
provider.GetService<ILanguageServer>(),
3131
hostStartupInfo))
32-
.AddSingleton<PowerShellConsoleService>(
33-
(provider) => PowerShellConsoleService.CreateAndStart(
34-
provider.GetService<ILoggerFactory>(),
35-
provider.GetService<PowerShellExecutionService>()))
3632
.AddSingleton<TemplateService>()
3733
.AddSingleton<EditorOperationsService>()
3834
.AddSingleton<RemoteFileManagerService>()

src/PowerShellEditorServices/Services/PowerShell/Console/ConsoleReadLine.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6-
using System.Collections.ObjectModel;
7-
using System.Linq;
86
using System.Text;
97
using System.Threading;
108
using System.Threading.Tasks;
119

1210
namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Console
1311
{
1412
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution;
15-
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
1613
using System;
1714
using System.Collections.Generic;
1815
using System.Management.Automation;

src/PowerShellEditorServices/Services/PowerShell/PowerShellConsoleService.cs renamed to src/PowerShellEditorServices/Services/PowerShell/Console/ConsoleReplRunner.cs

Lines changed: 17 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,25 @@
11
using Microsoft.Extensions.Logging;
2-
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Console;
32
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution;
43
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
54
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility;
6-
using Microsoft.PowerShell.EditorServices.Utility;
5+
using PowerShellEditorServices.Services.PowerShell.Utility;
76
using System;
87
using System.Collections.Concurrent;
98
using System.Collections.Generic;
109
using System.Linq;
1110
using System.Management.Automation;
12-
using System.Management.Automation.Runspaces;
13-
using System.Reflection;
1411
using System.Text;
1512
using System.Threading;
1613
using System.Threading.Tasks;
1714

18-
namespace Microsoft.PowerShell.EditorServices.Services.PowerShell
15+
namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Console
1916
{
20-
internal class PowerShellConsoleService : IDisposable
17+
internal class ConsoleReplRunner : IDisposable
2118
{
22-
public static PowerShellConsoleService CreateAndStart(
23-
ILoggerFactory loggerFactory,
24-
PowerShellExecutionService executionService)
25-
{
26-
return new PowerShellConsoleService(
27-
loggerFactory,
28-
executionService,
29-
executionService.EditorServicesHost,
30-
executionService.ReadLine,
31-
executionService.PSReadLineProxy);
32-
}
33-
3419
private readonly ILogger _logger;
3520

3621
private readonly PowerShellExecutionService _executionService;
3722

38-
private readonly EditorServicesConsolePSHost _editorServicesHost;
39-
40-
private readonly ConsoleReadLine _readLine;
41-
42-
private readonly PSReadLineProxy _psrlProxy;
43-
4423
private readonly ConcurrentStack<ReplTask> _replLoopTaskStack;
4524

4625
// This is required because PSRL will keep prompting for keys as we push a new REPL task
@@ -52,35 +31,23 @@ public static PowerShellConsoleService CreateAndStart(
5231

5332
private bool _exiting;
5433

55-
private bool _debugging;
56-
57-
private PowerShellConsoleService(
34+
public ConsoleReplRunner(
5835
ILoggerFactory loggerFactory,
59-
PowerShellExecutionService executionService,
60-
EditorServicesConsolePSHost editorServicesHost,
61-
ConsoleReadLine readLine,
62-
PSReadLineProxy psrlProxy)
36+
PowerShellExecutionService executionService)
6337
{
64-
_logger = loggerFactory.CreateLogger<PowerShellConsoleService>();
38+
_logger = loggerFactory.CreateLogger<ConsoleReplRunner>();
6539
_replLoopTaskStack = new ConcurrentStack<ReplTask>();
6640
_commandCancellationStack = new ConcurrentStack<CommandCancellation>();
6741
_executionService = executionService;
68-
_editorServicesHost = editorServicesHost;
69-
_readLine = readLine;
70-
_psrlProxy = psrlProxy;
7142
_exiting = false;
72-
_debugging = false;
7343
}
7444

7545
public void StartRepl()
7646
{
7747
System.Console.CancelKeyPress += OnCancelKeyPress;
7848
System.Console.InputEncoding = Encoding.UTF8;
7949
System.Console.OutputEncoding = Encoding.UTF8;
80-
_psrlProxy.OverrideReadKey(ReadKey);
81-
_executionService.PowerShellPushed += OnPowerShellPushed;
82-
_executionService.PromptCancellationRequested += OnPromptCancellationRequested;
83-
_executionService.FrameExiting += OnFrameExiting;
50+
_executionService.PSReadLineProxy.OverrideReadKey(ReadKey);
8451
PushNewReplTask();
8552
}
8653

@@ -92,9 +59,6 @@ public void Dispose()
9259
}
9360

9461
System.Console.CancelKeyPress -= OnCancelKeyPress;
95-
_executionService.PowerShellPushed -= OnPowerShellPushed;
96-
_executionService.PromptCancellationRequested -= OnPromptCancellationRequested;
97-
_executionService.FrameExiting -= OnFrameExiting;
9862
}
9963

10064
public void CancelCurrentPrompt()
@@ -149,7 +113,7 @@ private async Task RunReplLoopAsync()
149113
if (currentCommandCancellation.CancellationSource.IsCancellationRequested
150114
|| LastKeyWasCtrlC())
151115
{
152-
_editorServicesHost.UI.WriteLine();
116+
_executionService.EditorServicesHost.UI.WriteLine();
153117
}
154118
continue;
155119
}
@@ -190,9 +154,9 @@ private async Task<string> GetPromptStringAsync(CancellationToken cancellationTo
190154
{
191155
string prompt = (await GetPromptOutputAsync(cancellationToken).ConfigureAwait(false)).FirstOrDefault() ?? "PS> ";
192156

193-
if (_editorServicesHost.Runspace.RunspaceIsRemote)
157+
if (_executionService.EditorServicesHost.Runspace.RunspaceIsRemote)
194158
{
195-
prompt = _editorServicesHost.Runspace.GetRemotePrompt(prompt);
159+
prompt = _executionService.EditorServicesHost.Runspace.GetRemotePrompt(prompt);
196160
}
197161

198162
return prompt;
@@ -210,12 +174,12 @@ private Task<IReadOnlyList<string>> GetPromptOutputAsync(CancellationToken cance
210174

211175
private void WritePrompt(string promptString)
212176
{
213-
_editorServicesHost.UI.Write(promptString);
177+
_executionService.EditorServicesHost.UI.Write(promptString);
214178
}
215179

216180
private Task<string> InvokeReadLineAsync(CancellationToken cancellationToken)
217181
{
218-
return _readLine.ReadCommandLineAsync(cancellationToken);
182+
return _executionService.ReadLine.ReadCommandLineAsync(cancellationToken);
219183
}
220184

221185
private Task InvokeInputAsync(string input, CancellationToken cancellationToken)
@@ -230,30 +194,17 @@ private Task InvokeInputAsync(string input, CancellationToken cancellationToken)
230194
return _executionService.ExecutePSCommandAsync(command, executionOptions, cancellationToken);
231195
}
232196

233-
private void OnCancelKeyPress(object sender, ConsoleCancelEventArgs args)
234-
{
235-
CancelCurrentPrompt();
236-
}
237-
238-
private void OnPowerShellPushed(object sender, PowerShellPushedArgs args)
197+
public void SetReplPop()
239198
{
240-
if ((args.FrameType & PowerShellFrameType.NonInteractive) == 0)
241-
{
242-
PushNewReplTask();
243-
}
199+
_exiting = true;
200+
StopCurrentRepl();
244201
}
245202

246-
private void OnPromptCancellationRequested(object sender, PromptCancellationRequestedArgs args)
203+
private void OnCancelKeyPress(object sender, ConsoleCancelEventArgs args)
247204
{
248205
CancelCurrentPrompt();
249206
}
250207

251-
private void OnFrameExiting(object sender, FrameExitingArgs args)
252-
{
253-
_exiting = true;
254-
StopCurrentRepl();
255-
}
256-
257208
private void OnReplCanceled()
258209
{
259210
// Ordinarily, when the REPL is canceled
@@ -293,12 +244,11 @@ private bool LastKeyWasCtrlC()
293244
&& (_lastKey.Value.Modifiers & ConsoleModifiers.Alt) == 0;
294245
}
295246

296-
private void PushNewReplTask()
247+
public void PushNewReplTask()
297248
{
298249
ReplTask.PushAndStart(_replLoopTaskStack, RunReplLoopAsync, OnReplCanceled);
299250
}
300251

301-
302252
private class ReplTask
303253
{
304254
public static void PushAndStart(
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Management.Automation;
2+
3+
namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution
4+
{
5+
internal class DebuggerResumingEventArgs
6+
{
7+
public DebuggerResumingEventArgs(DebuggerResumeAction resumeAction)
8+
{
9+
ResumeAction = resumeAction;
10+
}
11+
12+
public DebuggerResumeAction ResumeAction { get; }
13+
14+
}
15+
}

0 commit comments

Comments
 (0)