Skip to content

Commit

Permalink
Merge pull request #699 from JetBrains/1.9.20
Browse files Browse the repository at this point in the history
1.9.20
  • Loading branch information
zoobestik authored Nov 13, 2023
2 parents 77b5556 + a394b72 commit 65a6caa
Show file tree
Hide file tree
Showing 27 changed files with 367 additions and 252 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ COPY --from=build /kotlin-compiler-server/${KOTLIN_LIB_JS} /kotlin-compiler-serv
COPY --from=build /kotlin-compiler-server/${KOTLIN_LIB_WASM} /kotlin-compiler-server/${KOTLIN_LIB_WASM}
COPY --from=build /kotlin-compiler-server/executor.policy /kotlin-compiler-server/
COPY --from=build /kotlin-compiler-server/indexes.json /kotlin-compiler-server/
COPY --from=build /kotlin-compiler-server/indexesJs.json /kotlin-compiler-server/
COPY --from=build /kotlin-compiler-server/indexesWasm.json /kotlin-compiler-server/

ENV PORT=8080

Expand Down
19 changes: 13 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.springframework.boot.gradle.tasks.bundling.BootJar

val kotlinVersion: String by System.getProperties()
val kotlinVersion = rootProject.properties["systemProp.kotlinVersion"]
val kotlinIdeVersion: String by System.getProperties()
val kotlinIdeVersionSuffix: String by System.getProperties()
val policy: String by System.getProperties()
val indexes: String by System.getProperties()
val indexesJs: String by System.getProperties()
val indexesWasm: String by System.getProperties()

group = "com.compiler.server"
version = "$kotlinVersion-SNAPSHOT"
Expand Down Expand Up @@ -54,12 +55,12 @@ val copyDependencies by tasks.creating(Copy::class) {
into(libJVMFolder)
}
val copyJSDependencies by tasks.creating(Copy::class) {
from(files(Callable { kotlinJsDependency.map { zipTree(it) } }))
from(kotlinJsDependency)
into(libJSFolder)
}

val copyWasmDependencies by tasks.creating(Copy::class) {
from(files(Callable { kotlinWasmDependency.map { zipTree(it) } }))
from(kotlinWasmDependency)
into(libWasmFolder)
}

