Skip to content

Commit 65a6caa

Browse files
authored
Merge pull request #699 from JetBrains/1.9.20
1.9.20
2 parents 77b5556 + a394b72 commit 65a6caa

27 files changed

+367
-252
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ COPY --from=build /kotlin-compiler-server/${KOTLIN_LIB_JS} /kotlin-compiler-serv
3131
COPY --from=build /kotlin-compiler-server/${KOTLIN_LIB_WASM} /kotlin-compiler-server/${KOTLIN_LIB_WASM}
3232
COPY --from=build /kotlin-compiler-server/executor.policy /kotlin-compiler-server/
3333
COPY --from=build /kotlin-compiler-server/indexes.json /kotlin-compiler-server/
34+
COPY --from=build /kotlin-compiler-server/indexesJs.json /kotlin-compiler-server/
35+
COPY --from=build /kotlin-compiler-server/indexesWasm.json /kotlin-compiler-server/
3436

3537
ENV PORT=8080
3638

build.gradle.kts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
55
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
66
import org.springframework.boot.gradle.tasks.bundling.BootJar
77

8-
val kotlinVersion: String by System.getProperties()
8+
val kotlinVersion = rootProject.properties["systemProp.kotlinVersion"]
99
val kotlinIdeVersion: String by System.getProperties()
1010
val kotlinIdeVersionSuffix: String by System.getProperties()
1111
val policy: String by System.getProperties()
1212
val indexes: String by System.getProperties()
1313
val indexesJs: String by System.getProperties()
14+
val indexesWasm: String by System.getProperties()
1415

1516
group = "com.compiler.server"
1617
version = "$kotlinVersion-SNAPSHOT"
@@ -54,12 +55,12 @@ val copyDependencies by tasks.creating(Copy::class) {
5455
into(libJVMFolder)
5556
}
5657
val copyJSDependencies by tasks.creating(Copy::class) {
57-
from(files(Callable { kotlinJsDependency.map { zipTree(it) } }))
58+
from(kotlinJsDependency)
5859
into(libJSFolder)
5960
}
6061

6162
val copyWasmDependencies by tasks.creating(Copy::class) {
62-
from(files(Callable { kotlinWasmDependency.map { zipTree(it) } }))
63+
from(kotlinWasmDependency)
6364
into(libWasmFolder)
6465
}
6566

