Add more await or unawaited() to DAS.

Change-Id: I45b2b988141c235b6fbe50e69fa018627e20e004
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/251146
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2022-07-12 00:59:01 +00:00 committed by Commit Bot
parent 635a3bf00f
commit 33295f8247
29 changed files with 68 additions and 51 deletions

View file

@ -33,7 +33,7 @@ Future main(List<String> args) async {
);
runner.addCommand(ListCommand(benchmarks));
runner.addCommand(RunCommand(benchmarks));
runner.run(args);
await runner.run(args);
}
String get analysisServerSrcPath {

View file

@ -112,7 +112,7 @@ class Driver extends IntegrationTestMixin {
logger.log(Level.FINE, 'requesting server shutdown');
// Give the server a short time to comply with the shutdown request; if it
// doesn't exit, then forcibly terminate it.
sendServerShutdown();
unawaited(sendServerShutdown());
await server.exitCode.timeout(timeout, onTimeout: () {
return server.kill('server failed to exit');
});

View file

@ -195,7 +195,7 @@ class LspAnalysisServerBenchmarkTest extends AbstractBenchmarkTest
@override
Future<void> shutdown() async {
_test.tearDown();
_logger.shutdown();
await _logger.shutdown();
}
@override
@ -254,7 +254,7 @@ mixin ServerMemoryUsageMixin {
total += heapUsage['heapUsage'] + heapUsage['externalUsage'] as int;
}
service.dispose();
await service.dispose();
return total;
}

View file

@ -805,7 +805,7 @@ class AnalysisServer extends AbstractAnalysisServer {
_refactoringManager = RefactoringManager(this, refactoringWorkspace);
}
Future<void> _scheduleAnalysisImplementedNotification() async {
void _scheduleAnalysisImplementedNotification() {
var files = analysisServices[AnalysisService.IMPLEMENTED];
if (files != null) {
scheduleImplementedNotification(this, files);

View file

@ -16,14 +16,14 @@ class AnalysisReanalyzeHandler extends LegacyHandler {
@override
Future<void> handle() async {
server.options.analytics?.sendEvent('analysis', 'reanalyze');
unawaited(server.options.analytics?.sendEvent('analysis', 'reanalyze'));
await server.reanalyze();
//
// Restart all of the plugins. This is an async operation that will happen
// in the background.
//
server.pluginManager.restartPlugins();
unawaited(server.pluginManager.restartPlugins());
sendResult(AnalysisReanalyzeResult());
}

View file

@ -21,8 +21,11 @@ class AnalysisSetAnalysisRootsHandler extends LegacyHandler {
var includedPathList = params.included;
var excludedPathList = params.excluded;
server.options.analytics?.sendEvent('analysis', 'setAnalysisRoots',
value: includedPathList.length);
unawaited(server.options.analytics?.sendEvent(
'analysis',
'setAnalysisRoots',
value: includedPathList.length,
));
server.analyticsManager.startedSetAnalysisRoots(params);
// validate

View file

@ -25,7 +25,7 @@ class AnalyticsSendEventHandler extends LegacyHandler {
}
var params = AnalyticsSendEventParams.fromRequest(request);
analytics.sendEvent(_clientId, params.action);
unawaited(analytics.sendEvent(_clientId, params.action));
sendResult(AnalyticsSendEventResult());
}
}

View file

@ -25,7 +25,8 @@ class AnalyticsSendTimingHandler extends LegacyHandler {
}
var params = AnalyticsSendTimingParams.fromRequest(request);
analytics.sendTiming(params.event, params.millis, category: _clientId);
unawaited(
analytics.sendTiming(params.event, params.millis, category: _clientId));
sendResult(AnalyticsSendTimingResult());
}
}

View file

@ -41,7 +41,7 @@ class CompletionGetSuggestionsHandler extends CompletionGetSuggestions2Handler {
}
var performance = OperationPerformanceImpl('<root>');
performance.runAsync(
await performance.runAsync(
'request',
(performance) async {
if (file.endsWith('.yaml')) {

View file

@ -147,7 +147,7 @@ class CompletionGetSuggestions2Handler extends CompletionHandler
}
var performance = OperationPerformanceImpl('<root>');
performance.runAsync(
await performance.runAsync(
'request',
(performance) async {
var resolvedUnit = await performance.runAsync(

View file

@ -20,7 +20,7 @@ class EditFormatHandler extends LegacyHandler {
@override
Future<void> handle() async {
server.options.analytics?.sendEvent('edit', 'format');
unawaited(server.options.analytics?.sendEvent('edit', 'format'));
var params = EditFormatParams.fromRequest(request);
var file = params.file;

View file

@ -18,7 +18,10 @@ class EditGetPostfixCompletionHandler extends LegacyHandler {
@override
Future<void> handle() async {
server.options.analytics?.sendEvent('edit', 'getPostfixCompletion');
unawaited(server.options.analytics?.sendEvent(
'edit',
'getPostfixCompletion',
));
var params = EditGetPostfixCompletionParams.fromRequest(request);
var file = params.file;

View file

@ -21,7 +21,10 @@ class EditOrganizeDirectivesHandler extends LegacyHandler {
@override
Future<void> handle() async {
// TODO(brianwilkerson) Move analytics tracking out of [handleRequest].
server.options.analytics?.sendEvent('edit', 'organizeDirectives');
unawaited(server.options.analytics?.sendEvent(
'edit',
'organizeDirectives',
));
var params = EditOrganizeDirectivesParams.fromRequest(request);
var file = params.file;

View file

@ -343,12 +343,12 @@ class PluginManager {
_pluginMap[path] = plugin;
try {
var session = await plugin.start(byteStorePath, sdkPath);
session?.onDone.then((_) {
unawaited(session?.onDone.then((_) {
if (_pluginMap[path] == plugin) {
_pluginMap.remove(path);
_notifyPluginsChanged();
}
});
}));
} catch (exception, stackTrace) {
// Record the exception (for debugging purposes) and record the fact
// that we should not try to communicate with the plugin.
@ -534,9 +534,9 @@ class PluginManager {
//
_pluginMap[path] = plugin;
var session = await plugin.start(byteStorePath, sdkPath);
session?.onDone.then((_) {
unawaited(session?.onDone.then((_) {
_pluginMap.remove(path);
});
}));
//
// Re-initialize the plugin.
//
@ -993,7 +993,7 @@ class PluginSession {
name = result.name;
version = result.version;
if (!isCompatible) {
sendRequest(PluginShutdownParams());
unawaited(sendRequest(PluginShutdownParams()));
info.reportException(CaughtException(
PluginException('Plugin is not compatible.'), StackTrace.current));
return false;

View file

@ -129,14 +129,15 @@ class DevAnalysisServer {
}
});
_channel.sendRequest(Request('${_nextId++}', 'server.setSubscriptions', {
await _channel
.sendRequest(Request('${_nextId++}', 'server.setSubscriptions', {
'subscriptions': ['STATUS'],
}));
directories =
directories.map((dir) => path.normalize(path.absolute(dir))).toList();
_channel.sendRequest(Request(
await _channel.sendRequest(Request(
'${_nextId++}',
'analysis.setAnalysisRoots',
{'included': directories, 'excluded': []},

View file

@ -428,7 +428,7 @@ class Driver implements ServerStarter {
}
await instrumentationService.shutdown();
socketServer.analysisServer!.shutdown();
unawaited(socketServer.analysisServer!.shutdown());
try {
tempDriverDir.deleteSync(recursive: true);
@ -454,7 +454,7 @@ class Driver implements ServerStarter {
httpServer.close();
}
await instrumentationService.shutdown();
socketServer.analysisServer!.shutdown();
unawaited(socketServer.analysisServer!.shutdown());
if (sendPort == null) exit(0);
});
},
@ -502,7 +502,7 @@ class Driver implements ServerStarter {
// Only shutdown the server and exit if the server is not already
// handling the shutdown.
if (!socketServer.analysisServer!.willExit) {
socketServer.analysisServer!.shutdown();
unawaited(socketServer.analysisServer!.shutdown());
exit(0);
}
});

View file

@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:analysis_server/src/socket_server.dart';
@ -102,7 +103,7 @@ class HttpAnalysisServer {
response.headers.contentType = ContentType.text;
response.write(
'WebSocket connections not supported (${request.uri.path}).');
response.close();
unawaited(response.close());
} else {
_returnUnknownRequest(request);
}

View file

@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io';
@ -192,7 +193,7 @@ abstract class Site {
var path = request.uri.path;
if (path == '/') {
respondRedirect(request, pages.first.path);
unawaited(respondRedirect(request, pages.first.path));
return;
}
@ -201,7 +202,7 @@ abstract class Site {
var response = request.response;
response.headers.contentType = ContentType.html;
response.write(await page.generate(request.uri.queryParameters));
response.close();
unawaited(response.close());
return;
}
}
@ -216,7 +217,7 @@ abstract class Site {
response.statusCode = HttpStatus.internalServerError;
response.headers.contentType = ContentType.text;
response.write('$e\n\n$st');
response.close();
unawaited(response.close());
}
}
}

View file

@ -79,7 +79,8 @@ class CompletionTestCase extends AbstractCompletionDomainTest {
.toList();
}
Future runTest(LocationSpec spec, [Map<String, String>? extraFiles]) async {
Future<void> runTest(LocationSpec spec,
[Map<String, String>? extraFiles]) async {
await super.setUp();
try {
@ -102,7 +103,7 @@ class CompletionTestCase extends AbstractCompletionDomainTest {
assertHasNoCompletion(result);
}
} finally {
super.tearDown();
await super.tearDown();
}
}
}

View file

@ -1458,7 +1458,7 @@ void f(A a) {}
/// Repeat a few times, eventually there will be no work to do.
Future<void> _waitAnalysisComplete() async {
for (var i = 0; i < 128; i++) {
pumpEventQueue();
await pumpEventQueue();
await server.onAnalysisComplete;
}
}

View file

@ -130,7 +130,7 @@ class ExecutionDomainTest extends PubPackageAnalysisServerTest {
@override
Future<void> tearDown() async {
await _disposeExecutionContext();
super.tearDown();
await super.tearDown();
}
Future<void> test_createAndDeleteMultipleContexts() async {

View file

@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:analysis_server/protocol/protocol.dart';
import 'package:analysis_server/protocol/protocol_generated.dart';
import 'package:analysis_server/src/services/refactoring/refactoring_manager.dart';
@ -877,8 +879,7 @@ class GetAvailableRefactoringsTest extends PubPackageAnalysisServerTest {
var request =
EditGetAvailableRefactoringsParams(testFile.path, offset, length)
.toRequest('0');
serverChannel.sendRequest(request);
var response = await serverChannel.waitForResponse(request);
var response = await serverChannel.sendRequest(request);
var result = EditGetAvailableRefactoringsResult.fromResponse(response);
kinds = result.kinds;
}
@ -2250,7 +2251,8 @@ void f() {
print(otherName);
}
''');
server.getAnalysisDriver(testFile.path)!.getResult(testFile.path);
unawaited(
server.getAnalysisDriver(testFile.path)!.getResult(testFile.path));
// send the second request, with the same kind, file and offset
await waitForTasksFinished();
result = await getRefactoringResult(() {

View file

@ -31,7 +31,7 @@ class FieldFormalParameterTest2 extends AbstractCompletionDriverTest
mixin SuperFormalParameterTestCases on AbstractCompletionDriverTest {
Future<void> test_class_replacement_left() async {
_checkContainers(
await _checkContainers(
declarations: 'var field = 0;',
constructorParameters: 'this.f^',
validator: (response) {
@ -48,7 +48,7 @@ mixin SuperFormalParameterTestCases on AbstractCompletionDriverTest {
}
Future<void> test_class_replacement_right() async {
_checkContainers(
await _checkContainers(
declarations: 'var field = 0;',
constructorParameters: 'this.^f',
validator: (response) {
@ -105,7 +105,7 @@ class B extends A {
}
Future<void> test_class_suggestions_onlyNotSpecified_optionalNamed() async {
_checkContainers(
await _checkContainers(
declarations: 'final int x; final int y;',
constructorParameters: '{this.x, this.^}',
validator: (response) {
@ -123,7 +123,7 @@ class B extends A {
Future<void>
test_class_suggestions_onlyNotSpecified_requiredPositional() async {
_checkContainers(
await _checkContainers(
declarations: 'final int x; final int y;',
constructorParameters: 'this.x, this.^',
validator: (response) {

View file

@ -45,7 +45,7 @@ class B {}
// Delete the file, the set should be removed.
deleteFile(path);
waitForSetWithUriRemoved(uriStr);
await waitForSetWithUriRemoved(uriStr);
}
Future<void> test_suggestion_class() async {

View file

@ -102,7 +102,7 @@ Future<void> _extractDataForSite() async {
final data['table'][] //marker
}
''');
assertNoAssistAt('] //marker');
await assertNoAssistAt('] //marker');
}
Future<void> test_throw() async {

View file

@ -87,6 +87,6 @@ class SdkNoDataFileTest extends DataDrivenFixProcessorTest {
await resolveTestCode('''
var x = '';
''');
assertNoExceptions();
await assertNoExceptions();
}
}

View file

@ -67,7 +67,7 @@ void foo() {
} catch 2;
}
''');
assertNoExceptions();
await assertNoExceptions();
}
Future<void> test_singleCatch_finally_newLine() async {

View file

@ -572,11 +572,11 @@ class Server {
// stdout.writeln('Launching $serverPath');
// stdout.writeln('$dartBinary ${arguments.join(' ')}');
_process = await Process.start(dartBinary, arguments);
_process!.exitCode.then((int code) {
unawaited(_process!.exitCode.then((int code) {
if (code != 0) {
throw StateError('Server terminated with exit code $code');
}
});
}));
_listenToOutput();
var completer = Completer<void>();
_serverConnectedCompleter = completer;

View file

@ -38,7 +38,8 @@ Future<void> main(List<String> args) async {
var options = CompletionMetricsOptions(result);
var stopwatch = Stopwatch()..start();
var client = _AnalysisServerClient(Directory(_sdk.sdkPath), targets);
_CompletionClientMetricsComputer(rootPath, options, client).computeMetrics();
await _CompletionClientMetricsComputer(rootPath, options, client)
.computeMetrics();
stopwatch.stop();
var duration = Duration(milliseconds: stopwatch.elapsedMilliseconds);
@ -289,7 +290,7 @@ class _AnalysisServerClient {
_process = process;
_shutdownResponseReceived = false;
// This callback hookup can't throw.
process.exitCode.whenComplete(() {
unawaited(process.exitCode.whenComplete(() {
_process = null;
if (!_shutdownResponseReceived) {
@ -312,7 +313,7 @@ class _AnalysisServerClient {
_onCrash.complete();
}
});
}));
final errorStream = process.stderr
.transform<String>(utf8.decoder)
@ -326,7 +327,7 @@ class _AnalysisServerClient {
_streamController('server.error').stream.listen(_handleServerError);
_sendCommand('server.setSubscriptions', params: <String, dynamic>{
await _sendCommand('server.setSubscriptions', params: <String, dynamic>{
'subscriptions': <String>['STATUS'],
});