Skip to content

Commit

Permalink
Only generate code if codegen is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Jul 28, 2024
1 parent 8b3eafc commit 188f41f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions server/src/main/kotlin/org/javacs/kt/CompilerClassPath.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>()
Expand All @@ -33,6 +34,7 @@ class CompilerClassPath(
classPath.map { it.compiledJar }.toSet(),
buildScriptClassPath,
scriptsConfig,
codegenConfig,
outputDirectory
)
private set
Expand Down Expand Up @@ -87,6 +89,7 @@ class CompilerClassPath(
classPath.map { it.compiledJar }.toSet(),
buildScriptClassPath,
scriptsConfig,
codegenConfig,
outputDirectory
)
updateCompilerConfiguration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down
4 changes: 3 additions & 1 deletion server/src/main/kotlin/org/javacs/kt/compiler/Compiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -460,6 +461,7 @@ class Compiler(
classPath: Set<Path>,
buildScriptClassPath: Set<Path> = emptySet(),
scriptsConfig: ScriptsConfiguration,
private val codegenConfig: CodegenConfiguration,
private val outputDirectory: File,
) : Closeable {
private var closed = false
Expand Down Expand Up @@ -584,7 +586,7 @@ class Compiler(
}

fun generateCode(module: ModuleDescriptor, bindingContext: BindingContext, files: Collection<KtFile>) {
outputDirectory.let {
outputDirectory.takeIf { codegenConfig.enabled }?.let {
compileLock.withLock {
val compileEnv = compileEnvironmentFor(CompilationKind.DEFAULT)
val state = GenerationState.Builder(
Expand Down
3 changes: 2 additions & 1 deletion server/src/test/kotlin/org/javacs/kt/CompiledFileTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions server/src/test/kotlin/org/javacs/kt/CompilerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private class FileToEdit {
javaSourcePath = setOf(),
classPath = setOf(),
scriptsConfig = ScriptsConfiguration(),
codegenConfig = CodegenConfiguration(),
outputDirectory = outputDirectory
)
}
Expand Down

0 comments on commit 188f41f

Please sign in to comment.