@@ -73,7 +74,9 @@ plugins {
7374

7475
apply<NodeJsRootPlugin>()
7576

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

7881
allprojects {
7982
repositories {
@@ -82,6 +85,7 @@ allprojects {
8285
maven("https://repo.spring.io/snapshot")
8386
maven("https://repo.spring.io/milestone")
8487
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide")
88+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
8589
maven("https://cache-redirector.jetbrains.com/jetbrains.bintray.com/intellij-third-party-dependencies")
8690
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies")
8791
maven("https://www.myget.org/F/rd-snapshots/maven/")
@@ -113,7 +117,8 @@ dependencies {
113117
kotlinDependency("org.jetbrains.kotlin:kotlin-test:$kotlinVersion")
114118
kotlinDependency("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.3")
115119
kotlinJsDependency("org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion")
116-
kotlinWasmDependency("org.jetbrains.kotlin:kotlin-stdlib-wasm:$kotlinVersion")
120+
kotlinJsDependency("org.jetbrains.kotlin:kotlin-dom-api-compat:$kotlinVersion")
121+
kotlinWasmDependency("org.jetbrains.kotlin:kotlin-stdlib-wasm-js:$kotlinVersion")
117122

118123
annotationProcessor("org.springframework:spring-context-indexer")
119124
implementation("com.google.code.gson:gson")
@@ -129,7 +134,6 @@ dependencies {
129134
implementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion")
130135
implementation("org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion")
131136
implementation("org.jetbrains.kotlin:kotlin-script-runtime:$kotlinVersion")
132-
implementation("org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion")
133137
implementation("org.jetbrains.kotlin:kotlin-compiler-for-ide:$kotlinIdeVersion"){
134138
isTransitive = false
135139
}
@@ -157,6 +161,7 @@ fun generateProperties(prefix: String = "") = """
157161
policy.file=${prefix + policy}
158162
indexes.file=${prefix + indexes}
159163
indexesJs.file=${prefix + indexesJs}
164+
indexesWasm.file=${prefix + indexesWasm}
160165
libraries.folder.jvm=${prefix + libJVMFolder}
161166
libraries.folder.js=${prefix + libJSFolder}
162167
libraries.folder.wasm=${prefix + libWasmFolder}
@@ -183,6 +188,7 @@ tasks.withType<KotlinCompile> {
183188
dependsOn(":indexation:run")
184189
buildPropertyFile()
185190
}
191+
println("Using Kotlin compiler $kotlinVersion")
186192

187193
tasks.withType<BootJar> {
188194
requiresUnpack("**/kotlin-*.jar")
@@ -200,6 +206,7 @@ val buildLambda by tasks.creating(Zip::class) {
200206
from(policy)
201207
from(indexes)
202208
from(indexesJs)
209+
from(indexesWasm)
203210
from(libJSFolder) { into(libJSFolder) }
204211
from(libWasmFolder) { into(libWasmFolder) }
205212
from(libJVMFolder) { into(libJVMFolder) }

gradle.properties

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
systemProp.kotlinVersion=1.9.10
2-
systemProp.kotlinIdeVersion=1.9.10-456
3-
systemProp.kotlinIdeVersionSuffix=IJ8770.65
1+
systemProp.kotlinVersion=1.9.20
2+
systemProp.kotlinIdeVersion=1.9.20-RC2-494
3+
systemProp.kotlinIdeVersionSuffix=IJ8109.175
44
systemProp.policy=executor.policy
55
systemProp.indexes=indexes.json
66
systemProp.indexesJs=indexesJs.json
7+
systemProp.indexesWasm=indexesWasm.json

indexation/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ val kotlinVersion: String by System.getProperties()
22
val kotlinIdeVersion: String by System.getProperties()
33
val indexes: String by System.getProperties()
44
val indexesJs: String by System.getProperties()
5+
val indexesWasm: String by System.getProperties()
56

67
plugins {
78
kotlin("jvm")
@@ -24,6 +25,7 @@ tasks.withType<JavaExec> {
2425
args = listOf(
2526
"$rootName${File.separator}$kotlinVersion",
2627
"$rootName${File.separator}$indexes",
27-
"$rootName${File.separator}$indexesJs"
28+
"$rootName${File.separator}$indexesJs",
29+
"$rootName${File.separator}$indexesWasm"
2830
)
2931
}

indexation/src/main/kotlin/JsIndexationBuilder.kt

Lines changed: 0 additions & 24 deletions
This file was deleted.

indexation/src/main/kotlin/KotlinEnvironmentConfiguration.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class KotlinEnvironmentConfiguration(fileName: String) {
1515
?: error("No kotlin libraries found in: ${jvmFile.absolutePath}")
1616
}
1717

18-
val additionalJsClasspath = listOfNotNull(jsFile)
19-
KotlinEnvironment(classPath, additionalJsClasspath, listOfNotNull(wasmFile))
18+
val additionalJsClasspath = jsFile.listFiles()?.toList() ?: emptyList()
19+
val additionalWasmClasspath = wasmFile.listFiles()?.toList() ?: emptyList()
20+
21+
KotlinEnvironment(classPath, additionalJsClasspath, additionalWasmClasspath)
2022
}
2123
}

indexation/src/main/kotlin/Main.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@ package indexation
66
* Third argument is path to output file for js indexes
77
*/
88
fun main(args: Array<String>) {
9-
val (directory, outputPathJvm, outputPathJs) = args
9+
val (directory, outputPathJvm, outputPathJs, outputPathWasm) = args
1010
val kotlinEnvironment = KotlinEnvironmentConfiguration(directory).kotlinEnvironment
1111
JvmIndexationBuilder(kotlinEnvironment = kotlinEnvironment).writeIndexesToFile(outputPathJvm)
12-
JsIndexationBuilder(kotlinEnvironment = kotlinEnvironment).writeIndexesToFile(outputPathJs)
12+
13+
WebIndexationBuilder(
14+
kotlinEnvironment = kotlinEnvironment,
15+
configuration = kotlinEnvironment.jsConfiguration,
16+
libraries = kotlinEnvironment.JS_LIBRARIES
17+
).writeIndexesToFile(outputPathJs)
18+
19+
WebIndexationBuilder(
20+
kotlinEnvironment = kotlinEnvironment,
21+
configuration = kotlinEnvironment.wasmConfiguration,
22+
libraries = kotlinEnvironment.WASM_LIBRARIES
23+
).writeIndexesToFile(outputPathWasm)
1324
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package indexation
2+
3+
import model.ImportInfo
4+
import component.KotlinEnvironment
5+
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
6+
import org.jetbrains.kotlin.config.CompilerConfiguration
7+
import org.jetbrains.kotlin.ir.backend.js.prepareAnalyzedSourceModule
8+
9+
class WebIndexationBuilder(
10+
private val kotlinEnvironment: KotlinEnvironment,
11+
private val configuration: CompilerConfiguration,
12+
private val libraries: List<String>
13+
): IndexationBuilder() {
14+
15+
override fun getAllIndexes(): List<ImportInfo> =
16+
kotlinEnvironment.environment { coreEnvironment ->
17+
val project = coreEnvironment.project
18+
19+
val sourceModule = prepareAnalyzedSourceModule(
20+
project,
21+
coreEnvironment.getSourceFiles(),
22+
configuration,
23+
libraries,
24+
friendDependencies = emptyList(),
25+
analyzer = AnalyzerWithCompilerReport(kotlinEnvironment.jsConfiguration),
26+
)
27+
28+
val mds = sourceModule.allDependencies.map {
29+
sourceModule.getModuleDescriptor(it)
30+
}
31+
32+
return@environment mds.flatMap { moduleDescriptor ->
33+
moduleDescriptor.allImportsInfo()
34+
}.distinct()
35+
}
36+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.compiler.server.compiler
2+
3+
enum class KotlinPlatform {
4+
JS,
5+
JVM,
6+
WASM
7+
}

src/main/kotlin/com/compiler/server/compiler/components/CompletionProvider.kt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.compiler.server.compiler.KotlinFile
44
import com.compiler.server.compiler.KotlinResolutionFacade
55
import com.compiler.server.model.Analysis
66
import com.compiler.server.model.ErrorDescriptor
7+
import com.compiler.server.model.ProjectType
78
import com.intellij.psi.PsiElement
89
import com.intellij.psi.tree.TokenSet
910
import model.Completion
@@ -59,16 +60,16 @@ class CompletionProvider(
5960
file: KotlinFile,
6061
line: Int,
6162
character: Int,
62-
isJs: Boolean,
63+
projectType: ProjectType,
6364
coreEnvironment: KotlinCoreEnvironment
6465
): List<Completion> = with(file.insert("$COMPLETION_SUFFIX ", line, character)) {
6566
elementAt(line, character)?.let { element ->
66-
val descriptorInfo = descriptorsFrom(this, element, isJs, coreEnvironment)
67+
val descriptorInfo = descriptorsFrom(this, element, projectType, coreEnvironment)
6768
val prefix = (if (descriptorInfo.isTipsManagerCompletion) element.text else element.parent.text)
6869
.substringBefore(COMPLETION_SUFFIX).let { if (it.endsWith(".")) "" else it }
69-
val importCompletionVariants = if (indexationProvider.hasIndexes(isJs)) {
70-
val (errors, _) = errorAnalyzer.errorsFrom(listOf(file.kotlinFile), coreEnvironment, isJs)
71-
importVariants(file, prefix, errors, line, character, isJs)
70+
val importCompletionVariants = if (indexationProvider.hasIndexes(projectType)) {
71+
val (errors, _) = errorAnalyzer.errorsFrom(listOf(file.kotlinFile), coreEnvironment, projectType)
72+
importVariants(file, prefix, errors, line, character, projectType)
7273
} else emptyList()
7374
descriptorInfo.descriptors.toMutableList().apply {
7475
sortWith(Comparator { a, b ->
@@ -115,9 +116,9 @@ class CompletionProvider(
115116
errors: Map<String, List<ErrorDescriptor>>,
116117
line: Int,
117118
character: Int,
118-
isJs: Boolean
119+
projectType: ProjectType
119120
): List<Completion> {
120-
val importCompletionVariants = indexationProvider.getClassesByName(prefix, isJs)
121+
val importCompletionVariants = indexationProvider.getClassesByName(prefix, projectType)
121122
?.map { it.toCompletion() } ?: emptyList()
122123
val currentErrors = errors[file.kotlinFile.name]?.filter {
123124
it.interval.start.line == line &&
@@ -195,14 +196,16 @@ class CompletionProvider(
195196
private fun descriptorsFrom(
196197
file: KotlinFile,
197198
element: PsiElement,
198-
isJs: Boolean,
199+
projectType: ProjectType,
199200
coreEnvironment: KotlinCoreEnvironment
200201
): DescriptorInfo {
201202
val files = listOf(file.kotlinFile)
202-
val analysis = if (isJs.not())
203-
errorAnalyzer.analysisOf(files, coreEnvironment)
204-
else
205-
errorAnalyzer.analyzeFileForJs(files, coreEnvironment)
203+
val analysis = when {
204+
projectType.isJvmRelated() -> errorAnalyzer.analysisOf(files, coreEnvironment)
205+
projectType.isJsRelated() -> errorAnalyzer.analyzeFileForJs(files, coreEnvironment)
206+
projectType == ProjectType.WASM -> errorAnalyzer.analyzeFileForWasm(files, coreEnvironment)
207+
else -> throw IllegalArgumentException("Unknown project type $projectType")
208+
}
206209
return with(analysis) {
207210
(referenceVariantsFrom(element, coreEnvironment)
208211
?: referenceVariantsFrom(element.parent, coreEnvironment))?.let { descriptors ->

0 commit comments

Comments
 (0)