Skip to content

Commit f270e45

Browse files
committed
fix: delay request if process not ready yet
1 parent cea1079 commit f270e45

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/custom_lint/lib/src/v2/custom_lint_analyzer_plugin.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class CustomLintServer {
122122
BehaviorSubject<SocketCustomLintServerToClientChannel?>();
123123
final _contextRoots = BehaviorSubject<AnalysisSetContextRootsParams>();
124124
final _runner = PendingOperation();
125+
final _delayedRequest = <Request>[];
125126

126127
/// A shorthand for accessing the current list of context roots.
127128
Future<List<ContextRoot>?> get _allContextRoots {
@@ -186,7 +187,10 @@ class CustomLintServer {
186187
orElse: () async {
187188
return _runner.run(() async {
188189
final clientChannel = await _clientChannel.safeFirst;
189-
if (clientChannel == null) return null;
190+
if (clientChannel == null || !clientChannel.initialed) {
191+
_delayedRequest.add(request);
192+
return null;
193+
}
190194

191195
final response =
192196
await clientChannel.sendAnalyzerPluginRequest(request);
@@ -291,6 +295,7 @@ class CustomLintServer {
291295
return _closeFuture = Future(() async {
292296
// Cancel pending operations
293297
await _contextRoots.close();
298+
_delayedRequest.clear();
294299

295300
// Flushes logs before stopping server.
296301
await _runner.wait();
@@ -396,6 +401,14 @@ class CustomLintServer {
396401
await clientChannel.init(
397402
debug: configs.any((e) => e != null && e.debug),
398403
);
404+
_sendDelayedRequest();
405+
}
406+
407+
void _sendDelayedRequest() {
408+
for (final request in _delayedRequest) {
409+
unawaited(_handleRequest(request));
410+
}
411+
_delayedRequest.clear();
399412
}
400413

401414
Future<void> _handleEvent(CustomLintEvent event) => _runner.run(() async {

packages/custom_lint/lib/src/v2/server_to_client_channel.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ class SocketCustomLintServerToClientChannel {
8181
final CustomLintWorkspace _workspace;
8282

8383
AnalysisSetContextRootsParams _contextRoots;
84+
bool _initialed = false;
85+
86+
/// Initial state
87+
///
88+
/// Returns `true` if requested `analysis.setContextRoots`
89+
bool get initialed => _initialed;
8490

8591
late final Stream<CustomLintMessage> _messages = _channel.messages
8692
.map((e) => e! as Map<String, Object?>)
@@ -127,6 +133,7 @@ class SocketCustomLintServerToClientChannel {
127133
sendAnalyzerPluginRequest(_version.toRequest(const Uuid().v4())),
128134
sendAnalyzerPluginRequest(_contextRoots.toRequest(const Uuid().v4())),
129135
]);
136+
_initialed = true;
130137
}
131138

132139
/// Updates the context roots on the client

0 commit comments

Comments
 (0)