[clang-tools-extra] [clang-doc] [feat] add --repository-line-prefix argument (PR #131280)

Paul Kirth via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 17 10:08:43 PDT 2025


================
@@ -750,11 +754,15 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) {
   Out.emplace_back(std::move(Table));
 
   if (I.DefLoc) {
-    if (!CDCtx.RepositoryUrl)
-      Out.emplace_back(writeFileDefinition(*I.DefLoc));
-    else
-      Out.emplace_back(
-          writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+    std::optional<StringRef> RepoUrl;
+    std::optional<StringRef> RepoLinePrefix;
+
+    if (CDCtx.RepositoryUrl)
+      RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+    if (CDCtx.RepositoryLinePrefix)
+      RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+    Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
----------------
ilovepi wrote:

The way the data and API are used now is not great. We're essentially using a complex indirection layer to convert `optional<string>` to `optional<StringRef>`.

Perhaps its better if `WriteFileDefinition` just takes `StringRef` arguments instead of `optional<StringRef>`? Then instead of checking the optional, you can either just use the `StringRef` as is or at worst check for `empty()`. Do you think that would allow us to simplify this code?

https://github.com/llvm/llvm-project/pull/131280


More information about the cfe-commits mailing list