Skip to content

Commit 6175171

Browse files
committed
fix: populate global_symbols.relationships in expt-convert
The relationships column was declared in the schema but never written, so every symbol reported no relationships while queries still succeeded -- making type-hierarchy features silently impossible to build on the SQLite output. Serialized like chunks.occurrences: a zstd-compressed wrapper message. Symbols without relationships bind NULL rather than an empty frame. Refs #464
1 parent d7d944f commit 6175171

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

cmd/scip/convert.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,33 @@ func (c *Converter) insertEnclosingRangeData(symbolToID map[string]int64, occs [
420420
return nil
421421
}
422422

423+
// marshalRelationships serializes a symbol's relationships for the
424+
// global_symbols.relationships column, framed the same way Chunk.toDBFormat
425+
// frames chunks.occurrences: a zstd-compressed wrapper message rather than a
426+
// bare repeated field, so the blob stays self-describing.
427+
func (c *Converter) marshalRelationships(rels []*scip.Relationship) ([]byte, error) {
428+
blob, err := proto.Marshal(&scip.SymbolInformation{Relationships: rels})
429+
if err != nil {
430+
return nil, fmt.Errorf("failed to serialize relationships: %w", err)
431+
}
432+
433+
var buf bytes.Buffer
434+
c.zstdWriter.Reset(&buf)
435+
if _, err = c.zstdWriter.Write(blob); err != nil {
436+
return nil, fmt.Errorf("compression error: %w", err)
437+
}
438+
if err = c.zstdWriter.Close(); err != nil {
439+
return nil, fmt.Errorf("flushing encoder: %w", err)
440+
}
441+
return buf.Bytes(), nil
442+
}
443+
423444
func (c *Converter) insertGlobalSymbols(symbol *scip.SymbolInformation) (symbolID int64, err error) {
424445
documentation := strings.Join(symbol.Documentation, "\n")
425446

426447
insertStmt, err := c.conn.Prepare(
427-
`INSERT INTO global_symbols (symbol, display_name, kind, documentation, enclosing_symbol)
428-
VALUES (?, ?, ?, ?, ?)
448+
`INSERT INTO global_symbols (symbol, display_name, kind, documentation, enclosing_symbol, relationships)
449+
VALUES (?, ?, ?, ?, ?, ?)
429450
ON CONFLICT(symbol) DO NOTHING
430451
RETURNING id`)
431452
if err != nil {
@@ -453,6 +474,19 @@ func (c *Converter) insertGlobalSymbols(symbol *scip.SymbolInformation) (symbolI
453474
} else {
454475
insertStmt.BindText(5, symbol.EnclosingSymbol)
455476
}
477+
// Bind NULL rather than an empty frame when there are no relationships:
478+
// insertGlobalSymbols is also called with synthetic SymbolInformation
479+
// values carrying only a Symbol, and a compressed empty message would make
480+
// "no relationships" indistinguishable from "present but empty".
481+
if len(symbol.Relationships) == 0 {
482+
insertStmt.BindNull(6)
483+
} else {
484+
relationshipsBlob, err := c.marshalRelationships(symbol.Relationships)
485+
if err != nil {
486+
return 0, err
487+
}
488+
insertStmt.BindBytes(6, relationshipsBlob)
489+
}
456490

457491
if _, err = insertStmt.Step(); err != nil {
458492
return 0, fmt.Errorf("failed to insert symbol %s: %w", symbol.Symbol, err)

0 commit comments

Comments
 (0)