Skip to content

[clang-doc] add async loading #93276

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 10 commits into from
Jun 30, 2024
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-doc/HTMLGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,9 +993,9 @@ static llvm::Error serializeIndex(ClangDocContext &CDCtx) {
});
});
};
OS << "var JsonIndex = `\n";
OS << "async function LoadIndex() {\nreturn";
IndexToJSON(CDCtx.Idx);
OS << "`;\n";
OS << ";\n}";
return llvm::Error::success();
}

Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/clang-doc/assets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ function createIndex(Index) {

// Runs after DOM loads
document.addEventListener("DOMContentLoaded", function() {
// JsonIndex is a variable from another file that contains the index
// in JSON format
var Index = JSON.parse(JsonIndex);
createIndex(Index);
// LoadIndex is an asynchronous function that will be generated clang-doc.
// It ensures that the function call will not block as soon the page loads,
// since the index object are often huge and can contain thousands of lines.
LoadIndex().then((Index) => { createIndex(Index); });
});
7 changes: 4 additions & 3 deletions clang-tools-extra/test/clang-doc/basic-project.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Rectangle.html -check-prefix=HTML-RECTANGLE
// RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Circle.html -check-prefix=HTML-CIRCLE

// JSON-INDEX: var JsonIndex = `
// JSON-INDEX-NEXT: {
// JSON-INDEX: async function LoadIndex() {
// JSON-INDEX-NEXT: return{
// JSON-INDEX-NEXT: "USR": "{{([0-9A-F]{40})}}",
// JSON-INDEX-NEXT: "Name": "",
// JSON-INDEX-NEXT: "RefType": "default",
Expand Down Expand Up @@ -51,7 +51,8 @@
// JSON-INDEX-NEXT: ]
// JSON-INDEX-NEXT: }
// JSON-INDEX-NEXT: ]
// JSON-INDEX-NEXT: }`;
// JSON-INDEX-NEXT: };
// JSON-INDEX-NEXT: }

// HTML-SHAPE: <!DOCTYPE html>
// HTML-SHAPE-NEXT: <meta charset="utf-8"/>
Expand Down