Skip to content

Commit d8ed060

Browse files
Extract names from var/const declarations in Go
var_declaration and const_declaration nodes contain spec children (var_spec, const_spec) with name fields. The Go name extractor now handles these the same way as type_declaration, so nested diffs show 'var_declaration storeLine' instead of '_var_declaration_25'.
1 parent 4b0cd4c commit d8ed060

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

pkg/github/structural_diff.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,10 @@ func defaultNameExtractor(node *sitter.Node, source []byte) string {
295295
return ""
296296
}
297297

298-
// goNameExtractor handles Go-specific naming (method receivers, type specs).
298+
// goNameExtractor handles Go-specific naming (method receivers, type/var/const specs).
299299
func goNameExtractor(node *sitter.Node, source []byte) string {
300300
switch node.Type() {
301301
case "method_declaration":
302-
// Include receiver type: (r *Receiver) MethodName
303302
nameNode := node.ChildByFieldName("name")
304303
if nameNode == nil {
305304
return ""
@@ -310,15 +309,13 @@ func goNameExtractor(node *sitter.Node, source []byte) string {
310309
return fmt.Sprintf("(%s).%s", extractReceiverType(receiver, source), name)
311310
}
312311
return name
313-
case "type_declaration":
314-
// type_declaration contains type_spec children
312+
case "type_declaration", "var_declaration", "const_declaration":
313+
// These contain spec children (type_spec, var_spec, const_spec) with name fields
315314
for i := 0; i < int(node.ChildCount()); i++ {
316315
child := node.Child(i)
317-
if child.Type() == "type_spec" {
318-
nameNode := child.ChildByFieldName("name")
319-
if nameNode != nil {
320-
return nameNode.Content(source)
321-
}
316+
nameNode := child.ChildByFieldName("name")
317+
if nameNode != nil {
318+
return nameNode.Content(source)
322319
}
323320
}
324321
return ""

0 commit comments

Comments
 (0)