File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ import 'package:analyzer/dart/ast/ast.dart';
66import 'package:analyzer/dart/element/element.dart' ;
77import 'package:analyzer/file_system/file_system.dart' ;
88import 'package:dartdoc/src/comment_references/parser.dart' ;
9- import 'package:dartdoc/src/model_utils.dart' ;
109
1110abstract class ModelCommentReference {
1211 /// Does the structure of the reference itself imply a possible default
@@ -70,9 +69,15 @@ class _ModelCommentReferenceImpl implements ModelCommentReference {
7069 /// [CommentReference] .
7170 static String _referenceText (
7271 CommentReference ref, ResourceProvider resourceProvider) {
73- var contents = getFileContentsFor (
74- (ref.root as CompilationUnit ).declaredElement, resourceProvider);
75- return contents.substring (ref.offset, ref.end);
72+ var token = (ref.parent as Comment )
73+ .tokens
74+ .firstWhere ((t) => t.offset <= ref.offset && t.end >= ref.end);
75+ // This is a little sketchy, but works since comments happen to be a token
76+ // that is fully preserved in its string representation.
77+ // TODO(jcollins-g): replace unparsing in general with lower level changes.
78+ return token
79+ .toString ()
80+ .substring (ref.offset - token.offset, ref.end - token.offset);
7681 }
7782
7883 List <CommentReferenceNode > _parsed;
Original file line number Diff line number Diff line change @@ -96,6 +96,12 @@ Iterable<Class> findCanonicalFor(Iterable<Class> classes) {
9696 c.packageGraph.findCanonicalModelElementFor (c.element) as Class ?? c);
9797}
9898
99+ /// Uses direct file access to get the contents of a file. Cached.
100+ ///
101+ /// Direct reading of source code via a [PhysicalResourceProvider] is not
102+ /// allowed in some environments, so avoid using this.
103+ // TODO(jcollins-g): consider deprecating this and the `--include-source`
104+ // feature that uses it now that source code linking is possible.
99105String getFileContentsFor (Element e, ResourceProvider resourceProvider) {
100106 var location = e.source.fullName;
101107 if (! _fileContents.containsKey (location)) {
You can’t perform that action at this time.
0 commit comments