Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion extractor/dbscheme/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,9 @@ var HasLocationTable = NewTable("has_location",
// CommentGroupsTable is the table defining comment group entities
var CommentGroupsTable = NewTable("comment_groups",
EntityColumn(CommentGroupType, "id").Key(),
)
EntityColumn(FileType, "parent"),
IntColumn("idx"),
).KeySet("parent", "idx")

// CommentsTable is the table defining comment entities
var CommentsTable = NewTable("comments",
Expand Down
8 changes: 4 additions & 4 deletions extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@ func extractFileNode(tw *trap.Writer, nd *ast.File) {
extractDecl(tw, decl, lbl, i)
}

for _, cg := range nd.Comments {
extractCommentGroup(tw, cg)
for i, cg := range nd.Comments {
extractCommentGroup(tw, cg, lbl, i)
}

extractDoc(tw, nd.Doc, lbl)
Expand All @@ -548,9 +548,9 @@ func extractDoc(tw *trap.Writer, doc *ast.CommentGroup, elt trap.Label) {
}

// extractCommentGroup extracts information about a doc comment group
func extractCommentGroup(tw *trap.Writer, cg *ast.CommentGroup) {
func extractCommentGroup(tw *trap.Writer, cg *ast.CommentGroup, parent trap.Label, idx int) {
lbl := tw.Labeler.LocalID(cg)
dbscheme.CommentGroupsTable.Emit(tw, lbl)
dbscheme.CommentGroupsTable.Emit(tw, lbl, parent, idx)
extractNodeLocation(tw, cg, lbl)
for i, c := range cg.List {
extractComment(tw, c, lbl, i)
Expand Down
2 changes: 1 addition & 1 deletion extractor/gomodextractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func extractGoModComments(tw *trap.Writer, expr modfile.Expr, exprlbl trap.Label

// extract a pseudo `@commentgroup` for each expr that contains their associated comments
grouplbl := tw.Labeler.LocalID(GoModExprCommentWrapper{expr})
dbscheme.CommentGroupsTable.Emit(tw, grouplbl)
dbscheme.CommentGroupsTable.Emit(tw, grouplbl, tw.Labeler.FileLabel(), 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smowton, looking at this code again, wouldn't this put every comment group in a go.mod file at index zero?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damnit, I thought this was called once per file, whereas actually it hits the toplevel comments and also comments relating to each expr.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, would be good to fix that, since our dbscheme claims that the tuple (file, index) functionally determines the comment group.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that

// some doc comment
require blah

Associated that comment with the require line, so it would be possible to have multiple. I hadn't actually tested this theory, though.

dbscheme.DocCommentsTable.Emit(tw, exprlbl, grouplbl)

var allComments []modfile.Comment
Expand Down
3 changes: 2 additions & 1 deletion ql/src/go.dbscheme
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ containerparent(int parent: @container ref, unique int child: @container ref);

has_location(unique int locatable: @locatable ref, int location: @location ref);

comment_groups(unique int id: @comment_group);
#keyset[parent, idx]
comment_groups(unique int id: @comment_group, int parent: @file ref, int idx: int ref);

comments(unique int id: @comment, int kind: int ref, int parent: @comment_group ref, int idx: int ref, string text: string ref);

Expand Down
Loading