@@ -237,6 +237,18 @@ func (g *graph) emitDocument(index *Index, doc *Document) {
237
237
if ok {
238
238
g .emitRelationships (rangeID , documentID , resultIDs , localSymbolInformationTable , symbolInfo )
239
239
}
240
+ // Emit definition relationship info here, because we have access to the rangeID
241
+ // for this definition, which we don't have if we were to try to emit it
242
+ // when emitting it from rel.Symbol. See [NOTE: isDefinition-handling].
243
+ if relationships , ok := g .inverseRelationships [occ .Symbol ]; ok {
244
+ for _ , rel := range relationships {
245
+ if rel .IsDefinition {
246
+ if ids , ok := g .symbolToResultSet [rel .Symbol ]; ok && ids .DefinitionResult > 0 {
247
+ g .emitEdge ("item" , reader.Edge {OutV : ids .DefinitionResult , InVs : []int {rangeID }, Document : documentID })
248
+ }
249
+ }
250
+ }
251
+ }
240
252
}
241
253
// reference
242
254
g .emitEdge ("item" , reader.Edge {OutV : resultIDs .ReferenceResult , InVs : []int {rangeID }, Document : documentID })
@@ -270,6 +282,7 @@ func (g *graph) emitRelationships(rangeID, documentID int, resultIDs *symbolInfo
270
282
func (g * graph ) emitRelationship (relationship * Relationship , rangeID , documentID int , localResultIDs map [string ]* symbolInformationIDs ) []int {
271
283
relationshipIDs := g .getOrInsertSymbolInformationIDs (relationship .Symbol , localResultIDs )
272
284
285
+ var out []int
273
286
if relationship .IsImplementation {
274
287
if relationshipIDs .ImplementationResult < 0 {
275
288
relationshipIDs .ImplementationResult = g .emitVertex ("implementationResult" , nil )
@@ -286,19 +299,14 @@ func (g *graph) emitRelationship(relationship *Relationship, rangeID, documentID
286
299
// The 'property' field is included in the LSIF JSON but it's not present in reader.Element
287
300
// Property: "referenceResults",
288
301
})
289
- return [] int { relationshipIDs .ReferenceResult }
302
+ out = append ( out , relationshipIDs .ReferenceResult )
290
303
}
291
304
292
- if relationship .IsDefinition {
293
- g .emitEdge ("item" , reader.Edge {
294
- OutV : relationshipIDs .DefinitionResult ,
295
- InVs : []int {rangeID },
296
- Document : documentID ,
297
- })
298
- return []int {relationshipIDs .DefinitionResult }
299
- }
305
+ // [NOTE: isDefinition-handling]
306
+ // We can't emit an edge for relationship.IsDefinition here,
307
+ // because we don't have the rangeID for the definition.
300
308
301
- return nil
309
+ return out
302
310
}
303
311
304
312
// emitMonikerVertex emits the "moniker" vertex and optionally the accompanying "packageInformation" vertex.
@@ -387,12 +395,16 @@ func (g *graph) emit(ty, label string, payload any) int {
387
395
func (g * graph ) registerInverseRelationships (info * SymbolInformation ) {
388
396
for _ , relationship := range info .Relationships {
389
397
inverseRelationships := g .inverseRelationships [relationship .Symbol ]
390
- g . inverseRelationships [ relationship . Symbol ] = append ( inverseRelationships , & Relationship {
398
+ rel := Relationship {
391
399
Symbol : info .Symbol ,
392
400
IsReference : relationship .IsReference ,
393
401
IsImplementation : relationship .IsImplementation ,
394
402
IsTypeDefinition : relationship .IsTypeDefinition ,
395
- })
403
+ IsDefinition : relationship .IsDefinition && IsGlobalSymbol (info .Symbol ) && IsGlobalSymbol (relationship .Symbol ),
404
+ }
405
+ if rel .IsReference || rel .IsImplementation || rel .IsTypeDefinition || rel .IsDefinition {
406
+ g .inverseRelationships [relationship .Symbol ] = append (inverseRelationships , & rel )
407
+ }
396
408
}
397
409
}
398
410
0 commit comments