Skip to content

Commit b5f3ff5

Browse files
Close stray processes on exit (#663)
* close stray processes on exit * revert only starting language service * fixed up some comments * remove TODO * alphasort props, move initialization to constructor
1 parent 0cef8c0 commit b5f3ff5

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

src/PowerShellEditorServices.Host/EditorServicesHost.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,30 @@ public class EditorServicesHost
5656
{
5757
#region Private Fields
5858

59-
private ILogger logger;
60-
private bool enableConsoleRepl;
61-
private HostDetails hostDetails;
62-
private ProfilePaths profilePaths;
59+
private string[] additionalModules;
6360
private string bundledModulesPath;
6461
private DebugAdapter debugAdapter;
65-
private string[] additionalModules;
6662
private EditorSession editorSession;
63+
private bool enableConsoleRepl;
6764
private HashSet<string> featureFlags;
65+
private HostDetails hostDetails;
6866
private LanguageServer languageServer;
67+
private ILogger logger;
68+
private ProfilePaths profilePaths;
69+
private TaskCompletionSource<bool> serverCompletedTask;
6970

7071
private IServerListener languageServiceListener;
7172
private IServerListener debugServiceListener;
7273

73-
private TaskCompletionSource<bool> serverCompletedTask;
74-
7574
#endregion
7675

7776
#region Properties
7877

79-
public EditorServicesHostStatus Status { get; private set; }
78+
public int DebugServicePort { get; private set; }
8079

8180
public int LanguageServicePort { get; private set; }
8281

83-
public int DebugServicePort { get; private set; }
82+
public EditorServicesHostStatus Status { get; private set; }
8483

8584
#endregion
8685

@@ -108,6 +107,7 @@ public EditorServicesHost(
108107
this.bundledModulesPath = bundledModulesPath;
109108
this.additionalModules = additionalModules ?? new string[0];
110109
this.featureFlags = new HashSet<string>(featureFlags ?? new string[0]);
110+
this.serverCompletedTask = new TaskCompletionSource<bool>();
111111

112112
#if DEBUG
113113
if (waitForDebugger)
@@ -226,6 +226,7 @@ private async void OnLanguageServiceClientConnect(
226226
this.editorSession,
227227
messageDispatcher,
228228
protocolEndpoint,
229+
this.serverCompletedTask,
229230
this.logger);
230231

231232
await this.editorSession.PowerShellContext.ImportCommandsModule(
@@ -348,7 +349,6 @@ public void StopServices()
348349
public void WaitForCompletion()
349350
{
350351
// TODO: We need a way to know when to complete this task!
351-
this.serverCompletedTask = new TaskCompletionSource<bool>();
352352
this.serverCompletedTask.Task.Wait();
353353
}
354354

@@ -479,4 +479,4 @@ private IServerListener CreateServiceListener(MessageProtocolType protocol, Edit
479479

480480
#endregion
481481
}
482-
}
482+
}

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,31 @@ public class LanguageServer
4040
private Dictionary<string, Dictionary<string, MarkerCorrection>> codeActionsPerFile =
4141
new Dictionary<string, Dictionary<string, MarkerCorrection>>();
4242

43+
private TaskCompletionSource<bool> serverCompletedTask;
44+
4345
public IEditorOperations EditorOperations
4446
{
4547
get { return this.editorOperations; }
4648
}
4749

48-
/// <param name="hostDetails">
49-
/// Provides details about the host application.
50-
/// </param>
50+
/// <summary>
51+
/// Initializes a new language server that is used for handing language server protocol messages
52+
/// </summary>
53+
/// <param name="editorSession">The editor session that handles the PowerShell runspace</param>
54+
/// <param name="messageHandlers">An object that manages all of the message handlers</param>
55+
/// <param name="messageSender">The message sender</param>
56+
/// <param name="serverCompletedTask">A TaskCompletionSource<bool> that will be completed to stop the running process</param>
57+
/// <param name="logger">The logger</param>
5158
public LanguageServer(
5259
EditorSession editorSession,
5360
IMessageHandlers messageHandlers,
5461
IMessageSender messageSender,
62+
TaskCompletionSource<bool> serverCompletedTask,
5563
ILogger logger)
5664
{
5765
this.Logger = logger;
5866
this.editorSession = editorSession;
67+
this.serverCompletedTask = serverCompletedTask;
5968
// Attach to the underlying PowerShell context to listen for changes in the runspace or execution status
6069
this.editorSession.PowerShellContext.RunspaceChanged += PowerShellContext_RunspaceChanged;
6170
this.editorSession.PowerShellContext.ExecutionStatusChanged += PowerShellContext_ExecutionStatusChanged;
@@ -145,7 +154,8 @@ protected Task Stop()
145154
{
146155
Logger.Write(LogLevel.Normal, "Language service is shutting down...");
147156

148-
// TODO: Raise an event so that the host knows to shut down
157+
// complete the task so that the host knows to shut down
158+
this.serverCompletedTask.SetResult(true);
149159

150160
return Task.FromResult(true);
151161
}
@@ -156,7 +166,6 @@ private async Task HandleShutdownRequest(
156166
RequestContext<object> requestContext)
157167
{
158168
// Allow the implementor to shut down gracefully
159-
await this.Stop();
160169

161170
await requestContext.SendResult(new object());
162171
}

0 commit comments

Comments
 (0)