Skip to content

Commit 2f4decb

Browse files
committed
Emit SCIP shards directly from plugins
semanticdb-javac and semanticdb-kotlinc now write per-source *.scip shards under META-INF/scip/; scip-semanticdb merges shards and rewrites symbol package coordinates. SemanticDB proto, *.semanticdb files, and the SignatureFormatter detour are gone. Goldens regenerated: class signatures carry extends/implements, local-var annotation args are preserved, enum constants keep ctor args, and the LombokBuilder enclosing_range ordering matches the new scan order.
1 parent f04a738 commit 2f4decb

55 files changed

Lines changed: 2244 additions & 4759 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.sbt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,16 @@ commands +=
7171
"scalafixAll --check" :: "publishLocal" :: s
7272
}
7373

74-
// Shared module that owns the canonical SemanticDB proto schema and the
75-
// associated symbol/builder utilities. Both the Java compiler plugin
76-
// (semanticdb-javac) and the Kotlin compiler plugin (semanticdb-kotlinc)
77-
// depend on it instead of carrying their own divergent copies of the proto.
74+
// Shared module with the SCIP shard utilities (symbol encoder, document
75+
// builder, on-disk writer) consumed by both the Java compiler plugin
76+
// (semanticdb-javac) and the Kotlin compiler plugin (semanticdb-kotlinc).
7877
lazy val semanticdbShared = project
7978
.in(file("semanticdb-shared"))
8079
.settings(
8180
moduleName := "semanticdb-shared",
8281
javaOnlySettings,
83-
(Compile / PB.targets) :=
84-
Seq(PB.gens.java(V.protobuf) -> (Compile / sourceManaged).value),
85-
libraryDependencies += "com.google.protobuf" % "protobuf-java" % V.protobuf
82+
libraryDependencies +=
83+
"org.scip-code" % "scip-java-bindings" % V.scipBindings
8684
)
8785

8886
lazy val gradlePlugin = project

scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleBuildTool.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) {
3535
}
3636

3737
/**
38-
* Diagnose the case where Gradle finished successfully but our SemanticDB
39-
* compiler plugin never produced any `.semanticdb` files. This used to be
40-
* silently rescued by a `-javaagent` fallback; now it surfaces as a clear
41-
* error pointing at the two known causes.
38+
* Diagnose the case where Gradle finished successfully but our SCIP compiler
39+
* plugin never produced any `.scip` shards. This used to be silently rescued
40+
* by a `-javaagent` fallback; now it surfaces as a clear error pointing at
41+
* the two known causes.
4242
*/
4343
private def reportMissingSemanticdbOutput(): Unit = {
44-
if (containsFileWithSuffix(targetroot, ".semanticdb"))
44+
if (containsFileWithSuffix(targetroot, ".scip"))
4545
return
4646
if (!containsFileWithSuffix(index.workingDirectory, ".class"))
4747
// Project produced no compiled JVM output — nothing to index, stay quiet.
@@ -50,9 +50,9 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) {
5050
.app
5151
.reporter
5252
.error(
53-
s"""scip-java: Gradle finished successfully but produced no SemanticDB output in $targetroot.
53+
s"""scip-java: Gradle finished successfully but produced no SCIP shards in $targetroot.
5454
|
55-
|This means our SemanticDB compiler plugin was not attached to one or more JavaCompile tasks. Two known causes:
55+
|This means our SCIP compiler plugin was not attached to one or more JavaCompile tasks. Two known causes:
5656
|
5757
| 1. The 'compileOnly' configuration was already resolved before our init script ran.
5858
| Check the Gradle output above for warnings of the form:

scip-java/src/main/scala/com/sourcegraph/scip_java/commands/IndexSemanticdbCommand.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import moped.cli.Command
1717
import moped.cli.CommandParser
1818
import org.scip_code.scip.ToolInfo
1919

20-
@Description("Converts SemanticDB files into a single SCIP index file.")
20+
@Description("Aggregates per-source SCIP shards into a single SCIP index file.")
2121
@Usage("scip-java index-semanticdb [OPTIONS ...] [POSITIONAL ARGUMENTS ...]")
2222
@ExampleUsage(
2323
"scip-java index-semanticdb --out=myindex.scip my/targetroot1 my/targetroot2"
@@ -26,14 +26,14 @@ import org.scip_code.scip.ToolInfo
2626
final case class IndexSemanticdbCommand(
2727
@Description("The name of the output file.")
2828
output: Path = Paths.get("index.scip"),
29-
@Description("Whether to process the SemanticDB files in parallel")
29+
@Description("Whether to process the SCIP shards in parallel")
3030
parallel: Boolean = true,
3131
@Description(
3232
"Whether to emit parent->child relationships for 'Find references' and 'Find implementations'. " +
3333
"This flag exists as a workaround for the issue https://github.com/sourcegraph/sourcegraph/issues/50927"
3434
)
3535
emitInverseRelationships: Boolean = true,
36-
@Description("Directories that contain SemanticDB files.")
36+
@Description("Directories that contain SCIP shards.")
3737
@PositionalArguments()
3838
targetroot: List[Path] = Nil,
3939
@Description(

scip-java/src/main/scala/com/sourcegraph/scip_java/commands/SnapshotCommand.scala

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,35 @@ case class SnapshotCommand(
5151
attrs: BasicFileAttributes
5252
): FileVisitResult = {
5353
if (scipPattern.matches(file)) {
54-
foundScipFile = true
5554
val index = Index.parseFrom(Files.readAllBytes(file))
56-
val root = URI.create(index.getMetadata.getProjectRoot)
57-
index
58-
.getDocumentsList
59-
.asScala
60-
.foreach { doc =>
61-
val sourcepath = Paths.get(root.resolve(doc.getRelativePath))
62-
val source =
63-
new String(
64-
Files.readAllBytes(sourcepath),
65-
StandardCharsets.UTF_8
55+
// Per-source SCIP shards under META-INF/scip/ carry no Metadata;
56+
// only the aggregated index does. Skip shards so `scip-java
57+
// snapshot <targetroot>` doesn't trip over them.
58+
val projectRoot = index.getMetadata.getProjectRoot
59+
if (!projectRoot.isEmpty) {
60+
foundScipFile = true
61+
val root = URI.create(projectRoot)
62+
index
63+
.getDocumentsList
64+
.asScala
65+
.foreach { doc =>
66+
val sourcepath = Paths.get(
67+
root.resolve(doc.getRelativePath)
6668
)
67-
val document = ScipPrinters.printTextDocument(doc, source)
68-
val snapshotOutput = output.resolve(doc.getRelativePath)
69-
Files.createDirectories(snapshotOutput.getParent)
70-
Files.write(
71-
snapshotOutput,
72-
document.getBytes(StandardCharsets.UTF_8)
73-
)
74-
}
69+
val source =
70+
new String(
71+
Files.readAllBytes(sourcepath),
72+
StandardCharsets.UTF_8
73+
)
74+
val document = ScipPrinters.printTextDocument(doc, source)
75+
val snapshotOutput = output.resolve(doc.getRelativePath)
76+
Files.createDirectories(snapshotOutput.getParent)
77+
Files.write(
78+
snapshotOutput,
79+
document.getBytes(StandardCharsets.UTF_8)
80+
)
81+
}
82+
}
7583
}
7684
super.visitFile(file, attrs)
7785
}

scip-semanticdb/src/main/java/com/sourcegraph/scip_semanticdb/RangeComparator.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)