Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 02920ab

Browse files
authored
Merge pull request #249 from smowton/smowton/feature/comment-group-ast-node-parents
Make CommentGroups AST-children of Files
2 parents 650cb5e + 6bf3802 commit 02920ab

14 files changed

Lines changed: 2152 additions & 936 deletions

File tree

extractor/dbscheme/tables.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,9 @@ var HasLocationTable = NewTable("has_location",
706706
// CommentGroupsTable is the table defining comment group entities
707707
var CommentGroupsTable = NewTable("comment_groups",
708708
EntityColumn(CommentGroupType, "id").Key(),
709-
)
709+
EntityColumn(FileType, "parent"),
710+
IntColumn("idx"),
711+
).KeySet("parent", "idx")
710712

711713
// CommentsTable is the table defining comment entities
712714
var CommentsTable = NewTable("comments",

extractor/extractor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,8 @@ func extractFileNode(tw *trap.Writer, nd *ast.File) {
532532
extractDecl(tw, decl, lbl, i)
533533
}
534534

535-
for _, cg := range nd.Comments {
536-
extractCommentGroup(tw, cg)
535+
for i, cg := range nd.Comments {
536+
extractCommentGroup(tw, cg, lbl, i)
537537
}
538538

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

550550
// extractCommentGroup extracts information about a doc comment group
551-
func extractCommentGroup(tw *trap.Writer, cg *ast.CommentGroup) {
551+
func extractCommentGroup(tw *trap.Writer, cg *ast.CommentGroup, parent trap.Label, idx int) {
552552
lbl := tw.Labeler.LocalID(cg)
553-
dbscheme.CommentGroupsTable.Emit(tw, lbl)
553+
dbscheme.CommentGroupsTable.Emit(tw, lbl, parent, idx)
554554
extractNodeLocation(tw, cg, lbl)
555555
for i, c := range cg.List {
556556
extractComment(tw, c, lbl, i)

extractor/gomodextractor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func extractGoModComments(tw *trap.Writer, expr modfile.Expr, exprlbl trap.Label
144144

145145
// extract a pseudo `@commentgroup` for each expr that contains their associated comments
146146
grouplbl := tw.Labeler.LocalID(GoModExprCommentWrapper{expr})
147-
dbscheme.CommentGroupsTable.Emit(tw, grouplbl)
147+
dbscheme.CommentGroupsTable.Emit(tw, grouplbl, tw.Labeler.FileLabel(), 0)
148148
dbscheme.DocCommentsTable.Emit(tw, exprlbl, grouplbl)
149149

150150
var allComments []modfile.Comment

ql/src/go.dbscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ containerparent(int parent: @container ref, unique int child: @container ref);
4949

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

52-
comment_groups(unique int id: @comment_group);
52+
#keyset[parent, idx]
53+
comment_groups(unique int id: @comment_group, int parent: @file ref, int idx: int ref);
5354

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

0 commit comments

Comments
 (0)