@@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets
55import java .nio .file .Files
66import java .nio .file .Path
77import java .nio .file .Paths
8+ import java .util .concurrent .atomic .AtomicInteger
89import java .util .stream .Collectors
910import java .util .stream .Stream
1011
@@ -118,17 +119,23 @@ object SnapshotLsifCommand {
118119 .predecessors(o)
119120 .asScala
120121 .exists(_.getLabel == " definitionResult" )
122+ val isSyntheticDefinition = isDefinition && ! lsif.next.contains(o.getId)
121123 val role =
122- if (isDefinition)
124+ if (isSyntheticDefinition)
125+ Role .SYNTHETIC_DEFINITION
126+ else if (isDefinition)
123127 Role .DEFINITION
124128 else
125129 Role .REFERENCE
126130
127131 val symbol = lsif
128132 .symbolFromRange(o)
133+ .orElse(lsif.monikerViaDefinition(o))
129134 .getOrElse {
130- val id = lsif.next.getOrElse(o.getId, o.getId)
131- s " missingMoniker $id"
135+ val id = lsif
136+ .next
137+ .getOrElse(o.getId, lsif.nextMissingMonikerId(doc.getUri))
138+ s " localMissingMoniker $id"
132139 }
133140 val occ = SymbolOccurrence
134141 .newBuilder()
@@ -147,15 +154,7 @@ object SnapshotLsifCommand {
147154 doc.addOccurrences(occ)
148155
149156 if (isDefinition) {
150- val hover =
151- (
152- for {
153- resultSetId <- lsif.next.get(o.getId).toList
154- hoverId <- lsif.hoverEdges.get(resultSetId).toList
155- hover <- lsif.hoverVertexes.get(hoverId).toList
156- line <- signatureLines(hover.getContents.getValue)
157- } yield line
158- ).mkString(" \n " )
157+ val hover = lsif.hoverViaDefinition(o)
159158 val symInfo = SymbolInformation
160159 .newBuilder()
161160 // we cheese it a bit here, as this is less work than trying to reconstruct
@@ -184,6 +183,11 @@ object SnapshotLsifCommand {
184183 ) {
185184 val documents = mutable.Map .empty[Int , TextDocument .Builder ]
186185 val next = mutable.Map .empty[Int , Int ]
186+ private val missingMonikerCounter = mutable.Map .empty[String , AtomicInteger ]
187+ def nextMissingMonikerId (uri : String ) =
188+ missingMonikerCounter
189+ .getOrElseUpdate(uri, new AtomicInteger ())
190+ .incrementAndGet()
187191 val monikerIdentifier = mutable.Map .empty[Int , String ]
188192 val moniker = mutable.Map .empty[Int , Int ]
189193 val monikerInverse = mutable.Map .empty[Int , Int ]
@@ -378,6 +382,35 @@ object SnapshotLsifCommand {
378382 S .build()
379383 }
380384
385+ def definitioResultSet (node : LsifObject ): Option [LsifObject ] = {
386+ for {
387+ definitionResult <- G .predecessors(node).asScala
388+ if definitionResult.getLabel == " definitionResult"
389+ resultSet <- G .predecessors(definitionResult).asScala
390+ if resultSet.getLabel == " resultSet"
391+ } yield resultSet
392+ }.headOption
393+
394+ def monikerViaDefinition (node : LsifObject ): Option [String ] = {
395+ for {
396+ resultSet <- definitioResultSet(node).toList
397+ moniker <- G .successors(resultSet).asScala
398+ if moniker.getLabel == " moniker"
399+ } yield moniker.getIdentifier
400+ }.headOption
401+
402+ def hoverViaDefinition (node : LsifObject ): String = {
403+ for {
404+ resultSet <- definitioResultSet(node).toList
405+ hover <-
406+ G .successors(resultSet)
407+ .asScala
408+ .find(_.getLabel == " hoverResult" )
409+ .toList
410+ line <- signatureLines(hover.getResult.getContents.getValue)
411+ } yield line
412+ }.mkString(" \n " )
413+
381414 val byId = objects.iterator.map(o => o.getId -> o).toMap
382415 val byType = objects.groupBy(_.getType)
383416 val byLabel = objects.groupBy(_.getLabel)
0 commit comments