Skip to content

Commit 9469447

Browse files
N. Taylor Mullendavid-driscollmergify[bot]
authored
Use ConfigureAwait when booting up input stream. (#354)
* Use ConfigureAwait when booting up input stream. - Razor initializes O#'s language server in-proc in Visual Studio and because the `pipeReader.ReadAsync` doesn't utilize `ConfigureAwait(false)` it attempts to only ever read information on the main thread which is a problem if a feature such as light bulbs or go-to-definition require. * ConfigureAwait(false) all the things Co-authored-by: David Driscoll <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent debb27d commit 9469447

38 files changed

+129
-122
lines changed

src/Client/LanguageClient.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static Task<LanguageClient> From(Action<LanguageClientOptions> optionsAct
9797
public static async Task<LanguageClient> From(LanguageClientOptions options, IServiceProvider outerServiceProvider, CancellationToken cancellationToken)
9898
{
9999
var server = Create(options, outerServiceProvider);
100-
await server.Initialize(cancellationToken);
100+
await server.Initialize(cancellationToken).ConfigureAwait(false);
101101
return server;
102102
}
103103

@@ -261,10 +261,10 @@ await LanguageProtocolEventingHelper.Run(
261261
(handler, ct) => handler.OnInitialize(this, @params, ct),
262262
_concurrency,
263263
token
264-
);
264+
).ConfigureAwait(false);
265265

266266
_connection.Open();
267-
var serverParams = await SendRequest(ClientSettings, token);
267+
var serverParams = await SendRequest(ClientSettings, token).ConfigureAwait(false);
268268
_receiver.Initialized();
269269

270270
ServerSettings = serverParams;
@@ -276,7 +276,7 @@ await LanguageProtocolEventingHelper.Run(
276276
(handler, ct) => handler.OnInitialized(this, @params, serverParams, ct),
277277
_concurrency,
278278
token
279-
);
279+
).ConfigureAwait(false);
280280

281281
// post init
282282

@@ -290,7 +290,7 @@ await LanguageProtocolEventingHelper.Run(
290290
(handler, ct) => handler.OnStarted(this, ct),
291291
_concurrency,
292292
token
293-
);
293+
).ConfigureAwait(false);
294294

295295
_instanceHasStarted.Started = true;
296296

@@ -361,11 +361,11 @@ public async Task Shutdown()
361361
{
362362
if (_connection.IsOpen)
363363
{
364-
await this.RequestShutdown();
364+
await this.RequestShutdown().ConfigureAwait(false);
365365
this.SendExit();
366366
}
367367

368-
await _connection.StopAsync();
368+
await _connection.StopAsync().ConfigureAwait(false);
369369
_connection.Dispose();
370370
}
371371

src/Dap.Client/DebugAdapterClient.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static Task<DebugAdapterClient> From(Action<DebugAdapterClientOptions> op
7676
public static async Task<DebugAdapterClient> From(DebugAdapterClientOptions options, IServiceProvider outerServiceProvider, CancellationToken cancellationToken)
7777
{
7878
var server = Create(options, outerServiceProvider);
79-
await server.Initialize(cancellationToken);
79+
await server.Initialize(cancellationToken).ConfigureAwait(false);
8080
return server;
8181
}
8282

@@ -127,12 +127,12 @@ await DebugAdapterEventingHelper.Run(
127127
(handler, ct) => handler.OnInitialize(this, ClientSettings, ct),
128128
_concurrency,
129129
token
130-
);
130+
).ConfigureAwait(false);
131131

132132
RegisterCapabilities(ClientSettings);
133133

134134
_connection.Open();
135-
var serverParams = await this.RequestDebugAdapterInitialize(ClientSettings, token);
135+
var serverParams = await this.RequestDebugAdapterInitialize(ClientSettings, token).ConfigureAwait(false);
136136

137137
ServerSettings = serverParams;
138138
_receiver.Initialized();
@@ -144,7 +144,7 @@ await DebugAdapterEventingHelper.Run(
144144
(handler, ct) => handler.OnInitialized(this, ClientSettings, ServerSettings, ct),
145145
_concurrency,
146146
token
147-
);
147+
).ConfigureAwait(false);
148148

149149
await _initializedComplete.ToTask(token);
150150

@@ -155,22 +155,13 @@ await DebugAdapterEventingHelper.Run(
155155
(handler, ct) => handler.OnStarted(this, ct),
156156
_concurrency,
157157
token
158-
);
158+
).ConfigureAwait(false);
159159

160160
_instanceHasStarted.Started = true;
161161
}
162162

