Skip to content

Commit 4c257c4

Browse files
committed
Make snapshot-lsif command more LSIF-compliant
Previously, the snapshot command assumed that monikers had an incoming edge from a result set. However, LSIF allows the moniker edge to come from the range vertex, and it also permits recursive result sets. This commit updates the snapshot command so that it computes monikers according to the spec.
1 parent 3109c97 commit 4c257c4

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

lsif-java/src/main/scala/com/sourcegraph/lsif_java/commands/SnapshotLsifCommand.scala

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,11 @@ object SnapshotLsifCommand {
114114
else
115115
Role.REFERENCE
116116

117-
val symbol =
118-
(
119-
for {
120-
resultSetId <- lsif.next.get(o.getId)
121-
monikerId <- lsif.moniker.get(resultSetId)
122-
moniker <- lsif.monikerIdentifier.get(monikerId)
123-
} yield moniker
124-
).getOrElse {
117+
val symbol = lsif
118+
.symbolFromRange(o)
119+
.getOrElse {
125120
val id = lsif.next.getOrElse(o.getId, o.getId)
126-
s"local$id"
121+
s"missingMoniker$id"
127122
}
128123
val occ = SymbolOccurrence
129124
.newBuilder()
@@ -189,6 +184,20 @@ object SnapshotLsifCommand {
189184
def textDocument(id: Int): TextDocument.Builder = {
190185
documents.getOrElseUpdate(id, TextDocument.newBuilder())
191186
}
187+
def symbolFromRange(o: LsifObject): Option[String] = {
188+
val moniker =
189+
for {
190+
monikerId <- this.moniker.get(o.getId())
191+
moniker <- this.monikerIdentifier.get(monikerId)
192+
} yield moniker
193+
moniker.orElse {
194+
for {
195+
resultSetId <- this.next.get(o.getId())
196+
resultSet <- this.byId.get(resultSetId)
197+
fromResultSet <- symbolFromRange(resultSet)
198+
} yield fromResultSet
199+
}
200+
}
192201

193202
val monikers: Map[String, LsifObject] =
194203
objects

0 commit comments

Comments
 (0)