Skip to content

Commit bf1253a

Browse files
committed
Skip codegen if there are errors
1 parent e6dc5f0 commit bf1253a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

server/src/main/kotlin/org/javacs/kt/SourcePath.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.psi.KtFile
1414
import org.jetbrains.kotlin.resolve.BindingContext
1515
import org.jetbrains.kotlin.resolve.CompositeBindingContext
1616
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
17+
import org.jetbrains.kotlin.diagnostics.Severity
1718
import kotlin.concurrent.withLock
1819
import java.nio.file.Path
1920
import java.nio.file.Paths
@@ -59,6 +60,9 @@ class SourcePath(
5960
if (path?.fileName?.toString()?.endsWith(".gradle.kts") ?: false) CompilationKind.BUILD_SCRIPT
6061
else CompilationKind.DEFAULT
6162

63+
val hasErrors: Boolean
64+
get() = compiledContext?.diagnostics?.any { it.severity == Severity.ERROR } ?: false
65+
6266
fun put(newContent: String) {
6367
content = newContent
6468
}
@@ -268,7 +272,7 @@ class SourcePath(
268272
*/
269273
fun save(uri: URI) {
270274
files[uri]?.let {
271-
if (!it.isScript) {
275+
if (!it.isScript && !it.hasErrors) {
272276
// If the code generation fails for some reason, we generate code for the other files anyway
273277
try {
274278
cp.compiler.removeGeneratedCode(listOfNotNull(it.lastSavedFile))

0 commit comments

Comments
 (0)