Expand All @@ -73,7 +74,9 @@ plugins {

apply<NodeJsRootPlugin>()

the<NodeJsRootExtension>().nodeVersion = "20.2.0"
// for new Wasm opcodes
the<NodeJsRootExtension>().nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2"
the<NodeJsRootExtension>().nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"

allprojects {
repositories {
Expand All @@ -82,6 +85,7 @@ allprojects {
maven("https://repo.spring.io/snapshot")
maven("https://repo.spring.io/milestone")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
maven("https://cache-redirector.jetbrains.com/jetbrains.bintray.com/intellij-third-party-dependencies")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies")
maven("https://www.myget.org/F/rd-snapshots/maven/")
Expand Down Expand Up @@ -113,7 +117,8 @@ dependencies {
kotlinDependency("org.jetbrains.kotlin:kotlin-test:$kotlinVersion")
kotlinDependency("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.3")
kotlinJsDependency("org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion")
kotlinWasmDependency("org.jetbrains.kotlin:kotlin-stdlib-wasm:$kotlinVersion")
kotlinJsDependency("org.jetbrains.kotlin:kotlin-dom-api-compat:$kotlinVersion")
kotlinWasmDependency("org.jetbrains.kotlin:kotlin-stdlib-wasm-js:$kotlinVersion")

annotationProcessor("org.springframework:spring-context-indexer")
implementation("com.google.code.gson:gson")
Expand All @@ -129,7 +134,6 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-script-runtime:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-compiler-for-ide:$kotlinIdeVersion"){
isTransitive = false
}
Expand Down Expand Up @@ -157,6 +161,7 @@ fun generateProperties(prefix: String = "") = """
policy.file=${prefix + policy}
indexes.file=${prefix + indexes}
indexesJs.file=${prefix + indexesJs}
indexesWasm.file=${prefix + indexesWasm}
libraries.folder.jvm=${prefix + libJVMFolder}
libraries.folder.js=${prefix + libJSFolder}
libraries.folder.wasm=${prefix + libWasmFolder}
Expand All @@ -183,6 +188,7 @@ tasks.withType<KotlinCompile> {
dependsOn(":indexation:run")
buildPropertyFile()
}
println("Using Kotlin compiler $kotlinVersion")

tasks.withType<BootJar> {
requiresUnpack("**/kotlin-*.jar")
Expand All @@ -200,6 +206,7 @@ val buildLambda by tasks.creating(Zip::class) {
from(policy)
from(indexes)
from(indexesJs)
from(indexesWasm)
from(libJSFolder) { into(libJSFolder) }
from(libWasmFolder) { into(libWasmFolder) }
from(libJVMFolder) { into(libJVMFolder) }
Expand Down
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
systemProp.kotlinVersion=1.9.10
systemProp.kotlinIdeVersion=1.9.10-456
systemProp.kotlinIdeVersionSuffix=IJ8770.65
systemProp.kotlinVersion=1.9.20
systemProp.kotlinIdeVersion=1.9.20-RC2-494
systemProp.kotlinIdeVersionSuffix=IJ8109.175
systemProp.policy=executor.policy
systemProp.indexes=indexes.json
systemProp.indexesJs=indexesJs.json
systemProp.indexesWasm=indexesWasm.json
4 changes: 3 additions & 1 deletion indexation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ val kotlinVersion: String by System.getProperties()
val kotlinIdeVersion: String by System.getProperties()
val indexes: String by System.getProperties()
val indexesJs: String by System.getProperties()
val indexesWasm: String by System.getProperties()

plugins {
kotlin("jvm")
Expand All @@ -24,6 +25,7 @@ tasks.withType<JavaExec> {
args = listOf(
"$rootName${File.separator}$kotlinVersion",
"$rootName${File.separator}$indexes",
"$rootName${File.separator}$indexesJs"
"$rootName${File.separator}$indexesJs",
"$rootName${File.separator}$indexesWasm"
)
}
24 changes: 0 additions & 24 deletions indexation/src/main/kotlin/JsIndexationBuilder.kt

This file was deleted.

6 changes: 4 additions & 2 deletions indexation/src/main/kotlin/KotlinEnvironmentConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class KotlinEnvironmentConfiguration(fileName: String) {
?: error("No kotlin libraries found in: ${jvmFile.absolutePath}")
}

val additionalJsClasspath = listOfNotNull(jsFile)
KotlinEnvironment(classPath, additionalJsClasspath, listOfNotNull(wasmFile))
val additionalJsClasspath = jsFile.listFiles()?.toList() ?: emptyList()
val additionalWasmClasspath = wasmFile.listFiles()?.toList() ?: emptyList()

KotlinEnvironment(classPath, additionalJsClasspath, additionalWasmClasspath)
}
}
15 changes: 13 additions & 2 deletions indexation/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@ package indexation
* Third argument is path to output file for js indexes
*/
fun main(args: Array<String>) {
val (directory, outputPathJvm, outputPathJs) = args
val (directory, outputPathJvm, outputPathJs, outputPathWasm) = args
val kotlinEnvironment = KotlinEnvironmentConfiguration(directory).kotlinEnvironment
JvmIndexationBuilder(kotlinEnvironment = kotlinEnvironment).writeIndexesToFile(outputPathJvm)
JsIndexationBuilder(kotlinEnvironment = kotlinEnvironment).writeIndexesToFile(outputPathJs)

WebIndexationBuilder(
kotlinEnvironment = kotlinEnvironment,
configuration = kotlinEnvironment.jsConfiguration,
libraries = kotlinEnvironment.JS_LIBRARIES
).writeIndexesToFile(outputPathJs)

WebIndexationBuilder(
kotlinEnvironment = kotlinEnvironment,
configuration = kotlinEnvironment.wasmConfiguration,
libraries = kotlinEnvironment.WASM_LIBRARIES
).writeIndexesToFile(outputPathWasm)
}
36 changes: 36 additions & 0 deletions indexation/src/main/kotlin/WebIndexationBuilder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package indexation

import model.ImportInfo
import component.KotlinEnvironment
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.ir.backend.js.prepareAnalyzedSourceModule

class WebIndexationBuilder(
private val kotlinEnvironment: KotlinEnvironment,
private val configuration: CompilerConfiguration,
private val libraries: List<String>
): IndexationBuilder() {

override fun getAllIndexes(): List<ImportInfo> =
kotlinEnvironment.environment { coreEnvironment ->
val project = coreEnvironment.project

val sourceModule = prepareAnalyzedSourceModule(
project,
coreEnvironment.getSourceFiles(),
configuration,
libraries,
friendDependencies = emptyList(),
analyzer = AnalyzerWithCompilerReport(kotlinEnvironment.jsConfiguration),
)

val mds = sourceModule.allDependencies.map {
sourceModule.getModuleDescriptor(it)
}

return@environment mds.flatMap { moduleDescriptor ->
moduleDescriptor.allImportsInfo()
}.distinct()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.compiler.server.compiler

enum class KotlinPlatform {
JS,
JVM,
WASM
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.compiler.server.compiler.KotlinFile
import com.compiler.server.compiler.KotlinResolutionFacade
import com.compiler.server.model.Analysis
import com.compiler.server.model.ErrorDescriptor
import com.compiler.server.model.ProjectType
import com.intellij.psi.PsiElement
import com.intellij.psi.tree.TokenSet
import model.Completion
Expand Down Expand Up @@ -59,16 +60,16 @@ class CompletionProvider(
file: KotlinFile,
line: Int,
character: Int,
isJs: Boolean,
projectType: ProjectType,
coreEnvironment: KotlinCoreEnvironment
): List<Completion> = with(file.insert("$COMPLETION_SUFFIX ", line, character)) {
elementAt(line, character)?.let { element ->
val descriptorInfo = descriptorsFrom(this, element, isJs, coreEnvironment)
val descriptorInfo = descriptorsFrom(this, element, projectType, coreEnvironment)
val prefix = (if (descriptorInfo.isTipsManagerCompletion) element.text else element.parent.text)
.substringBefore(COMPLETION_SUFFIX).let { if (it.endsWith(".")) "" else it }
val importCompletionVariants = if (indexationProvider.hasIndexes(isJs)) {
val (errors, _) = errorAnalyzer.errorsFrom(listOf(file.kotlinFile), coreEnvironment, isJs)
importVariants(file, prefix, errors, line, character, isJs)
val importCompletionVariants = if (indexationProvider.hasIndexes(projectType)) {
val (errors, _) = errorAnalyzer.errorsFrom(listOf(file.kotlinFile), coreEnvironment, projectType)
importVariants(file, prefix, errors, line, character, projectType)
} else emptyList()
descriptorInfo.descriptors.toMutableList().apply {
sortWith(Comparator { a, b ->
Expand Down Expand Up @@ -115,9 +116,9 @@ class CompletionProvider(
errors: Map<String, List<ErrorDescriptor>>,
line: Int,
character: Int,
isJs: Boolean
projectType: ProjectType
): List<Completion> {
val importCompletionVariants = indexationProvider.getClassesByName(prefix, isJs)
val importCompletionVariants = indexationProvider.getClassesByName(prefix, projectType)
?.map { it.toCompletion() } ?: emptyList()
val currentErrors = errors[file.kotlinFile.name]?.filter {
it.interval.start.line == line &&
Expand Down Expand Up @@ -195,14 +196,16 @@ class CompletionProvider(
private fun descriptorsFrom(
file: KotlinFile,
element: PsiElement,
isJs: Boolean,
projectType: ProjectType,
coreEnvironment: KotlinCoreEnvironment
): DescriptorInfo {
val files = listOf(file.kotlinFile)
val analysis = if (isJs.not())
errorAnalyzer.analysisOf(files, coreEnvironment)
else
errorAnalyzer.analyzeFileForJs(files, coreEnvironment)
val analysis = when {
projectType.isJvmRelated() -> errorAnalyzer.analysisOf(files, coreEnvironment)
projectType.isJsRelated() -> errorAnalyzer.analyzeFileForJs(files, coreEnvironment)
projectType == ProjectType.WASM -> errorAnalyzer.analyzeFileForWasm(files, coreEnvironment)
else -> throw IllegalArgumentException("Unknown project type $projectType")
}
return with(analysis) {
(referenceVariantsFrom(element, coreEnvironment)
?: referenceVariantsFrom(element.parent, coreEnvironment))?.let { descriptors ->
Expand Down
Loading

0 comments on commit 65a6caa

Please sign in to comment.