[clang-tools-extra] Clang doc async (PR #93276)
@@ -1049,31 +1047,33 @@ static llvm::Error CopyFile(StringRef FilePath, StringRef OutDirectory) { std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite); if (FileErr != OK) { return llvm::createStringError(llvm::inconvertibleErrorCode(), - "error creating file " + - llvm::sys::path::filename(FilePath) + - ": " + FileErr.message() + "\n"); + "error creating file " + FilePath + ": " + + FileErr.message() + "\n"); } return llvm::Error::success(); } llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) { - auto Err = SerializeIndex(CDCtx); - if (Err) + if (auto Err = SerializeIndex(CDCtx)) { return Err; - Err = GenIndex(CDCtx); - if (Err) + } + + if (auto Err = GenIndex(CDCtx)) { return Err; + } for (const auto &FilePath : CDCtx.UserStylesheets) { -Err = CopyFile(FilePath, CDCtx.OutDirectory); -if (Err) +if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) { return Err; +} } + for (const auto &FilePath : CDCtx.FilesToCopy) { -Err = CopyFile(FilePath, CDCtx.OutDirectory); -if (Err) +if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) { return Err; +} } + ilovepi wrote: nit: Try to avoid unrelated white space chagnes. If your editor inserts these automatically, you may need to update your config. Also `git clang-format HEAD~` is your friend, but do be sure to use an up-to-date `clang-format`. https://github.com/llvm/llvm-project/pull/93276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Clang doc async (PR #93276)
@@ -82,6 +82,7 @@ function createIndex(Index) { 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); + fetch("/index.json") + .then((response) => response.json()) + .then((Index) => { createIndex(Index); }); ilovepi wrote: Can you update this comment to reflect how this works? https://github.com/llvm/llvm-project/pull/93276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Clang doc async (PR #93276)
@@ -179,7 +183,7 @@ Example usage for a project using a compile commands database: SourceRoot, RepositoryUrl, {UserStylesheets.begin(), UserStylesheets.end()}, - {"index.js", "index_json.js"}}; + {"index.js"}}; ilovepi wrote: I assume `index_json.js` is no longer needed from the changes above w/ `fetch(...`. If that's accurate, can you include those details in the commit message? https://github.com/llvm/llvm-project/pull/93276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Clang doc async (PR #93276)
@@ -491,6 +491,7 @@ struct ClangDocContext { std::string SourceRoot; // Directory where processed files are stored. Links // to definition locations will only be generated if // the file is in this dir. + ilovepi wrote: nit: unrelated change in whitespace https://github.com/llvm/llvm-project/pull/93276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Clang doc async (PR #93276)
@@ -155,6 +155,10 @@ Example usage for a project using a compile commands database: return 1; } + // add option to customize url fragment + // such as + // https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-doc/ClangDocMain.cpp#L1 + ilovepi wrote: Is this intended as a `TODO:`? https://github.com/llvm/llvm-project/pull/93276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Clang doc async (PR #93276)
@@ -1049,31 +1047,33 @@ static llvm::Error CopyFile(StringRef FilePath, StringRef OutDirectory) { std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite); if (FileErr != OK) { return llvm::createStringError(llvm::inconvertibleErrorCode(), - "error creating file " + - llvm::sys::path::filename(FilePath) + - ": " + FileErr.message() + "\n"); + "error creating file " + FilePath + ": " + + FileErr.message() + "\n"); ilovepi wrote: I'm a little unclear on why we're not using the `llvm::sys::path` here anymore? Is `FilePath` actually a `URL` or something equivalent that isn't platform dependent? For example, if it's a real file system path, I'd worry that things like the `/` would be wrong if this was Windows vs. Linux. https://github.com/llvm/llvm-project/pull/93276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Clang doc async (PR #93276)
@@ -1049,31 +1047,33 @@ static llvm::Error CopyFile(StringRef FilePath, StringRef OutDirectory) { std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite); if (FileErr != OK) { return llvm::createStringError(llvm::inconvertibleErrorCode(), - "error creating file " + - llvm::sys::path::filename(FilePath) + - ": " + FileErr.message() + "\n"); + "error creating file " + FilePath + ": " + + FileErr.message() + "\n"); } return llvm::Error::success(); } llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) { - auto Err = SerializeIndex(CDCtx); - if (Err) + if (auto Err = SerializeIndex(CDCtx)) { return Err; - Err = GenIndex(CDCtx); - if (Err) + } ilovepi wrote: I'm not sure updating the error handling here and below is a functional improvement. However, even if it is, it belongs in a separate PR, as its unrelated to the work done in this patch. While we normally don't use `auto` that much in llvm (see https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable), an error code is probably an OK time to use one. Unfortunately, these APIs don't seem to obviously return an error based on their signatures, so you may want to consider using an explicit type (but its not required). Lastly, our style guide only uses braces for conditionals w/ multiple lines (see https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements). https://github.com/llvm/llvm-project/pull/93276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Clang doc async (PR #93276)
https://github.com/ilovepi requested changes to this pull request. I've noted several items that need to be addressed in line before this lands. Both the commit title and description need to be updated. Please add a tag `[clang-doc]` to the commit title, and include the full details of the problem you're addressing and how this patch addresses them in the description. If this fixes the issue you've referenced, add `Fixes #93273` after the body of the descripton. You can find more info on GitHub interactions w/ commits here https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue Lastly, this patch badly needs tests. Please create a PR with that demonstrates the existing behavior in a test (or tests) that we can land first. You can rebase this patch on top of it, and we can easily understand the delta between the new and old behaviors based on how the test changed. https://github.com/llvm/llvm-project/pull/93276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Clang doc async (PR #93276)
https://github.com/ilovepi edited https://github.com/llvm/llvm-project/pull/93276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Clang doc async (PR #93276)
https://github.com/PeterChou1 updated https://github.com/llvm/llvm-project/pull/93276 >From 0b6d536133f63e078fbde491a8c92c7ec916cb47 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 05:18:05 -0400 Subject: [PATCH] [clang-doc] make loading of json side bar async --- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 28 +-- clang-tools-extra/clang-doc/Representation.h | 1 + clang-tools-extra/clang-doc/assets/index.js | 5 ++-- .../clang-doc/tool/ClangDocMain.cpp | 6 +++- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index c0faf5f7e8fd9..fb1a7f94c9094 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -964,7 +964,7 @@ static llvm::Error SerializeIndex(ClangDocContext &CDCtx) { std::error_code FileErr; llvm::SmallString<128> FilePath; llvm::sys::path::native(CDCtx.OutDirectory, FilePath); - llvm::sys::path::append(FilePath, "index_json.js"); + llvm::sys::path::append(FilePath, "index.json"); llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_None); if (FileErr != OK) { return llvm::createStringError(llvm::inconvertibleErrorCode(), @@ -985,9 +985,7 @@ static llvm::Error SerializeIndex(ClangDocContext &CDCtx) { }); }); }; - OS << "var JsonIndex = `\n"; IndexToJSON(CDCtx.Idx); - OS << "`;\n"; return llvm::Error::success(); } @@ -1049,31 +1047,33 @@ static llvm::Error CopyFile(StringRef FilePath, StringRef OutDirectory) { std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite); if (FileErr != OK) { return llvm::createStringError(llvm::inconvertibleErrorCode(), - "error creating file " + - llvm::sys::path::filename(FilePath) + - ": " + FileErr.message() + "\n"); + "error creating file " + FilePath + ": " + + FileErr.message() + "\n"); } return llvm::Error::success(); } llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) { - auto Err = SerializeIndex(CDCtx); - if (Err) + if (auto Err = SerializeIndex(CDCtx)) { return Err; - Err = GenIndex(CDCtx); - if (Err) + } + + if (auto Err = GenIndex(CDCtx)) { return Err; + } for (const auto &FilePath : CDCtx.UserStylesheets) { -Err = CopyFile(FilePath, CDCtx.OutDirectory); -if (Err) +if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) { return Err; +} } + for (const auto &FilePath : CDCtx.FilesToCopy) { -Err = CopyFile(FilePath, CDCtx.OutDirectory); -if (Err) +if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) { return Err; +} } + return llvm::Error::success(); } diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h index a6b144eb7fa2a..23323f1cbdf46 100644 --- a/clang-tools-extra/clang-doc/Representation.h +++ b/clang-tools-extra/clang-doc/Representation.h @@ -491,6 +491,7 @@ struct ClangDocContext { std::string SourceRoot; // Directory where processed files are stored. Links // to definition locations will only be generated if // the file is in this dir. + // URL of repository that hosts code used for links to definition locations. std::optional RepositoryUrl; // Path of CSS stylesheets that will be copied to OutDirectory and used to diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index a5ac90f2e06e7..379867268527e 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -82,6 +82,7 @@ function createIndex(Index) { 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); + fetch("/index.json") + .then((response) => response.json()) + .then((Index) => { createIndex(Index); }); }); diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp index 21b581fa6df2e..53108a77dab21 100644 --- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp +++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp @@ -155,6 +155,10 @@ Example usage for a project using a compile commands database: return 1; } + // add option to customize url fragment + // such as + // https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-doc/ClangDocMain.cpp#L1 + // Fail early if an invalid format was provided. std::string Format = getFormatString(); llvm::outs() << "Emiting docs in " << Format << " format.\n"; @@ -179,7 +
[clang-tools-extra] Clang doc async (PR #93276)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 2287f8d2353dadcbe210e07776c927c9fabca57c 0fa00f0a6064dd0ab42dfd0863ebdcf90daa1742 -- clang-tools-extra/clang-doc/HTMLGenerator.cpp clang-tools-extra/clang-doc/Representation.h clang-tools-extra/clang-doc/Serialize.cpp clang-tools-extra/clang-doc/tool/ClangDocMain.cpp `` View the diff from clang-format here. ``diff diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index fd3807014f..fb1a7f94c9 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -1047,9 +1047,8 @@ static llvm::Error CopyFile(StringRef FilePath, StringRef OutDirectory) { std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite); if (FileErr != OK) { return llvm::createStringError(llvm::inconvertibleErrorCode(), - "error creating file " + - FilePath + - ": " + FileErr.message() + "\n"); + "error creating file " + FilePath + ": " + + FileErr.message() + "\n"); } return llvm::Error::success(); } diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index 49062af637..3b074d849e 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -32,7 +32,6 @@ populateParentNamespaces(llvm::SmallVector &Namespaces, static void populateMemberTypeInfo(MemberTypeInfo &I, const FieldDecl *D); - // A function to extract the appropriate relative path for a given info's // documentation. The path returned is a composite of the parent namespaces. // diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp index af892b5402..53108a77da 100644 --- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp +++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp @@ -156,8 +156,8 @@ Example usage for a project using a compile commands database: } // add option to customize url fragment - // such as https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-doc/ClangDocMain.cpp#L1 - + // such as + // https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-doc/ClangDocMain.cpp#L1 // Fail early if an invalid format was provided. std::string Format = getFormatString(); @@ -205,7 +205,6 @@ Example usage for a project using a compile commands database: CDCtx.FilesToCopy.emplace_back(IndexJS.str()); } - // Mapping phase llvm::outs() << "Mapping decls...\n"; auto Err = `` https://github.com/llvm/llvm-project/pull/93276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Clang doc async (PR #93276)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: None (PeterChou1) Changes relevant issue: https://github.com/llvm/llvm-project/issues/93273 --- Full diff: https://github.com/llvm/llvm-project/pull/93276.diff 5 Files Affected: - (modified) clang-tools-extra/clang-doc/HTMLGenerator.cpp (+13-12) - (modified) clang-tools-extra/clang-doc/Representation.h (+1) - (modified) clang-tools-extra/clang-doc/Serialize.cpp (+1) - (modified) clang-tools-extra/clang-doc/assets/index.js (+5-2) - (modified) clang-tools-extra/clang-doc/tool/ClangDocMain.cpp (+6-1) ``diff diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index c0faf5f7e8fd9..fd3807014fd09 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -964,7 +964,7 @@ static llvm::Error SerializeIndex(ClangDocContext &CDCtx) { std::error_code FileErr; llvm::SmallString<128> FilePath; llvm::sys::path::native(CDCtx.OutDirectory, FilePath); - llvm::sys::path::append(FilePath, "index_json.js"); + llvm::sys::path::append(FilePath, "index.json"); llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_None); if (FileErr != OK) { return llvm::createStringError(llvm::inconvertibleErrorCode(), @@ -985,9 +985,7 @@ static llvm::Error SerializeIndex(ClangDocContext &CDCtx) { }); }); }; - OS << "var JsonIndex = `\n"; IndexToJSON(CDCtx.Idx); - OS << "`;\n"; return llvm::Error::success(); } @@ -1050,30 +1048,33 @@ static llvm::Error CopyFile(StringRef FilePath, StringRef OutDirectory) { if (FileErr != OK) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "error creating file " + - llvm::sys::path::filename(FilePath) + + FilePath + ": " + FileErr.message() + "\n"); } return llvm::Error::success(); } llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) { - auto Err = SerializeIndex(CDCtx); - if (Err) + if (auto Err = SerializeIndex(CDCtx)) { return Err; - Err = GenIndex(CDCtx); - if (Err) + } + + if (auto Err = GenIndex(CDCtx)) { return Err; + } for (const auto &FilePath : CDCtx.UserStylesheets) { -Err = CopyFile(FilePath, CDCtx.OutDirectory); -if (Err) +if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) { return Err; +} } + for (const auto &FilePath : CDCtx.FilesToCopy) { -Err = CopyFile(FilePath, CDCtx.OutDirectory); -if (Err) +if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) { return Err; +} } + return llvm::Error::success(); } diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h index a6b144eb7fa2a..23323f1cbdf46 100644 --- a/clang-tools-extra/clang-doc/Representation.h +++ b/clang-tools-extra/clang-doc/Representation.h @@ -491,6 +491,7 @@ struct ClangDocContext { std::string SourceRoot; // Directory where processed files are stored. Links // to definition locations will only be generated if // the file is in this dir. + // URL of repository that hosts code used for links to definition locations. std::optional RepositoryUrl; // Path of CSS stylesheets that will be copied to OutDirectory and used to diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index 3b074d849e8a9..49062af637ea0 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -32,6 +32,7 @@ populateParentNamespaces(llvm::SmallVector &Namespaces, static void populateMemberTypeInfo(MemberTypeInfo &I, const FieldDecl *D); + // A function to extract the appropriate relative path for a given info's // documentation. The path returned is a composite of the parent namespaces. // diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index a5ac90f2e06e7..b659b20069ac5 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -82,6 +82,9 @@ function createIndex(Index) { 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); + fetch("/index.json") + .then((response) => response.json()) + .then((Index) => { +createIndex(Index); + }); }); diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp index 21b581fa6df2e..af892b5402092 100644 --- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp +++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp @@ -155,6 +155,10 @@ E
[clang-tools-extra] Clang doc async (PR #93276)
https://github.com/PeterChou1 created https://github.com/llvm/llvm-project/pull/93276 relevant issue: https://github.com/llvm/llvm-project/issues/93273 >From 1afdd4f6ef0c6e5caad06425cfa83036880ac08b Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 24 May 2024 02:32:44 -0400 Subject: [PATCH 1/2] [clang-doc] make loading of json side bar async --- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 25 ++- clang-tools-extra/clang-doc/Representation.h | 2 ++ clang-tools-extra/clang-doc/Serialize.cpp | 1 + clang-tools-extra/clang-doc/assets/index.js | 7 -- .../clang-doc/tool/ClangDocMain.cpp | 7 +- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index c0faf5f7e8fd9..fd3807014fd09 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -964,7 +964,7 @@ static llvm::Error SerializeIndex(ClangDocContext &CDCtx) { std::error_code FileErr; llvm::SmallString<128> FilePath; llvm::sys::path::native(CDCtx.OutDirectory, FilePath); - llvm::sys::path::append(FilePath, "index_json.js"); + llvm::sys::path::append(FilePath, "index.json"); llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_None); if (FileErr != OK) { return llvm::createStringError(llvm::inconvertibleErrorCode(), @@ -985,9 +985,7 @@ static llvm::Error SerializeIndex(ClangDocContext &CDCtx) { }); }); }; - OS << "var JsonIndex = `\n"; IndexToJSON(CDCtx.Idx); - OS << "`;\n"; return llvm::Error::success(); } @@ -1050,30 +1048,33 @@ static llvm::Error CopyFile(StringRef FilePath, StringRef OutDirectory) { if (FileErr != OK) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "error creating file " + - llvm::sys::path::filename(FilePath) + + FilePath + ": " + FileErr.message() + "\n"); } return llvm::Error::success(); } llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) { - auto Err = SerializeIndex(CDCtx); - if (Err) + if (auto Err = SerializeIndex(CDCtx)) { return Err; - Err = GenIndex(CDCtx); - if (Err) + } + + if (auto Err = GenIndex(CDCtx)) { return Err; + } for (const auto &FilePath : CDCtx.UserStylesheets) { -Err = CopyFile(FilePath, CDCtx.OutDirectory); -if (Err) +if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) { return Err; +} } + for (const auto &FilePath : CDCtx.FilesToCopy) { -Err = CopyFile(FilePath, CDCtx.OutDirectory); -if (Err) +if (auto Err = CopyFile(FilePath, CDCtx.OutDirectory)) { return Err; +} } + return llvm::Error::success(); } diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h index a6b144eb7fa2a..0a9002d21a20b 100644 --- a/clang-tools-extra/clang-doc/Representation.h +++ b/clang-tools-extra/clang-doc/Representation.h @@ -491,6 +491,8 @@ struct ClangDocContext { std::string SourceRoot; // Directory where processed files are stored. Links // to definition locations will only be generated if // the file is in this dir. + + std::string LineFragment; // URL of repository that hosts code used for links to definition locations. std::optional RepositoryUrl; // Path of CSS stylesheets that will be copied to OutDirectory and used to diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index 3b074d849e8a9..49062af637ea0 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -32,6 +32,7 @@ populateParentNamespaces(llvm::SmallVector &Namespaces, static void populateMemberTypeInfo(MemberTypeInfo &I, const FieldDecl *D); + // A function to extract the appropriate relative path for a given info's // documentation. The path returned is a composite of the parent namespaces. // diff --git a/clang-tools-extra/clang-doc/assets/index.js b/clang-tools-extra/clang-doc/assets/index.js index a5ac90f2e06e7..b659b20069ac5 100644 --- a/clang-tools-extra/clang-doc/assets/index.js +++ b/clang-tools-extra/clang-doc/assets/index.js @@ -82,6 +82,9 @@ function createIndex(Index) { 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); + fetch("/index.json") + .then((response) => response.json()) + .then((Index) => { +createIndex(Index); + }); }); diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp index 21b581fa6df2e..af892b5402092 10