163163
async Task<Unit> IRequestHandler<InitializedEvent, Unit>.Handle(InitializedEvent request, CancellationToken cancellationToken)
164164
{
165-
await DebugAdapterEventingHelper.Run(
166-
_initializedDelegates,
167-
(handler, ct) => handler(this, ClientSettings, ServerSettings, ct),
168-
_initializedHandlers.Union(_collection.Select(z => z.Handler).OfType<IOnDebugAdapterClientInitialized>()),
169-
(handler, ct) => handler.OnInitialized(this, ClientSettings, ServerSettings, ct),
170-
_concurrency,
171-
cancellationToken
172-
);
173-
174165
_initializedComplete.OnNext(request);
175166
_initializedComplete.OnCompleted();
176167
return Unit.Value;

src/Dap.Server/DebugAdapterServer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static Task<DebugAdapterServer> From(Action<DebugAdapterServerOptions> op
7878
public static async Task<DebugAdapterServer> From(DebugAdapterServerOptions options, IServiceProvider outerServiceProvider, CancellationToken cancellationToken)
7979
{
8080
var server = Create(options, outerServiceProvider);
81-
await server.Initialize(cancellationToken);
81+
await server.Initialize(cancellationToken).ConfigureAwait(false);
8282
return server;
8383
}
8484

@@ -125,7 +125,7 @@ public async Task Initialize(CancellationToken token)
125125
{
126126
try
127127
{
128-
await _initializingTask;
128+
await _initializingTask.ConfigureAwait(false);
129129
}
130130
catch
131131
{
@@ -139,15 +139,15 @@ public async Task Initialize(CancellationToken token)
139139
try
140140
{
141141
_initializingTask = _initializeComplete.ToTask(token);
142-
await _initializingTask;
142+
await _initializingTask.ConfigureAwait(false);
143143
await DebugAdapterEventingHelper.Run(
144144
_startedDelegates,
145145
(handler, ct) => handler(this, ct),
146146
_startedHandlers.Union(_collection.Select(z => z.Handler).OfType<IOnDebugAdapterServerStarted>()),
147147
(handler, ct) => handler.OnStarted(this, ct),
148148
_concurrency,
149149
token
150-
);
150+
).ConfigureAwait(false);
151151
_instanceHasStarted.Started = true;
152152

153153
this.SendDebugAdapterInitialized(new InitializedEvent());
@@ -178,7 +178,7 @@ await DebugAdapterEventingHelper.Run(
178178
(handler, ct) => handler.OnInitialize(this, request, ct),
179179
_concurrency,
180180
cancellationToken
181-
);
181+
).ConfigureAwait(false);
182182

183183
_receiver.Initialized();
184184

@@ -230,7 +230,7 @@ await DebugAdapterEventingHelper.Run(
230230
(handler, ct) => handler.OnInitialized(this, request, response, ct),
231231
_concurrency,
232232
cancellationToken
233-
);
233+
).ConfigureAwait(false);
234234

235235
_initializeComplete.OnNext(response);
236236
_initializeComplete.OnCompleted();

src/Dap.Shared/DapResponseRouter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public async Task<TResponse> Returning<TResponse>(CancellationToken cancellation
117117

118118
try
119119
{
120-
var result = await tcs.Task;
120+
var result = await tcs.Task.ConfigureAwait(false);
121121
if (typeof(TResponse) == typeof(Unit))
122122
{
123123
return (TResponse) (object) Unit.Value;
@@ -131,7 +131,7 @@ public async Task<TResponse> Returning<TResponse>(CancellationToken cancellation
131131
}
132132
}
133133

134-
public async Task ReturningVoid(CancellationToken cancellationToken) => await Returning<Unit>(cancellationToken);
134+
public async Task ReturningVoid(CancellationToken cancellationToken) => await Returning<Unit>(cancellationToken).ConfigureAwait(false);
135135
}
136136
}
137137
}

src/Dap.Testing/DebugAdapterProtocolTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Action<DebugAdapterServerOptions> serverOptionsAction
8080
return await Observable.FromAsync(_client.Initialize).ForkJoin(
8181
Observable.FromAsync(_server.Initialize),
8282
(a, b) => ( _client, _server )
83-
).ToTask(CancellationToken);
83+
).ToTask(CancellationToken).ConfigureAwait(false);
8484
}
8585
}
8686
}

src/Dap.Testing/DebugAdapterServerTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected virtual async Task<IDebugAdapterClient> InitializeClient(Action<DebugA
4646

4747
Disposable.Add(_client);
4848

49-
await _client.Initialize(CancellationToken);
49+
await _client.Initialize(CancellationToken).ConfigureAwait(false);
5050

5151
return _client;
5252
}

src/JsonRpc.Testing/JsonRpcServerTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Action<JsonRpcServerOptions> serverOptionsAction
7171
}, CancellationToken
7272
);
7373

74-
await Task.WhenAll(clientTask, serverTask);
74+
await Task.WhenAll(clientTask, serverTask).ConfigureAwait(false);
7575
_client = clientTask.Result;
7676
_server = serverTask.Result;
7777

src/JsonRpc.Testing/SettlePipeline.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async Task<R> IPipelineBehavior<T, R>.Handle(T request, CancellationToken cancel
1616
_settler.OnStartRequest();
1717
try
1818
{
19-
return await next();
19+
return await next().ConfigureAwait(false);
2020
}
2121
finally
2222
{

src/JsonRpc/DelegatingHandlers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public Request(Func<TParams, Task> handler) : this((a, ct) => handler(a))
3939
async Task<Unit> IRequestHandler<TParams, Unit>.
4040
Handle(TParams request, CancellationToken cancellationToken)
4141
{
42-
await _handler(request, cancellationToken);
42+
await _handler(request, cancellationToken).ConfigureAwait(false);
4343
return Unit.Value;
4444
}
4545
}
@@ -62,7 +62,7 @@ public Notification(Action<TParams, CancellationToken> handler) : this(
6262

6363
async Task<Unit> IRequestHandler<TParams, Unit>.Handle(TParams request, CancellationToken cancellationToken)
6464
{
65-
await _handler(request, cancellationToken);
65+
await _handler(request, cancellationToken).ConfigureAwait(false);
6666
return Unit.Value;
6767
}
6868
}

src/JsonRpc/DelegatingJsonNotificationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DelegatingJsonNotificationHandler : IJsonRpcNotificationHandler<Del
1414

1515
public async Task<Unit> Handle(DelegatingNotification<JToken> request, CancellationToken cancellationToken)
1616
{
17-
await _handler.Invoke(request.Value, cancellationToken);
17+
await _handler.Invoke(request.Value, cancellationToken).ConfigureAwait(false);
1818
return Unit.Value;
1919
}
2020
}

0 commit comments

Comments
 (0)