From 188f41f0107f7c53c06393071c34feab2c2570d1 Mon Sep 17 00:00:00 2001 From: fwcd Date: Mon, 29 Jul 2024 01:32:05 +0200 Subject: [PATCH] Only generate code if codegen is enabled --- server/src/main/kotlin/org/javacs/kt/CompilerClassPath.kt | 3 +++ server/src/main/kotlin/org/javacs/kt/KotlinLanguageServer.kt | 2 +- server/src/main/kotlin/org/javacs/kt/compiler/Compiler.kt | 4 +++- server/src/test/kotlin/org/javacs/kt/CompiledFileTest.kt | 3 ++- server/src/test/kotlin/org/javacs/kt/CompilerTest.kt | 1 + 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server/src/main/kotlin/org/javacs/kt/CompilerClassPath.kt b/server/src/main/kotlin/org/javacs/kt/CompilerClassPath.kt index d3ef00e2a..794377454 100644 --- a/server/src/main/kotlin/org/javacs/kt/CompilerClassPath.kt +++ b/server/src/main/kotlin/org/javacs/kt/CompilerClassPath.kt @@ -18,6 +18,7 @@ import java.nio.file.Path class CompilerClassPath( private val config: CompilerConfiguration, private val scriptsConfig: ScriptsConfiguration, + private val codegenConfig: CodegenConfiguration, private val databaseService: DatabaseService ) : Closeable { val workspaceRoots = mutableSetOf() @@ -33,6 +34,7 @@ class CompilerClassPath( classPath.map { it.compiledJar }.toSet(), buildScriptClassPath, scriptsConfig, + codegenConfig, outputDirectory ) private set @@ -87,6 +89,7 @@ class CompilerClassPath( classPath.map { it.compiledJar }.toSet(), buildScriptClassPath, scriptsConfig, + codegenConfig, outputDirectory ) updateCompilerConfiguration() diff --git a/server/src/main/kotlin/org/javacs/kt/KotlinLanguageServer.kt b/server/src/main/kotlin/org/javacs/kt/KotlinLanguageServer.kt index 29998dc3a..e8da0ff99 100644 --- a/server/src/main/kotlin/org/javacs/kt/KotlinLanguageServer.kt +++ b/server/src/main/kotlin/org/javacs/kt/KotlinLanguageServer.kt @@ -26,7 +26,7 @@ class KotlinLanguageServer( val config: Configuration = Configuration() ) : LanguageServer, LanguageClientAware, Closeable { val databaseService = DatabaseService() - val classPath = CompilerClassPath(config.compiler, config.scripts, databaseService) + val classPath = CompilerClassPath(config.compiler, config.scripts, config.codegen, databaseService) private val tempDirectory = TemporaryDirectory() private val uriContentProvider = URIContentProvider(ClassContentProvider(config.externalSources, classPath, tempDirectory, CompositeSourceArchiveProvider(JdkSourceArchiveProvider(classPath), ClassPathSourceArchiveProvider(classPath)))) diff --git a/server/src/main/kotlin/org/javacs/kt/compiler/Compiler.kt b/server/src/main/kotlin/org/javacs/kt/compiler/Compiler.kt index eef04b1dd..f81d1f0ee 100644 --- a/server/src/main/kotlin/org/javacs/kt/compiler/Compiler.kt +++ b/server/src/main/kotlin/org/javacs/kt/compiler/Compiler.kt @@ -57,6 +57,7 @@ import kotlin.script.experimental.host.configurationDependencies import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration import kotlin.script.experimental.jvm.JvmDependency import org.javacs.kt.LOG +import org.javacs.kt.CodegenConfiguration import org.javacs.kt.CompilerConfiguration import org.javacs.kt.ScriptsConfiguration import org.javacs.kt.util.KotlinLSException @@ -460,6 +461,7 @@ class Compiler( classPath: Set, buildScriptClassPath: Set = emptySet(), scriptsConfig: ScriptsConfiguration, + private val codegenConfig: CodegenConfiguration, private val outputDirectory: File, ) : Closeable { private var closed = false @@ -584,7 +586,7 @@ class Compiler( } fun generateCode(module: ModuleDescriptor, bindingContext: BindingContext, files: Collection) { - outputDirectory.let { + outputDirectory.takeIf { codegenConfig.enabled }?.let { compileLock.withLock { val compileEnv = compileEnvironmentFor(CompilationKind.DEFAULT) val state = GenerationState.Builder( diff --git a/server/src/test/kotlin/org/javacs/kt/CompiledFileTest.kt b/server/src/test/kotlin/org/javacs/kt/CompiledFileTest.kt index a1bd15bcb..c6552e272 100644 --- a/server/src/test/kotlin/org/javacs/kt/CompiledFileTest.kt +++ b/server/src/test/kotlin/org/javacs/kt/CompiledFileTest.kt @@ -30,12 +30,13 @@ class CompiledFileTest { javaSourcePath = setOf(), classPath = setOf(), scriptsConfig = ScriptsConfiguration(), + codegenConfig = CodegenConfiguration(), outputDirectory = outputDirectory ).use { compiler -> val file = testResourcesRoot().resolve("compiledFile/CompiledFileExample.kt") val content = Files.readAllLines(file).joinToString("\n") val parse = compiler.createKtFile(content, file) - val classPath = CompilerClassPath(CompilerConfiguration(), ScriptsConfiguration(), DatabaseService()) + val classPath = CompilerClassPath(CompilerConfiguration(), ScriptsConfiguration(), CodegenConfiguration(), DatabaseService()) val sourcePath = listOf(parse) val (context, container) = compiler.compileKtFiles(sourcePath, sourcePath) CompiledFile(content, parse, context, container, sourcePath, classPath) diff --git a/server/src/test/kotlin/org/javacs/kt/CompilerTest.kt b/server/src/test/kotlin/org/javacs/kt/CompilerTest.kt index 6ae232cfe..acfa569e4 100644 --- a/server/src/test/kotlin/org/javacs/kt/CompilerTest.kt +++ b/server/src/test/kotlin/org/javacs/kt/CompilerTest.kt @@ -33,6 +33,7 @@ private class FileToEdit { javaSourcePath = setOf(), classPath = setOf(), scriptsConfig = ScriptsConfiguration(), + codegenConfig = CodegenConfiguration(), outputDirectory = outputDirectory ) }