Skip to content

Commit

Permalink
Merge pull request #52 from sourcegraph/olafurpg/scip
Browse files Browse the repository at this point in the history
Upgrade to scip-java from lsif-java
  • Loading branch information
olafurpg authored Jun 10, 2022
2 parents 9909418 + f0a006b commit 0dd8fd6
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-auditor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
with: { repository: 'sourcegraph/sourcegraph' }
- uses: actions/setup-go@v2
with: { go-version: '1.17' }
with: { go-version: '1.18' }

- run: ./dev/pr-auditor/check-pr.sh
env:
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/sourcegraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ jobs:
- uses: coursier/[email protected]
with:
jvm: adopt:8
apps: lsif-java
- run: lsif-java index
- name: Upload LSIF data
uses: sourcegraph/lsif-upload-action@master
with:
endpoint: https://sourcegraph.com
github_token: ${{ secrets.GITHUB_TOKEN }}
file: dump.lsif
- run: |
cs launch com.sourcegraph:scip-java_2.13:latest.stable -M com.sourcegraph.scip_java.ScipJava -- index
- run: yarn global add @sourcegraph/src
- run: |
src code-intel upload "-commit=${GITHUB_SHA}" "-github-token=${GITHUB_TOKEN}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ out/
*.hnir
test-report.json
dump.lsif
index.scip
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ enablePlugins(ScriptedPlugin)
scriptedBufferLog := false
scriptedLaunchOpts ++= Seq(
"-Xmx2048M",
s"-Dscip-java.version=${Versions.semanticdbJavacVersion()}",
s"-Dplugin.version=${version.value}"
)

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ sbt sourcegraphUpload

**Tasks**:

