@@ -36,6 +36,8 @@ type AnnotatingParser interface {
3636 Language () string
3737}
3838
39+ // annotationWriter is the optional store capability needed to persist comment-derived annotations.
40+ // @intent allow incremental sync to skip annotation writes when the underlying store does not support them.
3941type annotationWriter interface {
4042 UpsertAnnotation (ctx context.Context , ann * model.Annotation ) error
4143}
@@ -66,6 +68,9 @@ type Syncer struct {
6668 logger * slog.Logger
6769}
6870
71+ // releaseContent drops the in-memory file content for one path so the sync loop can free memory early.
72+ // @intent prevent the FileInfo map from holding all source bytes after a file has been processed.
73+ // @mutates files[filePath].Content
6974func releaseContent (files map [string ]FileInfo , filePath string ) {
7075 info , ok := files [filePath ]
7176 if ! ok {
@@ -147,6 +152,10 @@ func (s *Syncer) SyncWithExistingStore(ctx context.Context, syncStore Store, fil
147152 return s .syncWithExisting (ctx , syncStore , files , existingFiles )
148153}
149154
155+ // syncWithExisting performs the actual diff-and-apply pass against the supplied store.
156+ // @intent compare hashes for known files, parse new/changed ones, and remove deleted entries in one pass.
157+ // @sideEffect upserts nodes/edges/annotations and deletes removed files through syncStore.
158+ // @mutates graph nodes, edges, annotations
150159func (s * Syncer ) syncWithExisting (ctx context.Context , syncStore Store , files map [string ]FileInfo , existingFiles []string ) (* SyncStats , error ) {
151160 stats := & SyncStats {}
152161
@@ -242,6 +251,8 @@ func (s *Syncer) syncWithExisting(ctx context.Context, syncStore Store, files ma
242251 return stats , nil
243252}
244253
254+ // resolveParser picks an extension-specific parser when configured, otherwise the legacy single parser.
255+ // @intent let multi-language projects sync without losing the single-parser fallback for callers using New.
245256func (s * Syncer ) resolveParser (filePath string ) Parser {
246257 if len (s .parsers ) > 0 {
247258 ext := strings .ToLower (filepath .Ext (filePath ))
@@ -252,6 +263,10 @@ func (s *Syncer) resolveParser(filePath string) Parser {
252263 return s .parser
253264}
254265
266+ // restoreAnnotations re-binds parsed comment blocks to the freshly persisted nodes for one file.
267+ // @intent keep doc comments associated with their owning declarations after incremental reparses.
268+ // @sideEffect upserts annotation rows through the store's annotation writer.
269+ // @mutates graph annotations
255270func (s * Syncer ) restoreAnnotations (ctx context.Context , syncStore Store , filePath string , content []byte , nodes []model.Node , comments []treesitter.CommentBlock , language string ) error {
256271 writer , ok := syncStore .(annotationWriter )
257272 if ! ok || language == "" {
@@ -298,6 +313,8 @@ func (s *Syncer) restoreAnnotations(ctx context.Context, syncStore Store, filePa
298313 return nil
299314}
300315
316+ // annotationBindingKey produces a stable lookup key combining qualified name and start line.
317+ // @intent disambiguate overloaded or repeated declarations sharing the same qualified name.
301318func annotationBindingKey (qualifiedName string , startLine int ) string {
302319 return qualifiedName + ":" + strconv .Itoa (startLine )
303320}
0 commit comments