precacheLocalDocs method

Iterable<Future<void>> precacheLocalDocs()

Generate a list of futures for any docs that actually require precaching.

Implementation

Iterable<Future<void>> precacheLocalDocs() sync* {
  // Prevent reentrancy.
  var precachedElements = <ModelElement>{};

  Iterable<Future<void>> precacheOneElement(ModelElement m) sync* {
    for (var d
        in m.documentationFrom.where((d) => d.hasDocumentationComment)) {
      if (d.needsPrecache && !precachedElements.contains(d)) {
        precachedElements.add(d);
        yield d.precacheLocalDocs();
        logProgress(d.name);
        // TopLevelVariables get their documentation from getters and setters,
        // so should be precached if either has a template.
        if (m is TopLevelVariable && !precachedElements.contains(m)) {
          precachedElements.add(m);
          yield m.precacheLocalDocs();
          logProgress(d.name);
        }
      }
    }
  }

  for (var m in allModelElements) {
    // Skip if there is a canonicalModelElement somewhere else we can run this
    // for and we won't need a one line document that is precached.
    // Not the same as allCanonicalModelElements since we need to run
    // for any ModelElement that might not have a canonical ModelElement,
    // too.
    if (m.canonicalModelElement !=
                null // A canonical element exists somewhere
            &&
            !m.isCanonical // This element is not canonical
            &&
            !m.enclosingElement
                .isCanonical // The enclosingElement won't need a oneLineDoc from this
        ) {
      continue;
    }
    yield* precacheOneElement(m);
  }
  // Now wait for any of the tasks still running to complete.
  yield config.tools.runner.wait();
}