@@ -237,6 +237,18 @@ func (g *graph) emitDocument(index *Index, doc *Document) {
237237 if ok {
238238 g .emitRelationships (rangeID , documentID , resultIDs , localSymbolInformationTable , symbolInfo )
239239 }
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+ }
240252 }
241253 // reference
242254 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
270282func (g * graph ) emitRelationship (relationship * Relationship , rangeID , documentID int , localResultIDs map [string ]* symbolInformationIDs ) []int {
271283 relationshipIDs := g .getOrInsertSymbolInformationIDs (relationship .Symbol , localResultIDs )
272284
285+ var out []int
273286 if relationship .IsImplementation {
274287 if relationshipIDs .ImplementationResult < 0 {
275288 relationshipIDs .ImplementationResult = g .emitVertex ("implementationResult" , nil )
@@ -286,19 +299,14 @@ func (g *graph) emitRelationship(relationship *Relationship, rangeID, documentID
286299 // The 'property' field is included in the LSIF JSON but it's not present in reader.Element
287300 // Property: "referenceResults",
288301 })
289- return [] int { relationshipIDs .ReferenceResult }
302+ out = append ( out , relationshipIDs .ReferenceResult )
290303 }
291304
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.
300308
301- return nil
309+ return out
302310}
303311
304312// 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 {
387395func (g * graph ) registerInverseRelationships (info * SymbolInformation ) {
388396 for _ , relationship := range info .Relationships {
389397 inverseRelationships := g .inverseRelationships [relationship .Symbol ]
390- g . inverseRelationships [ relationship . Symbol ] = append ( inverseRelationships , & Relationship {
398+ rel := Relationship {
391399 Symbol : info .Symbol ,
392400 IsReference : relationship .IsReference ,
393401 IsImplementation : relationship .IsImplementation ,
394402 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+ }
396408 }
397409}
398410
0 commit comments