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

Unified Diff: lib/src/debug.dart

Issue 1255643002: New, simpler and faster line splitter. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Optimize nesting. Reformat. Created 5 years, 5 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 | « lib/src/chunk_builder.dart ('k') | lib/src/line_prefix.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/debug.dart
diff --git a/lib/src/debug.dart b/lib/src/debug.dart
index b175f79ee120a9cf3e1905fe75149494d864151f..08c18f2b55d4d7bbff962e25e59a80231aa003b7 100644
--- a/lib/src/debug.dart
+++ b/lib/src/debug.dart
@@ -8,8 +8,8 @@ library dart_style.src.debug;
import 'dart:math' as math;
import 'chunk.dart';
-import 'line_prefix.dart';
-import 'line_splitter.dart';
+import 'rule/rule.dart';
+import 'rule_set.dart';
/// Set this to `true` to turn on diagnostic output while building chunks.
bool traceChunkBuilder = false;
@@ -84,6 +84,11 @@ void dumpChunks(int start, List<Chunk> chunks) {
spans = spans.toList();
+ var rules = chunks
+ .map((chunk) => chunk.rule)
+ .where((rule) => rule != null && rule is! HardSplitRule)
+ .toSet();
+
var rows = [];
addChunk(chunk, prefix, index) {
@@ -113,8 +118,8 @@ void dumpChunks(int start, List<Chunk> chunks) {
if (chunk.rule != null) {
row.add(chunk.isHardSplit ? "" : chunk.rule.toString());
- writeIf(chunk.rule.outerRules.isNotEmpty,
- () => "-> ${chunk.rule.outerRules.join(" ")}");
+ var outerRules = chunk.rule.outerRules.toSet().intersection(rules);
+ writeIf(outerRules.isNotEmpty, () => "-> ${outerRules.join(" ")}");
} else {
row.add("(no rule)");
@@ -171,15 +176,24 @@ void dumpChunks(int start, List<Chunk> chunks) {
///
/// It will determine how best to split it into multiple lines of output and
/// return a single string that may contain one or more newline characters.
-void dumpLines(List<Chunk> chunks, LinePrefix prefix, SplitSet splits) {
+void dumpLines(List<Chunk> chunks, int firstLineIndent, SplitSet splits) {
var buffer = new StringBuffer();
- // TODO(rnystrom): Handle block chunks here.
-
writeIndent(indent) => buffer.write(gray("| " * (indent ~/ 2)));
- writeIndent(prefix.column);
- for (var i = prefix.length; i < chunks.length - 1; i++) {
+ writeChunksUnsplit(List<Chunk> chunks) {
+ for (var chunk in chunks) {
+ buffer.write(chunk.text);
+ if (chunk.spaceWhenUnsplit) buffer.write(" ");
+
+ // Recurse into the block.
+ writeChunksUnsplit(chunk.blockChunks);
+ }
+ }
+
+ writeIndent(firstLineIndent);
+
+ for (var i = 0; i < chunks.length - 1; i++) {
var chunk = chunks[i];
buffer.write(chunk.text);
@@ -189,6 +203,8 @@ void dumpLines(List<Chunk> chunks, LinePrefix prefix, SplitSet splits) {
writeIndent(splits.getColumn(i));
}
} else {
+ writeChunksUnsplit(chunk.blockChunks);
+
if (chunk.spaceWhenUnsplit) buffer.write(" ");
}
}
« no previous file with comments | « lib/src/chunk_builder.dart ('k') | lib/src/line_prefix.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698