Skip to content

Close stray processes on exit #663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/PowerShellEditorServices.Host/EditorServicesHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,30 @@ public class EditorServicesHost
{
#region Private Fields

private ILogger logger;
private bool enableConsoleRepl;
private HostDetails hostDetails;
private ProfilePaths profilePaths;
private string[] additionalModules;
private string bundledModulesPath;
private DebugAdapter debugAdapter;
private string[] additionalModules;
private EditorSession editorSession;
private bool enableConsoleRepl;
private HashSet<string> featureFlags;
private HostDetails hostDetails;
private LanguageServer languageServer;
private ILogger logger;
private ProfilePaths profilePaths;
private TaskCompletionSource<bool> serverCompletedTask;

private IServerListener languageServiceListener;
private IServerListener debugServiceListener;

private TaskCompletionSource<bool> serverCompletedTask;

#endregion

#region Properties

public EditorServicesHostStatus Status { get; private set; }
public int DebugServicePort { get; private set; }

public int LanguageServicePort { get; private set; }

public int DebugServicePort { get; private set; }
public EditorServicesHostStatus Status { get; private set; }

#endregion

Expand Down Expand Up @@ -108,6 +107,7 @@ public EditorServicesHost(
this.bundledModulesPath = bundledModulesPath;
this.additionalModules = additionalModules ?? new string[0];
this.featureFlags = new HashSet<string>(featureFlags ?? new string[0]);
this.serverCompletedTask = new TaskCompletionSource<bool>();

#if DEBUG
if (waitForDebugger)
Expand Down Expand Up @@ -226,6 +226,7 @@ private async void OnLanguageServiceClientConnect(
this.editorSession,
messageDispatcher,
protocolEndpoint,
this.serverCompletedTask,
this.logger);

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

Expand Down Expand Up @@ -479,4 +479,4 @@ private IServerListener CreateServiceListener(MessageProtocolType protocol, Edit

#endregion
}
}
}
19 changes: 14 additions & 5 deletions src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,31 @@ public class LanguageServer
private Dictionary<string, Dictionary<string, MarkerCorrection>> codeActionsPerFile =
new Dictionary<string, Dictionary<string, MarkerCorrection>>();

private TaskCompletionSource<bool> serverCompletedTask;

public IEditorOperations EditorOperations
{
get { return this.editorOperations; }
}

/// <param name="hostDetails">
/// Provides details about the host application.
/// </param>
/// <summary>
/// Initializes a new language server that is used for handing language server protocol messages
/// </summary>
/// <param name="editorSession">The editor session that handles the PowerShell runspace</param>
/// <param name="messageHandlers">An object that manages all of the message handlers</param>
/// <param name="messageSender">The message sender</param>
/// <param name="serverCompletedTask">A TaskCompletionSource<bool> that will be completed to stop the running process</param>
/// <param name="logger">The logger</param>
public LanguageServer(
EditorSession editorSession,
IMessageHandlers messageHandlers,
IMessageSender messageSender,
TaskCompletionSource<bool> serverCompletedTask,
ILogger logger)
{
this.Logger = logger;
this.editorSession = editorSession;
this.serverCompletedTask = serverCompletedTask;
// Attach to the underlying PowerShell context to listen for changes in the runspace or execution status
this.editorSession.PowerShellContext.RunspaceChanged += PowerShellContext_RunspaceChanged;
this.editorSession.PowerShellContext.ExecutionStatusChanged += PowerShellContext_ExecutionStatusChanged;
Expand Down Expand Up @@ -145,7 +154,8 @@ protected Task Stop()
{
Logger.Write(LogLevel.Normal, "Language service is shutting down...");

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

return Task.FromResult(true);
}
Expand All @@ -156,7 +166,6 @@ private async Task HandleShutdownRequest(
RequestContext<object> requestContext)
{
// Allow the implementor to shut down gracefully
await this.Stop();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like we are simply ignoring the ShutdownRequest message? Does this mean we are really only processing the ExitNotification message in order to stop the lang server?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. The shutdown message is not supposed to actually do things that would stop the process.

It's the message that gets sent to inform the language server that a shutdown is occurring and that you should expect an exit message soon.


await requestContext.SendResult(new object());
}
Expand Down