Skip to content

Commit 2196876

Browse files
committed
fix LsifBuildTool errors.nonEmpty checks
1 parent e825792 commit 2196876

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

lsif-java/src/main/scala/com/sourcegraph/lsif_java/buildtools/LsifBuildTool.scala

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) {
136136
val deps = Dependencies.resolveDependencies(config.dependencies.map(_.repr))
137137
val sourceroot = index.workingDirectory
138138
if (!Files.isDirectory(sourceroot)) {
139-
throw new NoSuchFileException(sourceroot.toString())
139+
throw new NoSuchFileException(sourceroot.toString)
140140
}
141141
val allSourceFiles = collectAllSourceFiles(sourceroot)
142142
val javaFiles = allSourceFiles.filter(path => javaPattern.matches(path))
@@ -150,46 +150,46 @@ class LsifBuildTool(index: IndexCommand) extends BuildTool("LSIF", index) {
150150
return CommandResult(0, Nil)
151151
}
152152
val errors = ListBuffer.empty[Try[Unit]]
153-
errors += compileJavaFiles(tmp, deps, config, javaFiles)
154-
errors += compileScalaFiles(deps, scalaFiles)
153+
compileJavaFiles(tmp, deps, config, javaFiles).recover(e => errors.addOne(Failure(e)))
154+
compileScalaFiles(deps, scalaFiles).recover(e => errors.addOne(Failure(e)))
155155
if (index.cleanup) {
156156
Files.walkFileTree(tmp, new DeleteVisitor)
157157
}
158158
val isSemanticdbGenerated = Files
159159
.isDirectory(targetroot.resolve("META-INF"))
160160
if (errors.nonEmpty && !isSemanticdbGenerated) {
161161
CommandResult(1, Nil)
162-
} else {
163-
if (isSemanticdbGenerated) {
162+
} else if (errors.nonEmpty && isSemanticdbGenerated) {
164163
index
165164
.app
166165
.reporter
167166
.info(
168167
"Some SemanticDB files got generated even if there were compile errors. " +
169168
"In most cases, this means that lsif-java managed to index everything " +
170-
"except the locations that had compile errors and you can ignore the compile errors."
169+
"except the locations that had compile errors and you can ignore the compile errors." +
170+
errors.mkString("\n")
171171
)
172172
}
173-
CommandResult(0, Nil)
174-
}
173+
CommandResult(0, Nil)
175174
}
176175

177176
private def compileScalaFiles(
178177
deps: Dependencies,
179178
allScalaFiles: List[Path]
180179
): Try[Unit] =
181180
Try {
182-
withScalaPresentationCompiler(deps) { compiler =>
183-
allScalaFiles.foreach { path =>
184-
try compileScalaFile(compiler, path)
185-
catch {
186-
case NonFatal(e) =>
187-
// We want to try and index as much as possible so we don't fail the entire
188-
// compilation even if a single file fails to compile.
189-
index.app.reporter.log(Diagnostic.exception(e))
181+
if (allScalaFiles.nonEmpty)
182+
withScalaPresentationCompiler(deps) { compiler =>
183+
allScalaFiles.foreach { path =>
184+
try compileScalaFile(compiler, path)
185+
catch {
186+
case NonFatal(e) =>
187+
// We want to try and index as much as possible so we don't fail the entire
188+
// compilation even if a single file fails to compile.
189+
index.app.reporter.log(Diagnostic.exception(e))
190+
}
190191
}
191192
}
192-
}
193193
}
194194

195195
private def compileScalaFile(

0 commit comments

Comments
 (0)