precacheLocalDocs method

Iterable<Future<void>> precacheLocalDocs()

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


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)) {
        yield d.precacheLocalDocs();
        // TopLevelVariables get their documentation from getters and setters,
        // so should be precached if either has a template.
        if (m is TopLevelVariable && !precachedElements.contains(m)) {
          yield m.precacheLocalDocs();

  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
                .isCanonical // The enclosingElement won't need a oneLineDoc from this
        ) {
    yield* precacheOneElement(m);
  // Now wait for any of the tasks still running to complete.