Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: dart/site/try/src/interaction_manager.dart

Issue 340343006: Send console messages through interaction manager. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Mark comment as proper TODO. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/site/try/src/compilation.dart ('k') | dart/site/try/src/ui.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/site/try/src/interaction_manager.dart
diff --git a/dart/site/try/src/interaction_manager.dart b/dart/site/try/src/interaction_manager.dart
index 7f9e44c3f1ba633f8139b7ecab78abf3c0a27b6a..898f752bd5bd616ee24cfbd0472590d2471b155e 100644
--- a/dart/site/try/src/interaction_manager.dart
+++ b/dart/site/try/src/interaction_manager.dart
@@ -80,12 +80,14 @@ const String TRY_DART_NEW_DEFECT =
'https://code.google.com/p/dart/issues/entry'
'?template=Try+Dart+Internal+Error';
-const Duration HEARTBEAT_INTERVAL = const Duration(milliseconds: 500);
+const Duration HEARTBEAT_INTERVAL = const Duration(milliseconds: 50);
Johnni Winther 2014/06/23 14:50:01 Add comments on these constants.
ahe 2014/06/23 15:15:54 Done.
const Duration SAVE_INTERVAL = const Duration(seconds: 5);
const Duration COMPILE_INTERVAL = const Duration(seconds: 1);
+const Duration SLOW_COMPILE = const Duration(seconds: 1);
+
/**
* UI interaction manager for the entire application.
*/
@@ -136,13 +138,20 @@ abstract class InteractionManager {
void onHeartbeat(Timer timer);
/// Called by [:window.onMessage.listen:].
- void onMessage(MessageEvent event);
+ void onWindowMessage(MessageEvent event);
+
+ void onCompilationFailed();
void onCompilationDone();
/// Called when a compilation is starting, but just before sending the
/// initiating message to the compiler isolate.
void compilationStarting();
+
+ // TODO(ahe): Remove this from InteractionManager, but not from InitialState.
+ void consolePrintLine(line);
+
+ void verboseCompilerMessage(String message);
}
/**
@@ -157,10 +166,15 @@ class InteractionContext extends InteractionManager {
final Queue<CompilationUnit> unitsToSave = new Queue<CompilationUnit>();
+ /// Tracks time since last modification of a "project" file.
final Stopwatch saveTimer = new Stopwatch();
+ /// Tracks time since last modification.
final Stopwatch compileTimer = new Stopwatch();
+ /// Tracks elapsed time of current compilation.
+ final Stopwatch elapsedCompilationTime = new Stopwatch();
+
CompilationUnit currentCompilationUnit =
// TODO(ahe): Don't use a fake unit.
new CompilationUnit('fake', '');
@@ -169,6 +183,12 @@ class InteractionContext extends InteractionManager {
Completer<String> completeSaveOperation;
+ bool shouldClearConsole = false;
+
+ Element compilerConsole;
+
+ bool isFirstCompile = true;
+
final Set<AnchorElement> oldDiagnostics = new Set<AnchorElement>();
InteractionContext()
@@ -229,11 +249,19 @@ class InteractionContext extends InteractionManager {
void onHeartbeat(Timer timer) => state.onHeartbeat(timer);
- void onMessage(MessageEvent event) => state.onMessage(event);
+ void onWindowMessage(MessageEvent event) => state.onWindowMessage(event);
+
+ void onCompilationFailed() => state.onCompilationFailed();
void onCompilationDone() => state.onCompilationDone();
void compilationStarting() => state.compilationStarting();
+
+ void consolePrintLine(line) => state.consolePrintLine(line);
+
+ void verboseCompilerMessage(String message) {
+ return state.verboseCompilerMessage(message);
+ }
}
abstract class InteractionState implements InteractionManager {
@@ -526,6 +554,12 @@ class InitialState extends InteractionState {
..reset();
}
}
+
+ if (context.elapsedCompilationTime.elapsed > SLOW_COMPILE) {
+ if (context.compilerConsole.parent == null) {
+ outputDiv.append(context.compilerConsole);
+ }
+ }
}
void saveUnits() {
@@ -554,7 +588,7 @@ class InitialState extends InteractionState {
setupCompleter();
}
- void onMessage(MessageEvent event) {
+ void onWindowMessage(MessageEvent event) {
if (event.source is! WindowBase || event.source == window) {
return onBadMessage(event);
}
@@ -601,11 +635,33 @@ class InitialState extends InteractionState {
..groupEnd();
}
- void consolePrintLine(data) {
- outputDiv.appendText('$data\n');
+ void consolePrintLine(line) {
+ if (context.shouldClearConsole) {
+ context.shouldClearConsole = false;
+ outputDiv.nodes.clear();
+ }
+ if (window.parent != window) {
+ // Test support.
+ // TODO(ahe): Use '/' instead of '*' when Firefox is upgraded to version
+ // 30 across build bots. Support for '/' was added in version 29, and we
+ // support the two most recent versions.
+ window.parent.postMessage('$line\n', '*');
+ }
+ outputDiv.appendText('$line\n');
+ }
+
+ void onCompilationFailed() {
}
void onCompilationDone() {
+ context.isFirstCompile = false;
+ context.elapsedCompilationTime.stop();
+ Duration compilationDuration = context.elapsedCompilationTime.elapsed;
+ context.elapsedCompilationTime.reset();
+ print('Compilation took $compilationDuration.');
+ if (context.compilerConsole.parent != null) {
+ context.compilerConsole.remove();
+ }
for (AnchorElement diagnostic in context.oldDiagnostics) {
if (diagnostic.parent != null) {
// Problem fixed, remove the diagnostic.
@@ -617,10 +673,37 @@ class InitialState extends InteractionState {
}
void compilationStarting() {
+ var progress = new SpanElement()
+ ..appendHtml('<i class="icon-spinner icon-spin"></i>')
+ ..appendText(' Compiling Dart program.');
+ if (settings.verboseCompiler) {
+ progress.appendText('..');
+ }
+ context.compilerConsole = new SpanElement()
+ ..append(progress)
+ ..appendText('\n');
+ context.shouldClearConsole = true;
+ context.elapsedCompilationTime
+ ..start()
+ ..reset();
+ if (context.isFirstCompile) {
+ outputDiv.append(context.compilerConsole);
+ }
context.oldDiagnostics
..clear()
..addAll(mainEditorPane.querySelectorAll('a.diagnostic'));
}
+
+ void verboseCompilerMessage(String message) {
+ if (settings.verboseCompiler) {
+ context.compilerConsole.appendText('$message\n');
+ } else {
+ if (isCompilerStageMarker(message)) {
+ Element progress = context.compilerConsole.firstChild;
+ progress.appendText('.');
+ }
+ }
+ }
}
Future<String> getString(uri) {
@@ -1070,3 +1153,14 @@ void removeCodeCompletion() {
element.remove();
}
}
+
+bool isCompilerStageMarker(String message) {
+ return
+ message.startsWith('Package root is ') ||
+ message.startsWith('Compiling ') ||
+ message == "Resolving..." ||
+ message.startsWith('Resolved ') ||
+ message == "Inferring types..." ||
+ message == "Compiling..." ||
+ message.startsWith('Compiled ');
+}
« no previous file with comments | « dart/site/try/src/compilation.dart ('k') | dart/site/try/src/ui.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698