Skip to content

Commit 0b75006

Browse files
Properly await calls to ensure exception handling works for sync and async scenarios (dotnet#81826)
2 parents ca94ae4 + d9c3930 commit 0b75006

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/LanguageServer/Protocol/Handler/AbstractRefreshQueue.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected void EnqueueRefreshNotification(DocumentUri? documentUri)
104104
}
105105
}
106106

107-
private ValueTask FilterLspTrackedDocumentsAsync(
107+
private async ValueTask FilterLspTrackedDocumentsAsync(
108108
LspWorkspaceManager lspWorkspaceManager,
109109
IClientLanguageServerManager notificationManager,
110110
ImmutableSegmentedList<DocumentUri?> documentUris,
@@ -117,7 +117,11 @@ private ValueTask FilterLspTrackedDocumentsAsync(
117117
{
118118
try
119119
{
120-
return notificationManager.SendRequestAsync(GetWorkspaceRefreshName(), cancellationToken);
120+
// Fire the notification and immediately return. Refresh notifications are server-wide, and are not
121+
// associated with a particular project/document. So once we've sent one, we can stop processing
122+
// entirely.
123+
await notificationManager.SendRequestAsync(GetWorkspaceRefreshName(), cancellationToken).ConfigureAwait(false);
124+
return;
121125
}
122126
catch (Exception ex) when (ex is ObjectDisposedException or ConnectionLostException)
123127
{
@@ -128,7 +132,6 @@ private ValueTask FilterLspTrackedDocumentsAsync(
128132
}
129133

130134
// LSP is already tracking all changed documents so we don't need to send a refresh request.
131-
return ValueTask.CompletedTask;
132135
}
133136

134137
public virtual void Dispose()

src/LanguageServer/Protocol/Handler/SourceGenerators/SourceGeneratorRefreshQueue.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,27 +120,25 @@ await newProject.GetDependentVersionAsync(_disposalTokenSource.Token).ConfigureA
120120
}
121121
}
122122

123-
private ValueTask RefreshSourceGeneratedDocumentsAsync(
123+
private async ValueTask RefreshSourceGeneratedDocumentsAsync(
124124
CancellationToken cancellationToken)
125125
{
126126
var hasOpenSourceGeneratedDocuments = _lspWorkspaceManager.GetTrackedLspText().Keys.Any(uri => uri.ParsedUri?.Scheme == SourceGeneratedDocumentUri.Scheme);
127127
if (!hasOpenSourceGeneratedDocuments)
128128
{
129129
// There are no opened source generated documents - we don't need to bother asking the client to refresh anything.
130-
return ValueTask.CompletedTask;
130+
return;
131131
}
132132

133133
try
134134
{
135-
return _notificationManager.SendNotificationAsync(RefreshSourceGeneratedDocumentName, cancellationToken);
135+
await _notificationManager.SendNotificationAsync(RefreshSourceGeneratedDocumentName, cancellationToken).ConfigureAwait(false);
136136
}
137137
catch (Exception ex) when (ex is ObjectDisposedException or ConnectionLostException)
138138
{
139139
// It is entirely possible that we're shutting down and the connection is lost while we're trying to send a notification
140140
// as this runs outside of the guaranteed ordering in the queue. We can safely ignore this exception.
141141
}
142-
143-
return ValueTask.CompletedTask;
144142
}
145143

146144
public void Dispose()

0 commit comments

Comments
 (0)