Skip to content

Fix blocking issues related to flutter #1501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,28 @@ class DartDoc {
path.normalize(origin),
referredFrom: source);
_onCheckProgress.add(pathToCheck);
// Remove so that we properly count that the file doesn't exist for
// the orphan check.
visited.remove(fullPath);
return null;
}
visited.add(fullPath);
Iterable<String> stringLinks = stringLinksAndHref.item1;
String baseHref = stringLinksAndHref.item2;

// Prevent extremely large stacks by storing the paths we are using
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kk, good to document this (why we're using this algorithm)

// here instead -- occasionally, very large jobs have overflowed
// the stack without this.
// (newPathToCheck, newFullPath)
Set<Tuple2<String, String>> toVisit = new Set();

for (String href in stringLinks) {
if (!href.startsWith('http') && !href.contains('#')) {
Uri uri;
try {
uri = Uri.parse(href);
} catch (FormatError) {}

if (uri == null || !uri.hasAuthority && !uri.hasFragment) {
var full;
if (baseHref != null) {
full = '${path.dirname(pathToCheck)}/$baseHref/$href';
Expand All @@ -384,11 +398,15 @@ class DartDoc {
String newFullPath = path.joinAll([origin, newPathToCheck]);
newFullPath = path.normalize(newFullPath);
if (!visited.contains(newFullPath)) {
_doCheck(package, origin, visited, newPathToCheck, pathToCheck,
newFullPath);
toVisit.add(new Tuple2(newPathToCheck, newFullPath));
visited.add(newFullPath);
}
}
}
for (Tuple2 visitPaths in toVisit) {
_doCheck(package, origin, visited, visitPaths.item1, pathToCheck,
visitPaths.item2);
}
_onCheckProgress.add(pathToCheck);
}

Expand Down
29 changes: 19 additions & 10 deletions lib/src/markdown_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ MatchingLinkResult _getMatchingLinkElement(

// Try expensive not-scoped lookup.
if (refElement == null) {
refElement = _findRefElementInLibrary(codeRef, element, commentRefs);
Class preferredClass = _getPreferredClass(element);
refElement =
_findRefElementInLibrary(codeRef, element, commentRefs, preferredClass);
}

// This is faster but does not take canonicalization into account; try
Expand Down Expand Up @@ -281,7 +283,7 @@ MatchingLinkResult _getMatchingLinkElement(
if (searchElement is Member)
searchElement = Package.getBasestElement(refElement);

Class preferredClass = _getPreferredClass(element);
final Class preferredClass = _getPreferredClass(element);
ModelElement refModelElement = element.package.findCanonicalModelElementFor(
searchElement,
preferredClass: preferredClass);
Expand Down Expand Up @@ -357,6 +359,8 @@ bool _ConsiderIfConstructor(String codeRef, ModelElement modelElement) {
Constructor aConstructor = modelElement;
List<String> codeRefParts = codeRef.split('.');
if (codeRefParts.length > 1) {
// Pick the last two parts, in case a specific library was part of the
// codeRef.
if (codeRefParts[codeRefParts.length - 1] ==
codeRefParts[codeRefParts.length - 2]) {
// Foobar.Foobar -- assume they really do mean the constructor for this class.
Expand All @@ -380,8 +384,8 @@ Map<String, Set<ModelElement>> _findRefElementCache;
// TODO(jcollins-g): Subcomponents of this function shouldn't be adding nulls to results, strip the
// removes out that are gratuitous and debug the individual pieces.
// TODO(jcollins-g): A complex package winds up spending a lot of cycles in here. Optimize.
Element _findRefElementInLibrary(
String codeRef, ModelElement element, List<CommentReference> commentRefs) {
Element _findRefElementInLibrary(String codeRef, ModelElement element,
List<CommentReference> commentRefs, Class preferredClass) {
assert(element != null);
assert(element.package.allLibrariesAdded);

Expand All @@ -394,21 +398,24 @@ Element _findRefElementInLibrary(
// This might be an operator. Strip the operator prefix and try again.
if (results.isEmpty && codeRef.startsWith('operator')) {
String newCodeRef = codeRef.replaceFirst('operator', '');
return _findRefElementInLibrary(newCodeRef, element, commentRefs);
return _findRefElementInLibrary(
newCodeRef, element, commentRefs, preferredClass);
}

results.remove(null);
// Oh, and someone might have some type parameters or other garbage.
if (results.isEmpty && codeRef.contains(trailingIgnoreStuff)) {
String newCodeRef = codeRef.replaceFirst(trailingIgnoreStuff, '');
return _findRefElementInLibrary(newCodeRef, element, commentRefs);
return _findRefElementInLibrary(
newCodeRef, element, commentRefs, preferredClass);
}

results.remove(null);
// Oh, and someone might have thrown on a 'const' or 'final' in front.
if (results.isEmpty && codeRef.contains(leadingIgnoreStuff)) {
String newCodeRef = codeRef.replaceFirst(leadingIgnoreStuff, '');
return _findRefElementInLibrary(newCodeRef, element, commentRefs);
return _findRefElementInLibrary(
newCodeRef, element, commentRefs, preferredClass);
}

// Maybe this ModelElement has parameters, and this is one of them.
Expand All @@ -422,7 +429,7 @@ Element _findRefElementInLibrary(
if (results.isEmpty) {
// Maybe this is local to a class.
// TODO(jcollins-g): tryClasses is a strict subset of the superclass chain. Optimize.
List<Class> tryClasses = [_getPreferredClass(element)];
List<Class> tryClasses = [preferredClass];
Class realClass = tryClasses.first;
if (element is Inheritable) {
ModelElement overriddenElement = element.overriddenElement;
Expand Down Expand Up @@ -482,7 +489,8 @@ Element _findRefElementInLibrary(
_findRefElementCache.containsKey(codeRefChomped)) {
for (final modelElement in _findRefElementCache[codeRefChomped]) {
if (!_ConsiderIfConstructor(codeRef, modelElement)) continue;
results.add(package.findCanonicalModelElementFor(modelElement.element));
results.add(package.findCanonicalModelElementFor(modelElement.element,
preferredClass: preferredClass));
}
}
results.remove(null);
Expand All @@ -492,7 +500,8 @@ Element _findRefElementInLibrary(
for (final modelElement in library.allModelElements) {
if (!_ConsiderIfConstructor(codeRef, modelElement)) continue;
if (codeRefChomped == modelElement.fullyQualifiedNameWithoutLibrary) {
results.add(package.findCanonicalModelElementFor(modelElement.element));
results.add(package.findCanonicalModelElementFor(modelElement.element,
preferredClass: preferredClass));
}
}
}
Expand Down
Loading