From c9bcf1074e0805cb9d1b40e7e869fc5aae9110c8 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Mon, 13 Jun 2016 12:20:03 -0700 Subject: [PATCH] Analyzer was confused when you deleted files (#4528) Also, make it clear the screen between results so it's more obvious what's going on when you have new results (especially when you have fixed everything). --- .../flutter_tools/lib/src/base/logger.dart | 22 +++-- .../lib/src/commands/analyze.dart | 80 ++++++++++--------- .../lib/src/commands/daemon.dart | 4 +- .../flutter_tools/lib/src/commands/test.dart | 3 +- packages/flutter_tools/lib/src/globals.dart | 4 +- .../src/runner/flutter_command_runner.dart | 11 +++ 6 files changed, 78 insertions(+), 46 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/logger.dart b/packages/flutter_tools/lib/src/base/logger.dart index 2ba170d620..42bb2d9280 100644 --- a/packages/flutter_tools/lib/src/base/logger.dart +++ b/packages/flutter_tools/lib/src/base/logger.dart @@ -23,7 +23,7 @@ abstract class Logger { /// Display normal output of the command. This should be used for things like /// progress messages, success messages, or just normal command output. - void printStatus(String message, { bool emphasis: false }); + void printStatus(String message, { bool emphasis: false, bool newline: true }); /// Use this for verbose tracing output. Users can turn this output on in order /// to help diagnose issues with the toolchain or with their setup. @@ -58,11 +58,14 @@ class StdoutLogger extends Logger { } @override - void printStatus(String message, { bool emphasis: false }) { + void printStatus(String message, { bool emphasis: false, bool newline: true }) { _status?.cancel(); _status = null; - print(emphasis ? terminal.writeBold(message) : message); + if (newline) + stdout.writeln(emphasis ? terminal.writeBold(message) : message); + else + stdout.write(emphasis ? terminal.writeBold(message) : message); } @override @@ -102,7 +105,12 @@ class BufferLogger extends Logger { void printError(String message, [StackTrace stackTrace]) => _error.writeln(message); @override - void printStatus(String message, { bool emphasis: false }) => _status.writeln(message); + void printStatus(String message, { bool emphasis: false, bool newline: true }) { + if (newline) + _status.writeln(message); + else + _status.write(message); + } @override void printTrace(String message) => _trace.writeln(message); @@ -130,7 +138,8 @@ class VerboseLogger extends Logger { } @override - void printStatus(String message, { bool emphasis: false }) { + void printStatus(String message, { bool emphasis: false, bool newline: true }) { + // TODO(ianh): We ignore newline and emphasis here. _emit(); lastMessage = new _LogMessage(_LogType.status, message); } @@ -208,11 +217,14 @@ class AnsiTerminal { static const String _bold = '\u001B[1m'; static const String _reset = '\u001B[0m'; + static const String _clear = '\u001B[2J\u001B[H'; bool supportsColor; String writeBold(String str) => supportsColor ? '$_bold$str$_reset' : str; + String clearScreen() => supportsColor ? _clear : '\n\n'; + set singleCharMode(bool value) { stdin.lineMode = !value; } diff --git a/packages/flutter_tools/lib/src/commands/analyze.dart b/packages/flutter_tools/lib/src/commands/analyze.dart index aac2f797da..6823967a0a 100644 --- a/packages/flutter_tools/lib/src/commands/analyze.dart +++ b/packages/flutter_tools/lib/src/commands/analyze.dart @@ -271,30 +271,8 @@ class AnalyzeCommand extends FlutterCommand { return collected; } - Future _analyzeWatch() async { - List directories; - - if (argResults['flutter-repo']) { - directories = runner.getRepoPackages().map((Directory dir) => dir.path).toList(); - printStatus('Analyzing Flutter repository (${directories.length} projects).'); - for (String projectPath in directories) - printTrace(' ${path.relative(projectPath)}'); - printStatus(''); - } else { - directories = [Directory.current.path]; - } - - AnalysisServer server = new AnalysisServer(dartSdkPath, directories); - server.onAnalyzing.listen((bool isAnalyzing) => _handleAnalysisStatus(server, isAnalyzing)); - server.onErrors.listen(_handleAnalysisErrors); - - await server.start(); - - int exitCode = await server.onExit; - printStatus('Analysis server exited with code $exitCode.'); - return 0; - } + String analysisTarget; bool firstAnalysis = true; Set analyzedPaths = new Set(); Map> analysisErrors = >{}; @@ -302,26 +280,54 @@ class AnalyzeCommand extends FlutterCommand { int lastErrorCount = 0; Status analysisStatus; + Future _analyzeWatch() async { + List directories; + + if (argResults['flutter-repo']) { + directories = runner.getRepoAnalysisEntryPoints().map((Directory dir) => dir.path).toList(); + analysisTarget = 'Flutter repository'; + printTrace('Analyzing Flutter repository:'); + for (String projectPath in directories) + printTrace(' ${path.relative(projectPath)}'); + } else { + directories = [Directory.current.path]; + analysisTarget = Directory.current.path; + } + + AnalysisServer server = new AnalysisServer(dartSdkPath, directories); + server.onAnalyzing.listen((bool isAnalyzing) => _handleAnalysisStatus(server, isAnalyzing)); + server.onErrors.listen(_handleAnalysisErrors); + + await server.start(); + final int exitCode = await server.onExit; + + printStatus('Analysis server exited with code $exitCode.'); + return 0; + } + void _handleAnalysisStatus(AnalysisServer server, bool isAnalyzing) { if (isAnalyzing) { analysisStatus?.cancel(); - - if (firstAnalysis) { - analysisStatus = logger.startProgress('Analyzing ${path.basename(Directory.current.path)}...'); - } else { - analysisStatus = logger.startProgress('\nAnalyzing...'); - } - + if (!firstAnalysis) + printStatus('\n'); + analysisStatus = logger.startProgress('Analyzing $analysisTarget...'); analyzedPaths.clear(); analysisTimer = new Stopwatch()..start(); } else { analysisStatus?.stop(showElapsedTime: true); analysisTimer.stop(); - // Sort and print errors. - List errors = []; - for (List fileErrors in analysisErrors.values) - errors.addAll(fileErrors); + logger.printStatus(terminal.clearScreen(), newline: false); + + // Remove errors for deleted files, sort, and print errors. + final List errors = []; + for (String path in analysisErrors.keys.toList()) { + if (FileSystemEntity.isFileSync(path)) { + errors.addAll(analysisErrors[path]); + } else { + analysisErrors.remove(path); + } + } errors.sort(); @@ -341,11 +347,11 @@ class AnalyzeCommand extends FlutterCommand { if (firstAnalysis) errorsMessage = '$issueCount ${pluralize('issue', issueCount)} found'; else if (issueDiff > 0) - errorsMessage = '$issueDiff new ${pluralize('issue', issueDiff)}, $issueCount total'; + errorsMessage = '$issueCount ${pluralize('issue', issueCount)} found ($issueDiff new)'; else if (issueDiff < 0) - errorsMessage = '${-issueDiff} ${pluralize('issue', -issueDiff)} fixed, $issueCount remaining'; + errorsMessage = '$issueCount ${pluralize('issue', issueCount)} found (${-issueDiff} fixed)'; else if (issueCount != 0) - errorsMessage = 'no new issues, $issueCount total'; + errorsMessage = '$issueCount ${pluralize('issue', issueCount)} found'; else errorsMessage = 'no issues found'; diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index cbea273b94..69d9988c28 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -536,7 +536,7 @@ class NotifyingLogger extends Logger { } @override - void printStatus(String message, { bool emphasis: false }) { + void printStatus(String message, { bool emphasis: false, bool newline: true }) { _messageController.add(new LogMessage('status', message)); } @@ -603,7 +603,7 @@ class _AppRunLogger extends Logger { } @override - void printStatus(String message, { bool emphasis: false }) { + void printStatus(String message, { bool emphasis: false, bool newline: true }) { domain?._sendAppEvent(app, 'log', { 'log': message }); } diff --git a/packages/flutter_tools/lib/src/commands/test.dart b/packages/flutter_tools/lib/src/commands/test.dart index 9ad502afe1..a247e752e4 100644 --- a/packages/flutter_tools/lib/src/commands/test.dart +++ b/packages/flutter_tools/lib/src/commands/test.dart @@ -8,6 +8,7 @@ import 'dart:io'; import 'package:path/path.dart' as path; import 'package:test/src/executable.dart' as executable; // ignore: implementation_imports +import '../base/logger.dart'; import '../dart/package_map.dart'; import '../globals.dart'; import '../runner/flutter_command.dart'; @@ -91,7 +92,7 @@ class TestCommand extends FlutterCommand { } testArgs.insert(0, '--'); - if (Platform.environment['TERM'] == 'dumb') + if (!terminal.supportsColor) testArgs.insert(0, '--no-color'); loader.installHook(); diff --git a/packages/flutter_tools/lib/src/globals.dart b/packages/flutter_tools/lib/src/globals.dart index bf1be91596..d81e93c613 100644 --- a/packages/flutter_tools/lib/src/globals.dart +++ b/packages/flutter_tools/lib/src/globals.dart @@ -25,7 +25,9 @@ void printError(String message, [StackTrace stackTrace]) => logger.printError(me /// Display normal output of the command. This should be used for things like /// progress messages, success messages, or just normal command output. -void printStatus(String message, { bool emphasis: false }) => logger.printStatus(message, emphasis: emphasis); +void printStatus(String message, { bool emphasis: false, bool newline: true }) { + logger.printStatus(message, emphasis: emphasis, newline: newline); +} /// Use this for verbose tracing output. Users can turn this output on in order /// to help diagnose issues with the toolchain or with their setup. diff --git a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart index 18a79b045f..f4b6792b9b 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart @@ -264,6 +264,17 @@ class FlutterCommandRunner extends CommandRunner { .toList(); } + /// Get the entry-points we want to analyze in the Flutter repo. + List getRepoAnalysisEntryPoints() { + String rootPath = path.absolute(Cache.flutterRoot); + return [ + // not bin, and not the root + new Directory(path.join(rootPath, 'dev')), + new Directory(path.join(rootPath, 'examples')), + new Directory(path.join(rootPath, 'packages')), + ]; + } + bool _checkFlutterCopy() { // If the current directory is contained by a flutter repo, check that it's // the same flutter that is currently running.