Skip to content

Commit

Permalink
Add extension on Completer to simplify code.
Browse files Browse the repository at this point in the history
Change-Id: Ida74cf78f5cedf2c4b3c806c7aaef92fa86f6d61
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397960
Commit-Queue: Keerti Parthasarathy <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
keertip authored and Commit Queue committed Dec 2, 2024
1 parent 05696d5 commit 2a29052
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,7 @@ class LspAnalysisServer extends AnalysisServer {
} else {
showErrorMessageToUser('Unknown message type');
}
if (completer != null && !completer.isCompleted) {
completer.complete();
}
completer?.setComplete();
} on InconsistentAnalysisException {
sendErrorResponse(
message,
Expand All @@ -572,9 +570,7 @@ class LspAnalysisServer extends AnalysisServer {
message: 'Document was modified before operation completed',
),
);
if (completer != null && !completer.isCompleted) {
completer.complete();
}
completer?.setComplete();
} catch (error, stackTrace) {
var errorMessage =
message is ResponseMessage
Expand All @@ -592,9 +588,7 @@ class LspAnalysisServer extends AnalysisServer {
),
);
logException(errorMessage, error, stackTrace);
if (completer != null && !completer.isCompleted) {
completer.complete();
}
completer?.setComplete();
}
}, socketError);
}
Expand Down Expand Up @@ -1395,3 +1389,12 @@ class LspServerContextManagerCallbacks
);
}
}

extension on Completer<void> {
void setComplete() {
if (isCompleted) {
return;
}
complete();
}
}

0 comments on commit 2a29052

Please sign in to comment.