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 {
/// 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;
}
......
......@@ -271,17 +271,27 @@ class AnalyzeCommand extends FlutterCommand {
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 {
List<String> directories;
if (argResults['flutter-repo']) {
directories = runner.getRepoPackages().map((Directory dir) => dir.path).toList();
printStatus('Analyzing Flutter repository (${directories.length} projects).');
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)}');
printStatus('');
} else {
directories = <String>[Directory.current.path];
analysisTarget = Directory.current.path;
}
AnalysisServer server = new AnalysisServer(dartSdkPath, directories);
......@@ -289,39 +299,35 @@ class AnalyzeCommand extends FlutterCommand {
server.onErrors.listen(_handleAnalysisErrors);
await server.start();
final int exitCode = await server.onExit;
int exitCode = await server.onExit;
printStatus('Analysis server exited with code $exitCode.');
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) {
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<AnalysisError> errors = <AnalysisError>[];
for (List<AnalysisError> fileErrors in analysisErrors.values)
errors.addAll(fileErrors);
logger.printStatus(terminal.clearScreen(), newline: false);
// Remove errors for deleted files, sort, and print errors.
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();
......@@ -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';
......
......@@ -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', <String, dynamic>{ 'log': message });
}
......
......@@ -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();
......
......@@ -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.
......
......@@ -264,6 +264,17 @@ class FlutterCommandRunner extends CommandRunner {
.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() {
// If the current directory is contained by a flutter repo, check that it's
// 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