-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a regression where the SCIP index contained invalid symbols
Uploading an index with scip-java v0.8.17 results in the following error in the Sourcegraph UI ``` codeNavSvc.GetImplementations: lsifStore.MonikersByPosition: reached end of symbol while parsing <scheme>, expected a ' ' character minimized/Issue413Subclass#c. _____________________________^ ``` The problem is that this release introduced a regression where scip-java emitted invalid SCIP symbols. This PR fixes the issue, and adds new checks in the testing infrastructure to prevent this kind of regression from happening again.
- Loading branch information
Showing
27 changed files
with
246 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
scip-java/src/main/scala/com/sourcegraph/scip_java/ScipSymbol.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.sourcegraph.scip_java | ||
|
||
import com.sourcegraph.scip_semanticdb.SymbolDescriptor | ||
import com.sourcegraph.semanticdb_javac.SemanticdbSymbols | ||
|
||
sealed abstract class ScipSymbol {} | ||
final case class LocalScipSymbol(identifier: String) extends ScipSymbol | ||
final case class GlobalScipSymbol( | ||
scheme: String, | ||
packageManager: String, | ||
packageName: String, | ||
packageVersion: String, | ||
descriptors: List[SymbolDescriptor] | ||
) extends ScipSymbol | ||
|
||
object ScipSymbol { | ||
|
||
def parseOrThrowExceptionIfInvalid(scipSymbol: String): ScipSymbol = { | ||
if (scipSymbol.startsWith("local ")) { | ||
LocalScipSymbol(scipSymbol.stripPrefix("local ")) | ||
} else { | ||
scipSymbol.split(" ", 5) match { | ||
case Array( | ||
scheme, | ||
packageManager, | ||
packageName, | ||
packageVersion, | ||
descriptor | ||
) => | ||
GlobalScipSymbol( | ||
scheme, | ||
packageManager, | ||
packageName, | ||
packageVersion, | ||
parseDescriptors(descriptor) | ||
) | ||
case _ => | ||
throw new IllegalArgumentException( | ||
s"Invalid scip symbol: $scipSymbol" | ||
) | ||
} | ||
} | ||
} | ||
|
||
private def parseDescriptors( | ||
semanticdbSymbol: String | ||
): List[SymbolDescriptor] = { | ||
val descriptor = SymbolDescriptor.parseFromSymbol(semanticdbSymbol) | ||
if (descriptor.owner == SemanticdbSymbols.ROOT_PACKAGE) | ||
Nil | ||
else | ||
descriptor :: parseDescriptors(descriptor.owner) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.