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

Unified Diff: lib/src/utils.dart

Issue 973433003: Initial cut for a development server (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 10 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/testing.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/utils.dart
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 09bc4300a810728e1606bcdf6d4e5c65349b3409..20183fcdad4f8fda358536d10dae848490d88648 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -14,12 +14,15 @@ import 'package:analyzer/src/generated/ast.dart'
ExportDirective,
PartDirective,
CompilationUnit,
- Identifier;
+ Identifier,
+ AnnotatedNode,
+ AstNode;
import 'package:analyzer/src/generated/engine.dart'
show ParseDartTask, AnalysisContext;
import 'package:analyzer/src/generated/source.dart' show Source;
import 'package:analyzer/src/generated/element.dart';
import 'package:analyzer/analyzer.dart' show parseDirectives;
+import 'package:source_span/source_span.dart';
bool isDartPrivateLibrary(LibraryElement library) {
var uri = library.source.uri;
@@ -232,3 +235,24 @@ class OutWriter {
new File(_path).writeAsStringSync('$_sb');
}
}
+
+SourceLocation locationForOffset(CompilationUnit unit, Uri uri, int offset) {
+ var lineInfo = unit.lineInfo.getLocation(offset);
+ return new SourceLocation(offset,
+ sourceUrl: uri,
+ line: lineInfo.lineNumber - 1,
+ column: lineInfo.columnNumber - 1);
+}
+
+// TODO(sigmund): change to show the span from the beginning of the line (#73)
+SourceSpan spanForNode(CompilationUnit unit, Source source, AstNode node) {
+ var currentToken = node is AnnotatedNode
+ ? node.firstTokenAfterCommentAndMetadata
+ : node.beginToken;
+ var begin = currentToken.offset;
+ var end = node.end;
+ var text = source.contents.data.substring(begin, end);
+ var uri = source.uri;
+ return new SourceSpan(locationForOffset(unit, uri, begin),
+ locationForOffset(unit, uri, end), '$text');
+}
« no previous file with comments | « lib/src/testing.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698