Skip to content

Commit 0dd8fd6

Browse files
authored
Merge pull request #52 from sourcegraph/olafurpg/scip
Upgrade to scip-java from lsif-java
2 parents 9909418 + f0a006b commit 0dd8fd6

File tree

10 files changed

+49
-34
lines changed

10 files changed

+49
-34
lines changed

.github/workflows/pr-auditor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- uses: actions/checkout@v2
1111
with: { repository: 'sourcegraph/sourcegraph' }
1212
- uses: actions/setup-go@v2
13-
with: { go-version: '1.17' }
13+
with: { go-version: '1.18' }
1414

1515
- run: ./dev/pr-auditor/check-pr.sh
1616
env:

.github/workflows/sourcegraph.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ jobs:
1313
- uses: coursier/[email protected]
1414
with:
1515
jvm: adopt:8
16-
apps: lsif-java
17-
- run: lsif-java index
18-
- name: Upload LSIF data
19-
uses: sourcegraph/lsif-upload-action@master
20-
with:
21-
endpoint: https://sourcegraph.com
22-
github_token: ${{ secrets.GITHUB_TOKEN }}
23-
file: dump.lsif
16+
- run: |
17+
cs launch com.sourcegraph:scip-java_2.13:latest.stable -M com.sourcegraph.scip_java.ScipJava -- index
18+
- run: yarn global add @sourcegraph/src
19+
- run: |
20+
src code-intel upload "-commit=${GITHUB_SHA}" "-github-token=${GITHUB_TOKEN}"
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ out/
5151
*.hnir
5252
test-report.json
5353
dump.lsif
54+
index.scip

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ enablePlugins(ScriptedPlugin)
7979
scriptedBufferLog := false
8080
scriptedLaunchOpts ++= Seq(
8181
"-Xmx2048M",
82+
s"-Dscip-java.version=${Versions.semanticdbJavacVersion()}",
8283
s"-Dplugin.version=${version.value}"
8384
)
8485

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ sbt sourcegraphUpload
136136

137137
**Tasks**:
138138

139-
- `sourcegraphLsif`: compiles all projects in the build and generates an LSIF
139+
- `sourcegraphCompile`: compiles all projects in the build and generates an LSIF
140140
index from the compiled SemanticDB files.
141141
- `sourcegraphUpload`: uploads the LSIF index from `sourcegraphLsif` to
142142
Sourcegraph.

