Skip to content

Commit

Permalink
Save links to the source in the database
Browse files Browse the repository at this point in the history
They are not generated into the html output yet.

- Definitions with comments are preferred (including in an overload set)
  of multiple definitions.
- If the comment is not on the definition, the definition is still
  preferred.
- Otherwise, the comment location is preferred.
- Lastly, any given location will do.
  • Loading branch information
danakj committed Dec 11, 2023
1 parent 5f32eca commit d56aa9c
Show file tree
Hide file tree
Showing 16 changed files with 619 additions and 100 deletions.
1 change: 1 addition & 0 deletions subdoc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ if(${SUBSPACE_BUILD_TESTS})
"tests/methods_unittest.cc"
"tests/namespaces_unittest.cc"
"tests/records_unittest.cc"
"tests/source_link_unittest.cc"
"tests/styles_unittest.cc"
"tests/type_unittest.cc"
"tests/self_name_replace_unittest.cc"
Expand Down
19 changes: 19 additions & 0 deletions subdoc/lib/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ using FoundName = sus::Choice<sus_choice_types(
(FoundNameTag::Field, const FieldElement&),
(FoundNameTag::Macro, const MacroElement&))>;

struct SourceLink {
enum Quality {
UnknownLocation,
CommentLocation,
DefinitionLocation,
CommentAndDefinitionLocation,
};
Quality quality;
std::string file_path;
u32 line;

friend std::weak_ordering operator<=>(const SourceLink& lhs,
const SourceLink& rhs) noexcept {
return lhs.quality <=> rhs.quality;
}
};
static_assert(sus::cmp::Ord<SourceLink>);

struct Comment {
Comment() = default;
Comment(std::string text, std::string begin_loc, DocAttributes attrs)
Expand Down Expand Up @@ -93,6 +111,7 @@ struct CommentElement {
Comment comment;
std::string name;
u32 sort_key;
sus::Option<SourceLink> source_link;

/// Used during visit to determine if a comment has already been found and
/// applied to the element.
Expand Down
13 changes: 8 additions & 5 deletions subdoc/lib/run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
namespace subdoc {

sus::Result<Database, DiagnosticResults> run_test(
std::string content, sus::Slice<std::string> command_line_args,
std::string pretend_file_name, std::string content,
sus::Slice<std::string> command_line_args,
const RunOptions& options) noexcept {
auto join_args = std::string();
for (const std::string& a : command_line_args) {
Expand All @@ -40,9 +41,11 @@ sus::Result<Database, DiagnosticResults> run_test(
}

auto vfs = llvm::IntrusiveRefCntPtr(new llvm::vfs::InMemoryFileSystem());
vfs->addFile("test.cc", 0, llvm::MemoryBuffer::getMemBuffer(content));
vfs->addFile(pretend_file_name, 0, llvm::MemoryBuffer::getMemBuffer(content));

return run_files(*comp_db, sus::Vec<std::string>("test.cc"), std::move(vfs), options);
return run_files(*comp_db,
sus::Vec<std::string>(sus::move(pretend_file_name)),
std::move(vfs), options);
}

struct DiagnosticTracker : public clang::TextDiagnosticPrinter {
Expand Down Expand Up @@ -109,8 +112,8 @@ sus::Result<Database, DiagnosticResults> run_files(
tool.appendArgumentsAdjuster(adj);

auto cx = VisitCx(options);
auto docs_db =
Database(Comment(sus::clone(options.project_overview_text), "", DocAttributes()));
auto docs_db = Database(
Comment(sus::clone(options.project_overview_text), "", DocAttributes()));
auto visitor_factory = VisitorFactory(cx, docs_db, num_files);

i32 run_value = sus::move(tool).run(&visitor_factory);
Expand Down
3 changes: 2 additions & 1 deletion subdoc/lib/run.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ struct DiagnosticResults {
static_assert(sus::mem::Move<DiagnosticResults>);

sus::Result<Database, DiagnosticResults> run_test(
std::string content, sus::Slice<std::string> command_line_args,
std::string pretend_file_name, std::string content,
sus::Slice<std::string> command_line_args,
const RunOptions& options) noexcept;

sus::Result<Database, DiagnosticResults> run_files(
Expand Down
Loading

0 comments on commit d56aa9c

Please sign in to comment.