Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## NEXT

- fix: Improved reload handling

## 1.0.14

- feat: Allow overriding client environment with Dart define
Expand Down
26 changes: 11 additions & 15 deletions apps/cli/lib/src/compiler/api/local_api_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:celest_cli/src/utils/error.dart';
import 'package:celest_cli/src/utils/json.dart';
import 'package:celest_cli/src/utils/process.dart';
import 'package:celest_cli/src/utils/run.dart';
import 'package:collection/collection.dart';
import 'package:logging/logging.dart';
import 'package:meta/meta.dart';
import 'package:vm_service/vm_service.dart';
Expand Down Expand Up @@ -39,7 +38,6 @@ final class LocalApiRunner {
final FrontendServerClient _client;
final Process _localApiProcess;
VmService? _vmService;
late final String _vmIsolateId;

/// The WebSocket URI of the running Celest server.
String get wsUri => _vmService!.wsUri!;
Expand All @@ -53,7 +51,6 @@ final class LocalApiRunner {
required String environmentId,
required Map<String, String> configValues,
required bool verbose,
List<String> additionalSources = const [],
int? port,
@visibleForTesting Duration? vmServiceTimeout,
@visibleForTesting StringSink? stdoutPipe,
Expand Down Expand Up @@ -269,7 +266,7 @@ final class LocalApiRunner {
);

/// Waits for the main Isolate to be available, resume it, then return its ID.
static Future<String> _waitForIsolatesAndResume(VmService vmService) async {
static Future<void> _waitForIsolatesAndResume(VmService vmService) async {
var vm = await vmService.getVM();
var isolates = vm.isolates;
final stopwatch = Stopwatch()..start();
Expand All @@ -288,14 +285,6 @@ final class LocalApiRunner {
'VM started in ${stopwatch.elapsedMilliseconds}ms. '
'Isolates: $isolates',
);
var isolateRef = isolates.firstWhereOrNull(
(isolate) => isolate.isSystemIsolate ?? false,
);
isolateRef ??= isolates.firstOrNull;
if (isolateRef == null) {
throw StateError('Could not determine main isolate ID.');
}
return isolateRef.id!;
}

// Doesn't seem that we need pause-on-start anymore, but keeping code around
Expand Down Expand Up @@ -447,7 +436,7 @@ final class LocalApiRunner {
});
await _vmService!.streamListen(EventStreams.kLogging);

_vmIsolateId = await _waitForIsolatesAndResume(_vmService!);
await _waitForIsolatesAndResume(_vmService!);

await Future.any([
serverStartedCompleter.future,
Expand Down Expand Up @@ -480,7 +469,11 @@ final class LocalApiRunner {
]);
final dillOutput = _client.expectOutput(result);
_logger.fine('Hot reloading local API with entrypoint: $dillOutput');
await _vmService!.reloadSources(_vmIsolateId, rootLibUri: dillOutput);

final isolates = await _vmService!.getVM().then((vm) => vm.isolates!);
for (final isolate in isolates) {
await _vmService!.reloadSources(isolate.id!, rootLibUri: dillOutput);
}
}

// Copied from `package:flutter_tools/src/run_hot.dart`
Expand Down Expand Up @@ -546,9 +539,10 @@ final class LocalApiRunner {
}

final class CompilationException implements Exception {
CompilationException(this.message);
CompilationException(this.message, [this.compilerOutput = const []]);

final String message;
final List<String> compilerOutput;

@override
String toString() => message;
Expand All @@ -563,8 +557,10 @@ extension on FrontendServerClient {
switch (result) {
case CompileResult(errorCount: > 0):
_logger.finest('Error compiling local API', result.debugResult);
accept(); // Always accept so we can call `compile` again.
throw CompilationException(
'Error compiling local API: ${result.debugResult}',
result.compilerOutputLines.toList(),
);
case CompileResult(:final dillOutput?):
accept();
Expand Down
8 changes: 6 additions & 2 deletions apps/cli/lib/src/frontend/celest_frontend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,14 @@ final class CelestFrontend with CloudRepository {
)).port,
);
} on CompilationException catch (e, st) {
currentProgress!.fail();
cliLogger.err(
'Project has errors. Please fix them and save the '
'corresponding files.',
);
for (final compilerLine in e.compilerOutput) {
cliLogger.err(compilerLine);
}
performance.captureError(e, stackTrace: st);
break;
}
Expand Down Expand Up @@ -453,8 +457,8 @@ final class CelestFrontend with CloudRepository {
// there is one.
final exitCode = await Future.any<int?>([
_nextChangeSet().then((_) => null),
if (childProcess case final childProcess?)
Future.value(childProcess.exitCode),
if (childProcess case final childProcess? when childProcess.isStarted)
childProcess.exitCode,
]);
if (exitCode != null) {
return exitCode;
Expand Down
Loading