Skip to content

Commit e8e68e2

Browse files
tae2089claude
andcommitted
refactor: extract shared ccg ref matcher from CCGRefExists
Pull the node-matching query into ccgRefNodeQuery so lint validation and the upcoming cross-ref materialization judge ccg:// targets identically. No behavior change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent b678d87 commit e8e68e2

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

  • internal/adapters/outbound/graphgorm

internal/adapters/outbound/graphgorm/docs.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"context"
66
"strings"
77

8+
"gorm.io/gorm"
9+
810
docsapp "github.com/tae2089/code-context-graph/internal/app/docs"
911
"github.com/tae2089/code-context-graph/internal/domain/graph"
1012
"github.com/tae2089/code-context-graph/internal/domain/reference"
@@ -73,6 +75,15 @@ func (s *Store) QualifiedNameExists(ctx context.Context, namespace, name string)
7375

7476
// @intent validate parsed cross-namespace ccg references against graph path and symbol semantics.
7577
func (s *Store) CCGRefExists(ctx context.Context, ref reference.Ref) (bool, error) {
78+
var count int64
79+
err := s.ccgRefNodeQuery(ctx, ref).Count(&count).Error
80+
return count > 0, err
81+
}
82+
83+
// ccgRefNodeQuery builds the node query matching a parsed ccg:// reference target.
84+
// @intent keep one matcher for every consumer of ccg ref resolution so lint and cross-ref state never disagree.
85+
// @domainRule a path scope matches the file itself or any file under the path; a symbol scope matches name or qualified-name suffix.
86+
func (s *Store) ccgRefNodeQuery(ctx context.Context, ref reference.Ref) *gorm.DB {
7687
q := s.db.WithContext(ctx).Model(&graph.Node{}).Where("namespace = ?", ref.Namespace)
7788
if ref.Path != "" {
7889
if ref.Symbol != "" {
@@ -83,7 +94,5 @@ func (s *Store) CCGRefExists(ctx context.Context, ref reference.Ref) (bool, erro
8394
} else if ref.Symbol != "" {
8495
q = q.Where("name = ? OR qualified_name = ? OR qualified_name LIKE ? OR qualified_name LIKE ?", ref.Symbol, ref.Symbol, "%."+ref.Symbol, "%::"+ref.Symbol)
8596
}
86-
var count int64
87-
err := q.Count(&count).Error
88-
return count > 0, err
97+
return q
8998
}

0 commit comments

Comments
 (0)