- `sourcegraphLsif`: compiles all projects in the build and generates an LSIF
- `sourcegraphCompile`: compiles all projects in the build and generates an LSIF
index from the compiled SemanticDB files.
- `sourcegraphUpload`: uploads the LSIF index from `sourcegraphLsif` to
Sourcegraph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ object SourcegraphPlugin extends AutoPlugin {
"Task to upload the LSIF index to Sourcegraph to enable precise code intelligence."
)
val sourcegraphLsif: TaskKey[File] =
taskKey[File]("Alias for the sourcegraphCompile command.")
val sourcegraphScip: TaskKey[File] =
taskKey[File]("Alias for the sourcegraphCompile command.")
val sourcegraphCompile: TaskKey[File] =
taskKey[File](
"Task to generate a single LSIF index for all SemanticDB files in this workspace."
)
Expand All @@ -30,8 +34,8 @@ object SourcegraphPlugin extends AutoPlugin {
taskKey[File](
"Task to generate a single LSIF index for all SemanticDB files in this workspace."
)
val sourcegraphLsifJavaVersion: SettingKey[String] =
settingKey[String]("The version of the `lsif-java` command-line tool.")
val sourcegraphScipJavaVersion: SettingKey[String] =
settingKey[String]("The version of the `scip-java` command-line tool.")
val sourcegraphSemanticdbDirectories: TaskKey[List[File]] =
taskKey[List[File]](
"Task to compile all projects in this build and aggregate all SemanticDB directories."
Expand Down Expand Up @@ -79,9 +83,9 @@ object SourcegraphPlugin extends AutoPlugin {
import autoImport._

override lazy val buildSettings: Seq[Def.Setting[_]] = List(
sourcegraphLsifJavaVersion := {
sourcegraphScipJavaVersion := {
scala.util.Properties
.propOrElse("lsif-java-version", Versions.semanticdbJavacVersion())
.propOrElse("scip-java-version", Versions.semanticdbJavacVersion())
},
sourcegraphTargetRoots := {
val directories =
Expand All @@ -93,7 +97,7 @@ object SourcegraphPlugin extends AutoPlugin {
if (directoryArguments.isEmpty) {
throw new TaskException(
"Can't upload LSIF index to Sourcegraph because there are no SemanticDB directories. " +
"To fix this problem, run the `sourcegraphEnable` command before `sourcegraphLsif` like this: sbt sourcegraphEnable sourcegraphLsif"
"To fix this problem, run the `sourcegraphEnable` command before `sourcegraphCompile` like this: sbt sourcegraphEnable sourcegraphCompile"
)
}
directoryArguments
Expand All @@ -110,14 +114,17 @@ object SourcegraphPlugin extends AutoPlugin {
)
out
},
sourcegraphLsif := {
val out = target.in(Sourcegraph).value / "dump.lsif"
sourcegraphLsif := sourcegraphCompile.value,
sourcegraphScip := sourcegraphCompile.value,
sourcegraphCompile := {
val out = target.in(Sourcegraph).value / "index.scip"
out.getParentFile.mkdirs()
runProcess(
sourcegraphCoursierBinary.value ::
"launch" ::
"--contrib" ::
s"lsif-java:${sourcegraphLsifJavaVersion.value}" ::
s"com.sourcegraph:scip-java_2.13:${sourcegraphScipJavaVersion.value}" ::
"-M" ::
"com.sourcegraph.scip_java.ScipJava" ::
"--" ::
"index-semanticdb" ::
s"--output=$out" ::
Expand All @@ -134,11 +141,11 @@ object SourcegraphPlugin extends AutoPlugin {
"in https://github.com/sourcegraph/sbt-sourcegraph/blob/main/README.md"
)
}
val in = sourcegraphLsif.value
val in = sourcegraphCompile.value
val uploadCommand = List[Option[String]](
Some(sourcegraphSrcBinary.value),
sourcegraphEndpoint.value.map(url => s"--endpoint=$url"),
Some("lsif"),
Some("code-intel"),
Some("upload"),
Option(System.getenv("GITHUB_TOKEN"))
.map(token => s"--github-token=$token"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object Versions {
props.asScala.toMap
} else {
Map(
semanticdbJavacKey -> "0.6.3",
semanticdbJavacKey -> "0.8.0",
"2.12.12" -> scalametaVersion,
"2.13.6" -> scalametaVersion,
"2.11.12" -> scalametaVersion
Expand Down
22 changes: 12 additions & 10 deletions src/sbt-test/sbt-sourcegraph/basic/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,27 @@ lazy val b = project

commands += Command.command("checkLsif") { s =>
val dumpPath =
(ThisBuild / baseDirectory).value / "target" / "sbt-sourcegraph" / "dump.lsif"
val dump = Files.readAllLines(dumpPath.toPath).asScala
val packageInformation =
""".*"name":"(.*)","manager":"jvm-dependencies"}""".r
val jvmDependencies = dump
.collect { case packageInformation(name) =>
name
}
(ThisBuild / baseDirectory).value / "target" / "sbt-sourcegraph" / "index.scip"
val index =
lib.codeintel.scip.Scip.Index.parseFrom(Files.readAllBytes(dumpPath.toPath))
val packageNames = index.getDocumentsList.asScala
.flatMap(_.getOccurrencesList.asScala)
.map(_.getSymbol)
.filterNot(_.startsWith("local"))
.map(_.split(" ").toList)
.collect { case _ :: _ :: name :: _ => name }
.filterNot(_ == ".")
.distinct
.sorted
if (
jvmDependencies != List(
packageNames != List(
"jdk",
"maven/com.lihaoyi/geny_2.12",
"maven/junit/junit",
"maven/org.scala-lang/scala-library"
)
) {
sys.error(jvmDependencies.toString)
sys.error(packageNames.toString)
}
s
}
7 changes: 6 additions & 1 deletion src/sbt-test/sbt-sourcegraph/basic/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
addSbtPlugin("com.sourcegraph" % "sbt-sourcegraph" % sys.props("plugin.version"))
addSbtPlugin(
"com.sourcegraph" % "sbt-sourcegraph" % sys.props("plugin.version")
)

libraryDependencies += "com.sourcegraph" % "scip-semanticdb" %
sys.props("scip-java.version")
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-sourcegraph/basic/test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
> sourcegraphEnable
> sourcegraphLsif
> sourcegraphCompile
> checkLsif

0 comments on commit 0dd8fd6

Please sign in to comment.