void generateDoc()

in lib/documentation.dart [38:93]


  void generateDoc(List<DivElement> docElements) {
    if (docElements.isEmpty) {
      return;
    }

    if (!_sourceProvider.isFocused) {
      _previousDocHash = null;
      for (final docPanel in docElements) {
        docPanel.innerHtml = '';
      }
      return;
    }
    if (!_editor.hasFocus || _editor.document.selection.isNotEmpty) {
      return;
    }

    final offset = _editor.document.indexFromPos(_editor.document.cursor);

    final request = SourceRequest()..offset = offset;

    if (_editor.completionActive) {
      // If the completion popup is open we create a new source as if the
      // completion popup was chosen, and ask for the documentation of that
      // source.
      request.source =
          _sourceWithCompletionInserted(_sourceProvider.dartSource, offset);
    } else {
      request.source = _sourceProvider.dartSource;
    }

    dartServices
        .document(request)
        .timeout(serviceCallTimeout)
        .then((DocumentResponse result) {
      final hash = result.hashCode;
      // If nothing has changed, don't need to parse Markdown and
      // manipulate HTML again.
      if (hash == _previousDocHash) {
        return;
      }
      _previousDocHash = hash;

      final docResult = _getHtmlTextFor(result);

      final docType = 'type-${docResult.entityKind}';
      for (final docPanel in docElements) {
        docPanel.setInnerHtml(docResult.html, validator: _htmlValidator);
        for (final a in docPanel.querySelectorAll('a')) {
          if (a is AnchorElement) a.target = 'docs';
        }
        for (final h in docPanel.querySelectorAll('h1')) {
          h.classes.add(docType);
        }
      }
    });
  }