Skip to content

Commit 5e3a302

Browse files
committed
Make sure the server is shut down before we try to start it up
1 parent 0358e72 commit 5e3a302

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/EditorFeatures/Core/LanguageServer/AbstractInProcLanguageClient.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,16 @@ internal abstract partial class AbstractInProcLanguageClient(
110110

111111
public event AsyncEventHandler<EventArgs>? StartAsync;
112112

113+
public event AsyncEventHandler<EventArgs>? StopAsync;
114+
113115
/// <summary>
114-
/// Unused, implementing <see cref="ILanguageClient"/>
116+
/// Stops the server if it has been started.
115117
/// </summary>
116-
public event AsyncEventHandler<EventArgs>? StopAsync { add { } remove { } }
118+
/// <remarks>
119+
/// Per the documentation on <see cref="ILanguageClient.StopAsync"/>, the event is ignored if the server has not been started.
120+
/// </remarks>
121+
public Task StopServerAsync()
122+
=> StopAsync?.InvokeAsync(this, EventArgs.Empty) ?? Task.CompletedTask;
117123

118124
public async Task<Connection?> ActivateAsync(CancellationToken cancellationToken)
119125
{

src/EditorFeatures/Core/LanguageServer/AlwaysActiveLanguageClientEventListener.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ private void Load()
6666

6767
async Task LoadAsync()
6868
{
69-
7069
// Explicitly switch to the bg so that if this causes any expensive work (like mef loads) it
7170
// doesn't block the UI thread. Note, we always yield because sometimes our caller starts
7271
// on the threadpool thread but is indirectly blocked on by the UI thread.
7372
await TaskScheduler.Default.SwitchTo(alwaysYield: true);
7473

74+
// Sometimes the editor can be slow to stop the old server instance when the old solution is closed, so we force it here.
75+
// This will no-op if the server hasn't been started yet.
76+
await _languageClient.StopServerAsync().ConfigureAwait(false);
77+
7578
await _languageClientBroker.Value.LoadAsync(new LanguageClientMetadata(
7679
[
7780
ContentTypeNames.CSharpContentType,

0 commit comments

Comments
 (0)