Skip to content

feat(core): Go scanner - methods, receivers, and generics #130

Description

@prosdev

Summary

Extend Go scanner to handle receiver methods and Go generics, enabling full support for modern Go codebases.

Background

Part of Epic #128: Go Language Support
Depends on: #129 (Core Go Scanner)

Tasks

Method Extraction

  • Extract methods with receivers: func (s *Server) Start()
  • Track receiver name in metadata: receiver: "Server"
  • Track pointer vs value receiver: receiverPointer: true
  • Link methods to their struct conceptually

Generics Support

  • Extract generic functions: func TopK[T any](...)
  • Extract generic types: type Embedding[T any] struct
  • Track type parameters in metadata: typeParameters: ["T any"]
  • Flag generic items: isGeneric: true

Go Doc Comments

  • Extract doc comments immediately preceding declarations
  • Handle multi-line doc comments
  • Store in docstring metadata field

Technical Notes

Metadata Schema Extension:

interface GoMetadata extends BaseMetadata {
  receiver?: string;           // "Server" for method receivers
  receiverPointer?: boolean;   // true for *Server
  isGeneric?: boolean;         // true for generic functions/types
  typeParameters?: string[];   // ["T any", "K comparable"]
}

Example Extractions:

Input:

// ExpBackoff helps implement exponential backoff.
type ExpBackoff struct {
    conf *ExpBackoffConf
}

// MarkFailAndGetWait returns wait duration after failure.
func (e *ExpBackoff) MarkFailAndGetWait() time.Duration {
    e.numFailures++
    return e.GetWaitFromFailures(e.numFailures)
}

func TopK[T any](k int, target Embedding[T]) ([]T, error) {
    // ...
}

Output metadata for method:

{
  "name": "ExpBackoff.MarkFailAndGetWait",
  "type": "method",
  "receiver": "ExpBackoff",
  "receiverPointer": true,
  "signature": "func (e *ExpBackoff) MarkFailAndGetWait() time.Duration",
  "docstring": "MarkFailAndGetWait returns wait duration after failure."
}

Acceptance Criteria

  • Methods extracted with receiver information
  • Generic functions and types detected and flagged
  • Doc comments captured for all declaration types
  • Tests cover receiver methods, generics, and doc comments

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    pkg:corepackages/core - indexer, scanner, vectortype:featureNew functionality

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions