sourcegraph / scip-java

SCIP Code Intelligence Protocol generator for Java
https://sourcegraph.github.io/scip-java/
Apache License 2.0
73 stars 28 forks source link

Cannot produce java semanticdb files inside sbt project #390

Open tgodzik opened 2 years ago

tgodzik commented 2 years ago

I tried adding semanticdb to metals input project in order to run some more tests, but got:

Please report a bug to https://github.com/sourcegraph/semanticdb-java with the stack trace above.
com.sourcegraph.semanticdb_javac.CompilationUnitException: vf://tmp/$%7BBASE%7D/tests/input/src/main/java/example/JavaOverloading.java
Caused by: java.nio.file.FileSystemNotFoundException: Provider "vf" not installed
        at java.base/java.nio.file.Path.of(Path.java:212)
        at java.base/java.nio.file.Paths.get(Paths.java:97)
        at com.sourcegraph.semanticdb_javac.SemanticdbTaskListener.absolutePathFromUri(SemanticdbTaskListener.java:95)
        at com.sourcegraph.semanticdb_javac.SemanticdbTaskListener.semanticdbOutputPath(SemanticdbTaskListener.java:100)
        at com.sourcegraph.semanticdb_javac.SemanticdbTaskListener.onFinishedAnalyze(SemanticdbTaskListener.java:62)
        at com.sourcegraph.semanticdb_javac.SemanticdbTaskListener.finished(SemanticdbTaskListener.java:46)
        at jdk.compiler/com.sun.tools.javac.api.ClientCodeWrapper$WrappedTaskListener.finished(ClientCodeWrapper.java:828)
        at jdk.compiler/com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:132)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1418)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1375)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:147)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
        at sbt.internal.inc.javac.LocalJavaCompiler.run(LocalJava.scala:345)
        at sbt.internal.inc.javac.AnalyzingJavaCompiler.$anonfun$compile$12(AnalyzingJavaCompiler.scala:172)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at sbt.internal.inc.javac.AnalyzingJavaCompiler.timed(AnalyzingJavaCompiler.scala:262)
        at sbt.internal.inc.javac.AnalyzingJavaCompiler.compile(AnalyzingJavaCompiler.scala:161)
        at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$2(MixedAnalyzingCompiler.scala:103)
        at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$2$adapted(MixedAnalyzingCompiler.scala:91)
        at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
        at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compileJava$1(MixedAnalyzingCompiler.scala:91)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:247)
        at sbt.internal.inc.MixedAnalyzingCompiler.compileJava(MixedAnalyzingCompiler.scala:61)
        at sbt.internal.inc.MixedAnalyzingCompiler.compileJava0$1(MixedAnalyzingCompiler.scala:197)
        at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:210)
        at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:528)
        at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:528)
        at sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:177)
        at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:175)
        at sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:461)
        at sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
        at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
        at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
        at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
        at sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:416)
        at sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:503)
        at sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:403)
        at sbt.internal.inc.Incremental$.apply(Incremental.scala:169)
        at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528)
        at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:482)
        at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
        at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420)
        at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
        at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2366)
        at sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2316)
        at sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:30)
        at sbt.internal.io.Retry$.apply(Retry.scala:46)
        at sbt.internal.io.Retry$.apply(Retry.scala:28)
        at sbt.internal.io.Retry$.apply(Retry.scala:23)
        at sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:30)
        at sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2314)
        at scala.Function1.$anonfun$compose$1(Function1.scala:49)
        at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
        at sbt.std.Transform$$anon$4.work(Transform.scala:68)
        at sbt.Execute.$anonfun$submit$2(Execute.scala:282)
        at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
        at sbt.Execute.work(Execute.scala:291)
        at sbt.Execute.$anonfun$submit$1(Execute.scala:282)
        at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)

The effort can be found here: https://github.com/scalameta/metals/compare/main...tgodzik:add-testing-java?expand=1

The issue seems to be the VirtualFile that zinc uses, but not exactly sure why would this pop up here but not during normal Java compilation.

olafurpg commented 2 years ago

Thank you for reporting! The flag -build-tool:sbt is needed alongside -sourceroot and -targetroot to work with with the custom sbt file system

https://github.com/sourcegraph/lsif-java/blob/205dc612578dbf4ef58b1444f65dba38adbea24b/semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbJavacOptions.java#L57

This flag is automatically added by sbt-sourcegraph here

https://github.com/sourcegraph/sbt-sourcegraph/blob/d0c4b2a33d8f091d8ca82f8fc1e801a5afb75654/src/main/scala/com/sourcegraph/sbtsourcegraph/SourcegraphEnable.scala#L44