Gracefully handle a race condition in code completion (issue 40008)

Change-Id: I4dcef63210e2318594fe15484e00b72ca126e49a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130760
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Brian Wilkerson 2020-01-08 19:03:55 +00:00 committed by commit-bot@chromium.org
parent ac4b43f0a8
commit 5b6bdaba64

View file

@ -89,9 +89,17 @@ class CompletionRanking {
return await receivePort.first; return await receivePort.first;
} }
/// Makes a next-token prediction starting at the completion request cursor /// Return a next-token prediction starting at the completion request cursor
/// and walking back to find previous input tokens. /// and walking back to find previous input tokens, or `null` if the
/// prediction isolates are not running.
Future<Map<String, double>> predict(DartCompletionRequest request) async { Future<Map<String, double>> predict(DartCompletionRequest request) async {
if (_writes == null || _writes.isEmpty) {
// The field `_writes` is initialized in `start`, but the code that
// invokes `start` doesn't wait for it complete. That means that it's
// possible for this method to be invoked before `_writes` is initialized.
// In those cases we return `null`
return null;
}
final query = constructQuery(request, _LOOKBACK); final query = constructQuery(request, _LOOKBACK);
if (query == null) { if (query == null) {
return Future.value(); return Future.value();