|
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
5 | 5 | import 'dart:async'; |
6 | | -import 'dart:io'; |
| 6 | +import 'dart:io' as io; |
7 | 7 |
|
8 | 8 | import 'package:meta/meta.dart'; |
9 | 9 | import 'package:path/path.dart' as path; |
@@ -43,45 +43,41 @@ class AnalyzeCommand extends DartdevCommand<int> { |
43 | 43 |
|
44 | 44 | // find directory from argResults.rest |
45 | 45 | var dir = argResults.rest.isEmpty |
46 | | - ? Directory.current |
47 | | - : Directory(argResults.rest.single); |
| 46 | + ? io.Directory.current |
| 47 | + : io.Directory(argResults.rest.single); |
48 | 48 | if (!dir.existsSync()) { |
49 | 49 | usageException("Directory doesn't exist: ${dir.path}"); |
50 | 50 | } |
51 | 51 |
|
52 | | - final Completer<void> analysisCompleter = Completer<void>(); |
53 | 52 | final List<AnalysisError> errors = <AnalysisError>[]; |
54 | 53 |
|
55 | 54 | var progress = log.progress('Analyzing ${path.basename(dir.path)}'); |
56 | 55 |
|
57 | 56 | final AnalysisServer server = AnalysisServer( |
58 | | - Directory(sdk.sdkPath), |
| 57 | + io.Directory(sdk.sdkPath), |
59 | 58 | [dir], |
60 | 59 | ); |
61 | 60 |
|
62 | | - StreamSubscription<bool> subscription; |
63 | | - subscription = server.onAnalyzing.listen((bool isAnalyzing) { |
64 | | - if (!isAnalyzing) { |
65 | | - analysisCompleter.complete(); |
66 | | - subscription.cancel(); |
67 | | - } |
68 | | - }); |
69 | 61 | server.onErrors.listen((FileAnalysisErrors fileErrors) { |
70 | 62 | // Record the issues found (but filter out to do comments). |
71 | 63 | errors.addAll(fileErrors.errors |
72 | 64 | .where((AnalysisError error) => error.type != 'TODO')); |
73 | 65 | }); |
74 | 66 |
|
75 | 67 | await server.start(); |
76 | | - // Completing the future in the callback can't fail. |
77 | | - //ignore: unawaited_futures |
| 68 | + |
| 69 | + bool analysisFinished = false; |
| 70 | + |
| 71 | + // ignore: unawaited_futures |
78 | 72 | server.onExit.then((int exitCode) { |
79 | | - if (!analysisCompleter.isCompleted) { |
80 | | - analysisCompleter.completeError('analysis server exited: $exitCode'); |
| 73 | + if (!analysisFinished) { |
| 74 | + io.exitCode = exitCode; |
81 | 75 | } |
82 | 76 | }); |
83 | 77 |
|
84 | | - await analysisCompleter.future; |
| 78 | + await server.analysisFinished; |
| 79 | + analysisFinished = true; |
| 80 | + |
85 | 81 | // todo (pq): consider server.shutdown() for cleaner dispose. |
86 | 82 | await server.dispose(); |
87 | 83 | progress.finish(showTiming: true); |
|
0 commit comments