diff --git a/.github/workflows/subdoc.yml b/.github/workflows/subdoc.yml index 8f149b697..59403c814 100644 --- a/.github/workflows/subdoc.yml +++ b/.github/workflows/subdoc.yml @@ -172,6 +172,7 @@ jobs: --project-name Subspace \ --remove-source-path-prefix $PWD \ --add-source-path-prefix ${source_url} \ + --source-path-line-prefix L \ /home/runner/work/subspace/subspace/sus - name: Deploy diff --git a/.github/workflows/try.yml b/.github/workflows/try.yml index 6e8543ccf..ba5b8ff9e 100644 --- a/.github/workflows/try.yml +++ b/.github/workflows/try.yml @@ -420,6 +420,7 @@ jobs: --project-name Subspace \ --remove-source-path-prefix $PWD \ --add-source-path-prefix ${source_url} \ + --source-path-line-prefix L \ /home/runner/work/subspace/subspace/sus bench: diff --git a/subdoc/lib/database.h b/subdoc/lib/database.h index e884cbc96..8fa479b61 100644 --- a/subdoc/lib/database.h +++ b/subdoc/lib/database.h @@ -69,7 +69,7 @@ struct SourceLink { }; Quality quality; std::string file_path; - u32 line; + std::string line; friend std::weak_ordering operator<=>(const SourceLink& lhs, const SourceLink& rhs) noexcept { diff --git a/subdoc/lib/run_options.h b/subdoc/lib/run_options.h index e17e099b0..2417e769e 100644 --- a/subdoc/lib/run_options.h +++ b/subdoc/lib/run_options.h @@ -49,6 +49,10 @@ struct RunOptions { macro_prefixes = sus::move(prefixes); return sus::move(*this); } + RunOptions set_generate_source_links(bool gen) && { + generate_source_links = gen; + return sus::move(*this); + } RunOptions set_remove_path_prefix(sus::Option prefix) && { remove_path_prefix = sus::move(prefix); return sus::move(*this); @@ -57,6 +61,10 @@ struct RunOptions { add_path_prefix = sus::move(prefix); return sus::move(*this); } + RunOptions set_source_line_prefix(sus::Option prefix) && { + source_line_prefix = sus::move(prefix); + return sus::move(*this); + } /// Whether to print progress while collecting documentation from souce files. bool show_progress = true; @@ -84,6 +92,9 @@ struct RunOptions { /// A prefix to add to all paths in source links, after removing the prefix /// specified by `remove_path_prefix`. sus::Option add_path_prefix; + /// A prefix to add to the source code line number html fragment. Github uses + /// an `L` as its prefix. + sus::Option source_line_prefix; }; } // namespace subdoc diff --git a/subdoc/lib/visit.cc b/subdoc/lib/visit.cc index 08053387d..cd746f55e 100644 --- a/subdoc/lib/visit.cc +++ b/subdoc/lib/visit.cc @@ -1583,9 +1583,14 @@ class Visitor : public clang::RecursiveASTVisitor { std::replace(canonical_path.begin(), canonical_path.end(), '\\', '/'); if (cx_.options.remove_path_prefix.is_some()) { - const auto& prefix = cx_.options.remove_path_prefix.as_value(); - if (canonical_path.starts_with(prefix)) { - canonical_path = canonical_path.substr(prefix.size()); + // Canonicalize the path to use `/` instead of `\`. + std::string canonical_prefix = + sus::clone(cx_.options.remove_path_prefix.as_value()); + std::replace(canonical_prefix.begin(), canonical_prefix.end(), '\\', + '/'); + + if (canonical_path.starts_with(canonical_prefix)) { + canonical_path = canonical_path.substr(canonical_prefix.size()); if (canonical_path.starts_with("/")) canonical_path = canonical_path.substr(1u); } @@ -1596,10 +1601,16 @@ class Visitor : public clang::RecursiveASTVisitor { canonical_path.insert(0u, prefix); } + std::ostringstream line; + if (cx_.options.source_line_prefix.is_some()) { + line << cx_.options.source_line_prefix.as_value(); + } + line << sm.getLineNumber(sm.getFileID(loc), sm.getFileOffset(loc)); + auto link = sus::Option(SourceLink{ .quality = quality, .file_path = sus::move(canonical_path), - .line = sm.getLineNumber(sm.getFileID(loc), sm.getFileOffset(loc)), + .line = sus::move(line).str(), }); if (link > e.source_link) e.source_link = sus::move(link); } diff --git a/subdoc/subdoc_main.cc b/subdoc/subdoc_main.cc index 179cc7e03..eff62baf3 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_source_line_prefix( + "source-path-line-prefix", + llvm::cl::desc("A prefix to add to the line number on all source code " + "links. Github uses an `L` as its prefix."), + llvm::cl::cat(option_category)); + llvm::cl::opt option_no_source_links( "no-source-links", llvm::cl::desc("Avoid generating links to source code."), @@ -228,14 +234,16 @@ int main(int argc, const char** argv) { .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(); - std::replace(canonical_path.begin(), canonical_path.end(), '\\', '/'); - run_options.remove_path_prefix = sus::some(sus::move(canonical_path)); + run_options.remove_path_prefix = + sus::some(sus::move(option_remove_path_prefix.getValue())); } if (option_add_path_prefix.getNumOccurrences() > 0) { run_options.add_path_prefix = sus::some(option_add_path_prefix.getValue()); } + if (option_source_line_prefix.getNumOccurrences() > 0) { + run_options.source_line_prefix = + sus::some(option_source_line_prefix.getValue()); + } auto fs = llvm::vfs::getRealFileSystem(); auto result = subdoc::run_files(comp_db, sus::move(run_against_files), diff --git a/subdoc/tests/aliases_unittest.cc b/subdoc/tests/aliases_unittest.cc index 3b4e260c4..02d2d58d7 100644 --- a/subdoc/tests/aliases_unittest.cc +++ b/subdoc/tests/aliases_unittest.cc @@ -35,13 +35,13 @@ TEST_F(SubDocTest, AliasUsingStruct) { auto& e = db.find_alias_comment("7:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 8u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "8"); } { auto& e = db.find_alias_comment("10:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 11u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "11"); } } @@ -66,13 +66,13 @@ TEST_F(SubDocTest, AliasUsingConcept) { auto& e = db.find_alias_comment("7:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 8u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "8"); } { auto& e = db.find_alias_comment("10:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 11u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "11"); } } @@ -98,7 +98,7 @@ TEST_F(SubDocTest, AliasUsingMethod) { auto& e = db.find_alias_comment("10:7").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 11u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "11"); } TEST_F(SubDocTest, AliasUsingEnumInNamespace) { @@ -114,7 +114,7 @@ TEST_F(SubDocTest, AliasUsingEnumInNamespace) { auto& e = db.find_alias_comment("3:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 4u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "4"); } TEST_F(SubDocTest, DISABLED_AliasUsingEnum) { @@ -141,13 +141,13 @@ TEST_F(SubDocTest, DISABLED_AliasUsingEnum) { auto& e = db.find_alias_comment("8:7").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 9u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "9"); } { auto& e = db.find_alias_comment("13:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 14u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "14"); } } @@ -185,13 +185,13 @@ TEST_F(SubDocTest, AliasNamedTypeInNamespace) { auto& e = db.find_alias_comment("7:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 8u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "8"); } { auto& e = db.find_alias_comment("10:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 11u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "11"); } } @@ -213,7 +213,7 @@ TEST_F(SubDocTest, AliasNamedTypeInRecord) { auto& e = db.find_alias_comment("7:7").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 8u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "8"); } } @@ -233,6 +233,6 @@ TEST_F(SubDocTest, AliasUsingVariable) { auto& e = db.find_alias_comment("6:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 7u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "7"); } } diff --git a/subdoc/tests/fields_unittest.cc b/subdoc/tests/fields_unittest.cc index 48975d812..1765bf4f9 100644 --- a/subdoc/tests/fields_unittest.cc +++ b/subdoc/tests/fields_unittest.cc @@ -27,7 +27,7 @@ TEST_F(SubDocTest, Field) { auto& e = db.find_field_comment("3:7").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 4u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "4"); } TEST_F(SubDocTest, StaticField) { @@ -43,7 +43,7 @@ TEST_F(SubDocTest, StaticField) { auto& e = db.find_field_comment("3:7").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 4u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "4"); } TEST_F(SubDocTest, StaticFieldSplit) { @@ -61,7 +61,7 @@ TEST_F(SubDocTest, StaticFieldSplit) { auto& e = db.find_field_comment("3:7").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 7u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "7"); } TEST_F(SubDocTest, PrivateField) { @@ -133,12 +133,12 @@ TEST_F(SubDocTest, Variables) { auto& e = db.find_variable_comment("2:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 3u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "3"); } { auto& e = db.find_variable_comment("5:7").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 6u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "6"); } } diff --git a/subdoc/tests/functions_unittest.cc b/subdoc/tests/functions_unittest.cc index a03914239..8f0aa5651 100644 --- a/subdoc/tests/functions_unittest.cc +++ b/subdoc/tests/functions_unittest.cc @@ -26,7 +26,7 @@ TEST_F(SubDocTest, Function) { auto& e = db.find_function_comment("2:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 3u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "3"); } TEST_F(SubDocTest, FunctionOverloads) { @@ -47,13 +47,13 @@ TEST_F(SubDocTest, FunctionOverloads) { auto& e = db.find_function_comment("2:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 3u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "3"); } { auto& e = db.find_function_comment("7:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 8u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "8"); } } @@ -80,13 +80,13 @@ TEST_F(SubDocTest, FunctionOverloadsNoMerge) { auto& e = db.find_function_comment("2:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 6u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "6"); } { auto& e = db.find_function_comment("7:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 11u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "11"); } } @@ -109,13 +109,13 @@ TEST_F(SubDocTest, FunctionOverloadsMerge) { auto& e = db.find_function_comment("2:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 4u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "4"); } { auto& e = db.find_function_comment("7:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 9u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "9"); } } @@ -205,7 +205,7 @@ TEST_F(SubDocTest, ForwardDeclDocumented) { auto& e = db.find_function_comment("2:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 4u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "4"); } TEST_F(SubDocTest, ForwardDeclUndocumented) { @@ -222,7 +222,7 @@ TEST_F(SubDocTest, ForwardDeclUndocumented) { auto& e = db.find_function_comment("3:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 4u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "4"); } TEST_F(SubDocTest, FunctionInNamedNamespace) { @@ -239,7 +239,7 @@ TEST_F(SubDocTest, FunctionInNamedNamespace) { auto& e = db.find_function_comment("3:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 4u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "4"); } TEST_F(SubDocTest, FunctionInAnonymousNamespace) { @@ -294,19 +294,19 @@ TEST_F(SubDocTest, FunctionFriend) { auto& e = db.find_function_comment("3:7").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 4u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "4"); } { auto& e = db.find_function_comment("7:7").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 11u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "11"); } { auto& e = db.find_function_comment("13:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 14u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "14"); } } diff --git a/subdoc/tests/macros_unittest.cc b/subdoc/tests/macros_unittest.cc index 288ab5234..2aedfeb0c 100644 --- a/subdoc/tests/macros_unittest.cc +++ b/subdoc/tests/macros_unittest.cc @@ -35,7 +35,7 @@ TEST_F(SubDocTest, MacroFunction) { auto& e = db.find_function_comment("3:7").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 4u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "4"); } TEST_F(SubDocTest, MacroClass) { @@ -109,7 +109,7 @@ TEST_F(SubDocTest, MacroNamesField) { auto& e = db.find_field_comment("4:9").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 5u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "5"); } TEST_F(SubDocTest, MacroModName) { @@ -126,7 +126,7 @@ TEST_F(SubDocTest, MacroModName) { auto& e = db.find_record_comment("4:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 5u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "5"); } TEST_F(SubDocTest, MacroMultilineComment) { @@ -185,5 +185,5 @@ TEST_F(SubDocTest, Macro) { auto& e = db.find_macro_comment("2:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 3u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "3"); } diff --git a/subdoc/tests/namespaces_unittest.cc b/subdoc/tests/namespaces_unittest.cc index 4c0f9369a..d8c03eaa7 100644 --- a/subdoc/tests/namespaces_unittest.cc +++ b/subdoc/tests/namespaces_unittest.cc @@ -102,7 +102,7 @@ TEST_F(SubDocTest, NamespaceComment) { auto& e = db.find_namespace_comment("2:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 3u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "3"); } TEST_F(SubDocTest, NestedNamespaceComment) { @@ -119,7 +119,7 @@ TEST_F(SubDocTest, NestedNamespaceComment) { auto& e = db.find_namespace_comment("3:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 4u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "4"); } TEST_F(SubDocTest, NamespaceDotsComment) { diff --git a/subdoc/tests/records_unittest.cc b/subdoc/tests/records_unittest.cc index e7f397aaa..e96d8fb51 100644 --- a/subdoc/tests/records_unittest.cc +++ b/subdoc/tests/records_unittest.cc @@ -26,7 +26,7 @@ TEST_F(SubDocTest, Struct) { auto& e = db.find_record_comment("2:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 3u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "3"); } TEST_F(SubDocTest, ForwardStruct) { @@ -55,7 +55,7 @@ TEST_F(SubDocTest, TemplateStruct) { auto& e = db.find_record_comment("2:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 4u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "4"); } TEST_F(SubDocTest, TemplateStructSpecialization) { @@ -88,7 +88,7 @@ TEST_F(SubDocTest, StructInNamedNamespace) { auto& e = db.find_record_comment("3:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 4u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "4"); } TEST_F(SubDocTest, StructInPrivateNamespace) { @@ -147,7 +147,7 @@ TEST_F(SubDocTest, NestedStruct) { auto& e = db.find_record_comment("4:7").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 5u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "5"); } TEST_F(SubDocTest, PrivateStruct) { @@ -198,12 +198,12 @@ TEST_F(SubDocTest, AnonStruct) { auto& e = db.find_record_comment("2:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 3u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "3"); } { auto& e = db.find_record_comment("4:5").unwrap(); ASSERT_TRUE(e.source_link.is_some()); EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "test.cc"); - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 5u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "5"); } } diff --git a/subdoc/tests/source_link_unittest.cc b/subdoc/tests/source_link_unittest.cc index e99050e81..b56dff103 100644 --- a/subdoc/tests/source_link_unittest.cc +++ b/subdoc/tests/source_link_unittest.cc @@ -38,7 +38,34 @@ TEST_F(SubDocTest, SourceLinkFilePath) { #else EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "/path/to/test.cc"); #endif - EXPECT_EQ(e.source_link.as_ref().unwrap().line, 3u); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "3"); +} + +TEST_F(SubDocTest, SourceLinkPrefixes) { +#ifdef _MSC_VER + const char PATH[] = "C:\\path\\to\\test.cc"; + const char REMOVE[] = "C:\\path"; +#else + const char PATH[] = "/path/to/test.cc"; + const char REMOVE[] = "/path"; +#endif + + auto options = subdoc::RunOptions() + .set_show_progress(false) + .set_remove_path_prefix(sus::some(REMOVE)) + .set_add_path_prefix(sus::some("/things")) + .set_source_line_prefix(sus::some("L")); + auto result = run_code_with_options(options, PATH, R"( + /// Comment headline 1 + int i; + )"); + ASSERT_TRUE(result.is_ok()); + subdoc::Database db = sus::move(result).unwrap(); + ASSERT_TRUE(has_variable_comment(db, "2:5", "

Comment headline 1

")); + auto& e = db.find_variable_comment("2:5").unwrap(); + ASSERT_TRUE(e.source_link.is_some()); + EXPECT_EQ(e.source_link.as_ref().unwrap().file_path, "/things/to/test.cc"); + EXPECT_EQ(e.source_link.as_ref().unwrap().line, "L3"); } } // namespace diff --git a/tools/run_subdoc.bat b/tools/run_subdoc.bat index 036aaf1f6..35b3ffab7 100644 --- a/tools/run_subdoc.bat +++ b/tools/run_subdoc.bat @@ -15,4 +15,5 @@ out\subdoc\subdoc -p out --out docs ^ --ignore-bad-code-links ^ --remove-source-path-prefix %cd% ^ --add-source-path-prefix .. ^ + --source-path-line-prefix L ^ subspace/sus/num/uptr_uni reverse_uni diff --git a/tools/run_subdoc.sh b/tools/run_subdoc.sh index 98f58756a..1fa0682e7 100755 --- a/tools/run_subdoc.sh +++ b/tools/run_subdoc.sh @@ -17,4 +17,5 @@ out/subdoc/subdoc -p out --out docs \ --ignore-bad-code-links \ --remove-source-path-prefix $PWD \ --add-source-path-prefix .. \ + --source-path-line-prefix L \ i8_unittest $*