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