Commit c9bcf107 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

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).
parent 1d5d7f4a
...@@ -23,7 +23,7 @@ abstract class Logger { ...@@ -23,7 +23,7 @@ abstract class Logger {
/// Display normal output of the command. This should be used for things like /// Display normal output of the command. This should be used for things like
/// progress messages, success messages, or just normal command output. /// 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 /// 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. /// to help diagnose issues with the toolchain or with their setup.
...@@ -58,11 +58,14 @@ class StdoutLogger extends Logger { ...@@ -58,11 +58,14 @@ class StdoutLogger extends Logger {
} }
@override @override
void printStatus(String message, { bool emphasis: false }) { void printStatus(String message, { bool emphasis: false, bool newline: true }) {
_status?.cancel(); _status?.cancel();
_status = null; _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 @override
...@@ -102,7 +105,12 @@ class BufferLogger extends Logger { ...@@ -102,7 +105,12 @@ class BufferLogger extends Logger {
void printError(String message, [StackTrace stackTrace]) => _error.writeln(message); void printError(String message, [StackTrace stackTrace]) => _error.writeln(message);
@override @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 @override
void printTrace(String message) => _trace.writeln(message); void printTrace(String message) => _trace.writeln(message);
...@@ -130,7 +138,8 @@ class VerboseLogger extends Logger { ...@@ -130,7 +138,8 @@ class VerboseLogger extends Logger {
} }
@override @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(); _emit();
lastMessage = new _LogMessage(_LogType.status, message); lastMessage = new _LogMessage(_LogType.status, message);
} }
...@@ -208,11 +217,14 @@ class AnsiTerminal { ...@@ -208,11 +217,14 @@ class AnsiTerminal {
static const String _bold = '\u001B[1m'; static const String _bold = '\u001B[1m';
static const String _reset = '\u001B[0m'; static const String _reset = '\u001B[0m';
static const String _clear = '\u001B[2J\u001B[H';
bool supportsColor; bool supportsColor;
String writeBold(String str) => supportsColor ? '$_bold$str$_reset' : str; String writeBold(String str) => supportsColor ? '$_bold$str$_reset' : str;
String clearScreen() => supportsColor ? _clear : '\n\n';
set singleCharMode(bool value) { set singleCharMode(bool value) {
stdin.lineMode = !value; stdin.lineMode = !value;
} }
......
...@@ -271,17 +271,27 @@ class AnalyzeCommand extends FlutterCommand { ...@@ -271,17 +271,27 @@ class AnalyzeCommand extends FlutterCommand {
return collected; return collected;
} }
String analysisTarget;
bool firstAnalysis = true;
Set<String> analyzedPaths = new Set<String>();
Map<String, List<AnalysisError>> analysisErrors = <String, List<AnalysisError>>{};
Stopwatch analysisTimer;
int lastErrorCount = 0;
Status analysisStatus;
Future<int> _analyzeWatch() async { Future<int> _analyzeWatch() async {
List<String> directories; List<String> directories;
if (argResults['flutter-repo']) { if (argResults['flutter-repo']) {
directories = runner.getRepoPackages().map((Directory dir) => dir.path).toList(); directories = runner.getRepoAnalysisEntryPoints().map((Directory dir) => dir.path).toList();
printStatus('Analyzing Flutter repository (${directories.length} projects).'); analysisTarget = 'Flutter repository';
printTrace('Analyzing Flutter repository:');
for (String projectPath in directories) for (String projectPath in directories)
printTrace(' ${path.relative(projectPath)}'); printTrace(' ${path.relative(projectPath)}');
printStatus('');
} else { } else {
directories = <String>[Directory.current.path]; directories = <String>[Directory.current.path];
analysisTarget = Directory.current.path;
} }
AnalysisServer server = new AnalysisServer(dartSdkPath, directories); AnalysisServer server = new AnalysisServer(dartSdkPath, directories);
...@@ -289,39 +299,35 @@ class AnalyzeCommand extends FlutterCommand { ...@@ -289,39 +299,35 @@ class AnalyzeCommand extends FlutterCommand {
server.onErrors.listen(_handleAnalysisErrors); server.onErrors.listen(_handleAnalysisErrors);
await server.start(); await server.start();
final int exitCode = await server.onExit;
int exitCode = await server.onExit;
printStatus('Analysis server exited with code $exitCode.'); printStatus('Analysis server exited with code $exitCode.');
return 0; return 0;
} }
bool firstAnalysis = true;
Set<String> analyzedPaths = new Set<String>();
Map<String, List<AnalysisError>> analysisErrors = <String, List<AnalysisError>>{};
Stopwatch analysisTimer;
int lastErrorCount = 0;
Status analysisStatus;
void _handleAnalysisStatus(AnalysisServer server, bool isAnalyzing) { void _handleAnalysisStatus(AnalysisServer server, bool isAnalyzing) {
if (isAnalyzing) { if (isAnalyzing) {
analysisStatus?.cancel(); analysisStatus?.cancel();
if (!firstAnalysis)
if (firstAnalysis) { printStatus('\n');
analysisStatus = logger.startProgress('Analyzing ${path.basename(Directory.current.path)}...'); analysisStatus = logger.startProgress('Analyzing $analysisTarget...');
} else {
analysisStatus = logger.startProgress('\nAnalyzing...');
}
analyzedPaths.clear(); analyzedPaths.clear();
analysisTimer = new Stopwatch()..start(); analysisTimer = new Stopwatch()..start();
} else { } else {
analysisStatus?.stop(showElapsedTime: true); analysisStatus?.stop(showElapsedTime: true);
analysisTimer.stop(); analysisTimer.stop();
// Sort and print errors. logger.printStatus(terminal.clearScreen(), newline: false);
List<AnalysisError> errors = <AnalysisError>[];
for (List<AnalysisError> fileErrors in analysisErrors.values) // Remove errors for deleted files, sort, and print errors.
errors.addAll(fileErrors); final List<AnalysisError> errors = <AnalysisError>[];
for (String path in analysisErrors.keys.toList()) {
if (FileSystemEntity.isFileSync(path)) {
errors.addAll(analysisErrors[path]);
} else {
analysisErrors.remove(path);
}
}
errors.sort(); errors.sort();
...@@ -341,11 +347,11 @@ class AnalyzeCommand extends FlutterCommand { ...@@ -341,11 +347,11 @@ class AnalyzeCommand extends FlutterCommand {
if (firstAnalysis) if (firstAnalysis)
errorsMessage = '$issueCount ${pluralize('issue', issueCount)} found'; errorsMessage = '$issueCount ${pluralize('issue', issueCount)} found';
else if (issueDiff > 0) else if (issueDiff > 0)
errorsMessage = '$issueDiff new ${pluralize('issue', issueDiff)}, $issueCount total'; errorsMessage = '$issueCount ${pluralize('issue', issueCount)} found ($issueDiff new)';
else if (issueDiff < 0) else if (issueDiff < 0)
errorsMessage = '${-issueDiff} ${pluralize('issue', -issueDiff)} fixed, $issueCount remaining'; errorsMessage = '$issueCount ${pluralize('issue', issueCount)} found (${-issueDiff} fixed)';
else if (issueCount != 0) else if (issueCount != 0)
errorsMessage = 'no new issues, $issueCount total'; errorsMessage = '$issueCount ${pluralize('issue', issueCount)} found';
else else
errorsMessage = 'no issues found'; errorsMessage = 'no issues found';
......
...@@ -536,7 +536,7 @@ class NotifyingLogger extends Logger { ...@@ -536,7 +536,7 @@ class NotifyingLogger extends Logger {
} }
@override @override
void printStatus(String message, { bool emphasis: false }) { void printStatus(String message, { bool emphasis: false, bool newline: true }) {
_messageController.add(new LogMessage('status', message)); _messageController.add(new LogMessage('status', message));
} }
...@@ -603,7 +603,7 @@ class _AppRunLogger extends Logger { ...@@ -603,7 +603,7 @@ class _AppRunLogger extends Logger {
} }
@override @override
void printStatus(String message, { bool emphasis: false }) { void printStatus(String message, { bool emphasis: false, bool newline: true }) {
domain?._sendAppEvent(app, 'log', <String, dynamic>{ 'log': message }); domain?._sendAppEvent(app, 'log', <String, dynamic>{ 'log': message });
} }
......
...@@ -8,6 +8,7 @@ import 'dart:io'; ...@@ -8,6 +8,7 @@ import 'dart:io';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:test/src/executable.dart' as executable; // ignore: implementation_imports import 'package:test/src/executable.dart' as executable; // ignore: implementation_imports
import '../base/logger.dart';
import '../dart/package_map.dart'; import '../dart/package_map.dart';
import '../globals.dart'; import '../globals.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
...@@ -91,7 +92,7 @@ class TestCommand extends FlutterCommand { ...@@ -91,7 +92,7 @@ class TestCommand extends FlutterCommand {
} }
testArgs.insert(0, '--'); testArgs.insert(0, '--');
if (Platform.environment['TERM'] == 'dumb') if (!terminal.supportsColor)
testArgs.insert(0, '--no-color'); testArgs.insert(0, '--no-color');
loader.installHook(); loader.installHook();
......
...@@ -25,7 +25,9 @@ void printError(String message, [StackTrace stackTrace]) => logger.printError(me ...@@ -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 /// Display normal output of the command. This should be used for things like
/// progress messages, success messages, or just normal command output. /// 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 /// 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. /// to help diagnose issues with the toolchain or with their setup.
......
...@@ -264,6 +264,17 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -264,6 +264,17 @@ class FlutterCommandRunner extends CommandRunner {
.toList(); .toList();
} }
/// Get the entry-points we want to analyze in the Flutter repo.
List<Directory> getRepoAnalysisEntryPoints() {
String rootPath = path.absolute(Cache.flutterRoot);
return <Directory>[
// 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() { bool _checkFlutterCopy() {
// If the current directory is contained by a flutter repo, check that it's // If the current directory is contained by a flutter repo, check that it's
// the same flutter that is currently running. // the same flutter that is currently running.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment