File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
src/EditorFeatures/Core/LanguageServer Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments