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

Unified Diff: pkg/analyzer/lib/src/task/options.dart

Issue 1417363007: Fix to give `LineInfo` to options error spans. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
Index: pkg/analyzer/lib/src/task/options.dart
diff --git a/pkg/analyzer/lib/src/task/options.dart b/pkg/analyzer/lib/src/task/options.dart
index 80ac44f714593cafc19bd5acfeb3558165b3b79b..9f22f7f647aec59ebd23f567d3067a99073e2c09 100644
--- a/pkg/analyzer/lib/src/task/options.dart
+++ b/pkg/analyzer/lib/src/task/options.dart
@@ -48,7 +48,7 @@ class GenerateOptionsErrorsTask extends SourceBasedAnalysisTask {
'GenerateOptionsErrorsTask',
createTask,
buildInputs,
- <ResultDescriptor>[ANALYSIS_OPTIONS_ERRORS]);
+ <ResultDescriptor>[ANALYSIS_OPTIONS_ERRORS, LINE_INFO]);
final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider();
@@ -81,6 +81,7 @@ class GenerateOptionsErrorsTask extends SourceBasedAnalysisTask {
// Record outputs.
//
outputs[ANALYSIS_OPTIONS_ERRORS] = errors;
+ outputs[LINE_INFO] = _computeLineInfo(content);
}
List<AnalysisError> _validate(Map<String, YamlNode> options) =>
@@ -96,6 +97,17 @@ class GenerateOptionsErrorsTask extends SourceBasedAnalysisTask {
static GenerateOptionsErrorsTask createTask(
AnalysisContext context, AnalysisTarget target) =>
new GenerateOptionsErrorsTask(context, target);
+
+ /// Compute [LineInfo] for the given [content].
+ static LineInfo _computeLineInfo(String content) {
+ List<int> lineStarts = <int>[0];
+ for (int index = 0; index < content.length; index++) {
+ if (content.codeUnitAt(index) == 0x0A) {
Brian Wilkerson 2015/10/27 13:18:29 For Dart files we accept either CR, CR/LF, or LF a
pquitslund 2015/10/27 15:31:44 I was folllowing HTML's suit but this is not a bad
Brian Wilkerson 2015/10/27 15:59:44 We compute line info while scanning, as part of th
+ lineStarts.add(index + 1);
+ }
+ }
+ return new LineInfo(lineStarts);
+ }
}
/// Validates `linter` top-level options.

Powered by Google App Engine
This is Rietveld 408576698