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

Unified Diff: lib/src/utils.dart

Issue 1141013002: Fixes #179 -- compile error if editing files during server mode (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 7 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') | test/dart_codegen/expect/core/string.dart » ('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 d9ccdac94ac96584535e041f3ee49e7f7db88319..60c6d491386c00394db6751c7bfd16fe1199a723 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -113,7 +113,8 @@ Iterable<Source> reachableSources(Source start, AnalysisContext context) {
/// Returns sources that are imported or exported in [source] (parts are
/// excluded).
Iterable<Source> _importsAndExportsOf(Source source, AnalysisContext context) {
- var unit = parseDirectives(source.contents.data, name: source.fullName);
+ var unit =
+ parseDirectives(context.getContents(source).data, name: source.fullName);
return unit.directives
.where((d) => d is ImportDirective || d is ExportDirective)
.map((d) {
@@ -291,19 +292,6 @@ SourceLocation locationForOffset(CompilationUnit unit, Uri uri, int offset) {
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');
-}
-
/// Computes a hash for the given contents.
String computeHash(String contents) {
if (contents == null || contents == '') return null;
@@ -439,3 +427,28 @@ InterfaceType findSupertype(InterfaceType type, bool match(InterfaceType t)) {
if (match(s)) return type;
return findSupertype(s, match);
}
+
+SourceSpanWithContext createSpan(
+ AnalysisContext context, CompilationUnit unit, int start, int end,
+ [Source source]) {
+ if (source == null) source = unit.element.source;
+ var content = context.getContents(source).data;
+ var startLoc = locationForOffset(unit, source.uri, start);
+ var endLoc = locationForOffset(unit, source.uri, end);
+
+ var lineStart = startLoc.offset - startLoc.column;
+ // Find the end of the line. This is not exposed directly on LineInfo, but
+ // we can find it pretty easily.
+ // TODO(jmesserly): for now we do the simple linear scan. Ideally we can get
+ // some help from the LineInfo API.
+ var lineInfo = unit.lineInfo;
+ int lineEnd = endLoc.offset;
+ int unitEnd = unit.endToken.end;
+ int lineNum = lineInfo.getLocation(lineEnd).lineNumber;
+ while (lineEnd < unitEnd &&
+ lineInfo.getLocation(++lineEnd).lineNumber == lineNum);
+
+ var text = content.substring(start, end);
+ var lineText = content.substring(lineStart, lineEnd);
+ return new SourceSpanWithContext(startLoc, endLoc, text, lineText);
+}
« no previous file with comments | « lib/src/testing.dart ('k') | test/dart_codegen/expect/core/string.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698