Skip to content

Commit

Permalink
Add an option to not generate source code links at all
Browse files Browse the repository at this point in the history
  • Loading branch information
danakj committed Dec 12, 2023
1 parent 7253d98 commit ebf41bb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions subdoc/lib/run_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> remove_path_prefix;
/// A prefix to add to all paths in source links, after removing the prefix
Expand Down
3 changes: 3 additions & 0 deletions subdoc/lib/visit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,9 @@ class Visitor : public clang::RecursiveASTVisitor<Visitor> {
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));
Expand Down
7 changes: 7 additions & 0 deletions subdoc/subdoc_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> 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<bool> option_ignore_bad_code_links(
"ignore-bad-code-links",
llvm::cl::desc("Ignore bad code links, don't generate an error. Useful "
Expand Down Expand Up @@ -220,6 +226,7 @@ int main(int argc, const char** argv) {
sus::iter::from_range(option_include_macro_prefixes)
.cloned()
.collect<sus::Vec<std::string>>();
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();
Expand Down

0 comments on commit ebf41bb

Please sign in to comment.