From ebf41bbce9c7ea7ffeae6ff72de209ad0350b4e7 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 11 Dec 2023 22:18:46 -0500 Subject: [PATCH] Add an option to not generate source code links at all --- subdoc/lib/run_options.h | 2 ++ subdoc/lib/visit.cc | 3 +++ subdoc/subdoc_main.cc | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/subdoc/lib/run_options.h b/subdoc/lib/run_options.h index e50fedd64..e17e099b0 100644 --- a/subdoc/lib/run_options.h +++ b/subdoc/lib/run_options.h @@ -77,6 +77,8 @@ struct RunOptions { /// global namespace/project overview page. This is the raw markdown text, not /// parsed to html yet. std::string project_overview_text; + /// Whether to generate links to source code. + bool generate_source_links = true; /// A prefix to remove from all paths in source links. sus::Option remove_path_prefix; /// A prefix to add to all paths in source links, after removing the prefix diff --git a/subdoc/lib/visit.cc b/subdoc/lib/visit.cc index 8cd52e868..08053387d 100644 --- a/subdoc/lib/visit.cc +++ b/subdoc/lib/visit.cc @@ -1542,6 +1542,9 @@ class Visitor : public clang::RecursiveASTVisitor { clang::SourceLocation loc, clang::SourceLocation begin_loc, clang::ASTContext& ast_cx) noexcept { + // The user may not have anywhere to store code in order to link to it. + if (!cx_.options.generate_source_links) return; + clang::SourceManager& sm = ast_cx.getSourceManager(); const clang::FileEntry* entry = sm.getFileEntryForID(sm.getFileID(loc)); diff --git a/subdoc/subdoc_main.cc b/subdoc/subdoc_main.cc index 09138d6e0..179cc7e03 100644 --- a/subdoc/subdoc_main.cc +++ b/subdoc/subdoc_main.cc @@ -118,6 +118,12 @@ int main(int argc, const char** argv) { "specified by `--remove-source-path-prefix` is removed."), llvm::cl::cat(option_category)); + llvm::cl::opt option_no_source_links( + "no-source-links", + llvm::cl::desc("Avoid generating links to source code."), + llvm::cl::init(false), // + llvm::cl::cat(option_category)); + llvm::cl::opt option_ignore_bad_code_links( "ignore-bad-code-links", llvm::cl::desc("Ignore bad code links, don't generate an error. Useful " @@ -220,6 +226,7 @@ int main(int argc, const char** argv) { sus::iter::from_range(option_include_macro_prefixes) .cloned() .collect>(); + run_options.generate_source_links = !option_no_source_links.getValue(); if (option_remove_path_prefix.getNumOccurrences() > 0) { // Canonicalize the path to use `/` instead of `\`. std::string canonical_path = option_remove_path_prefix.getValue();