src/main/scala/com/sourcegraph/sbtsourcegraph/SourcegraphPlugin.scala

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ object SourcegraphPlugin extends AutoPlugin {
1919
"Task to upload the LSIF index to Sourcegraph to enable precise code intelligence."
2020
)
2121
val sourcegraphLsif: TaskKey[File] =
22+
taskKey[File]("Alias for the sourcegraphCompile command.")
23+
val sourcegraphScip: TaskKey[File] =
24+
taskKey[File]("Alias for the sourcegraphCompile command.")
25+
val sourcegraphCompile: TaskKey[File] =
2226
taskKey[File](
2327
"Task to generate a single LSIF index for all SemanticDB files in this workspace."
2428
)
@@ -30,8 +34,8 @@ object SourcegraphPlugin extends AutoPlugin {
3034
taskKey[File](
3135
"Task to generate a single LSIF index for all SemanticDB files in this workspace."
3236
)
33-
val sourcegraphLsifJavaVersion: SettingKey[String] =
34-
settingKey[String]("The version of the `lsif-java` command-line tool.")
37+
val sourcegraphScipJavaVersion: SettingKey[String] =
38+
settingKey[String]("The version of the `scip-java` command-line tool.")
3539
val sourcegraphSemanticdbDirectories: TaskKey[List[File]] =
3640
taskKey[List[File]](
3741
"Task to compile all projects in this build and aggregate all SemanticDB directories."
@@ -79,9 +83,9 @@ object SourcegraphPlugin extends AutoPlugin {
7983
import autoImport._
8084

8185
override lazy val buildSettings: Seq[Def.Setting[_]] = List(
82-
sourcegraphLsifJavaVersion := {
86+
sourcegraphScipJavaVersion := {
8387
scala.util.Properties
84-
.propOrElse("lsif-java-version", Versions.semanticdbJavacVersion())
88+
.propOrElse("scip-java-version", Versions.semanticdbJavacVersion())
8589
},
8690
sourcegraphTargetRoots := {
8791
val directories =
@@ -93,7 +97,7 @@ object SourcegraphPlugin extends AutoPlugin {
9397
if (directoryArguments.isEmpty) {
9498
throw new TaskException(
9599
"Can't upload LSIF index to Sourcegraph because there are no SemanticDB directories. " +
96-
"To fix this problem, run the `sourcegraphEnable` command before `sourcegraphLsif` like this: sbt sourcegraphEnable sourcegraphLsif"
100+
"To fix this problem, run the `sourcegraphEnable` command before `sourcegraphCompile` like this: sbt sourcegraphEnable sourcegraphCompile"
97101
)
98102
}
99103
directoryArguments
@@ -110,14 +114,17 @@ object SourcegraphPlugin extends AutoPlugin {
110114
)
111115
out
112116
},
113-
sourcegraphLsif := {
114-
val out = target.in(Sourcegraph).value / "dump.lsif"
117+
sourcegraphLsif := sourcegraphCompile.value,
118+
sourcegraphScip := sourcegraphCompile.value,
119+
sourcegraphCompile := {
120+
val out = target.in(Sourcegraph).value / "index.scip"
115121
out.getParentFile.mkdirs()
116122
runProcess(
117123
sourcegraphCoursierBinary.value ::
118124
"launch" ::
119-
"--contrib" ::
120-
s"lsif-java:${sourcegraphLsifJavaVersion.value}" ::
125+
s"com.sourcegraph:scip-java_2.13:${sourcegraphScipJavaVersion.value}" ::
126+
"-M" ::
127+
"com.sourcegraph.scip_java.ScipJava" ::
121128
"--" ::
122129
"index-semanticdb" ::
123130
s"--output=$out" ::
@@ -134,11 +141,11 @@ object SourcegraphPlugin extends AutoPlugin {
134141
"in https://github.com/sourcegraph/sbt-sourcegraph/blob/main/README.md"
135142
)
136143
}
137-
val in = sourcegraphLsif.value
144+
val in = sourcegraphCompile.value
138145
val uploadCommand = List[Option[String]](
139146
Some(sourcegraphSrcBinary.value),
140147
sourcegraphEndpoint.value.map(url => s"--endpoint=$url"),
141-
Some("lsif"),
148+
Some("code-intel"),
142149
Some("upload"),
143150
Option(System.getenv("GITHUB_TOKEN"))
144151
.map(token => s"--github-token=$token"),

src/main/scala/com/sourcegraph/sbtsourcegraph/Versions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object Versions {
2525
props.asScala.toMap
2626
} else {
2727
Map(
28-
semanticdbJavacKey -> "0.6.3",
28+
semanticdbJavacKey -> "0.8.0",
2929
"2.12.12" -> scalametaVersion,
3030
"2.13.6" -> scalametaVersion,
3131
"2.11.12" -> scalametaVersion

src/sbt-test/sbt-sourcegraph/basic/build.sbt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,27 @@ lazy val b = project
2020

2121
commands += Command.command("checkLsif") { s =>
2222
val dumpPath =
23-
(ThisBuild / baseDirectory).value / "target" / "sbt-sourcegraph" / "dump.lsif"
24-
val dump = Files.readAllLines(dumpPath.toPath).asScala
25-
val packageInformation =
26-
""".*"name":"(.*)","manager":"jvm-dependencies"}""".r
27-
val jvmDependencies = dump
28-
.collect { case packageInformation(name) =>
29-
name
30-
}
23+
(ThisBuild / baseDirectory).value / "target" / "sbt-sourcegraph" / "index.scip"
24+
val index =
25+
lib.codeintel.scip.Scip.Index.parseFrom(Files.readAllBytes(dumpPath.toPath))
26+
val packageNames = index.getDocumentsList.asScala
27+
.flatMap(_.getOccurrencesList.asScala)
28+
.map(_.getSymbol)
29+
.filterNot(_.startsWith("local"))
30+
.map(_.split(" ").toList)
31+
.collect { case _ :: _ :: name :: _ => name }
32+
.filterNot(_ == ".")
3133
.distinct
3234
.sorted
3335
if (
34-
jvmDependencies != List(
36+
packageNames != List(
3537
"jdk",
3638
"maven/com.lihaoyi/geny_2.12",
3739
"maven/junit/junit",
3840
"maven/org.scala-lang/scala-library"
3941
)
4042
) {
41-
sys.error(jvmDependencies.toString)
43+
sys.error(packageNames.toString)
4244
}
4345
s
4446
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
addSbtPlugin("com.sourcegraph" % "sbt-sourcegraph" % sys.props("plugin.version"))
1+
addSbtPlugin(
2+
"com.sourcegraph" % "sbt-sourcegraph" % sys.props("plugin.version")
3+
)
4+
5+
libraryDependencies += "com.sourcegraph" % "scip-semanticdb" %
6+
sys.props("scip-java.version")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
> sourcegraphEnable
2-
> sourcegraphLsif
2+
> sourcegraphCompile
33
> checkLsif

0 commit comments

Comments
 (0)