Skip to content

Commit 19a25ed

Browse files
authored
Merge pull request #681 from JetBrains/ilgonmic/wasm-frontend
Use wasm frontend for wasm target
2 parents 2696f48 + 667d2b4 commit 19a25ed

20 files changed

+275
-160
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ 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"
@@ -160,6 +161,7 @@ fun generateProperties(prefix: String = "") = """
160161
policy.file=${prefix + policy}
161162
indexes.file=${prefix + indexes}
162163
indexesJs.file=${prefix + indexesJs}
164+
indexesWasm.file=${prefix + indexesWasm}
163165
libraries.folder.jvm=${prefix + libJVMFolder}
164166
libraries.folder.js=${prefix + libJSFolder}
165167
libraries.folder.wasm=${prefix + libWasmFolder}
@@ -204,6 +206,7 @@ val buildLambda by tasks.creating(Zip::class) {
204206
from(policy)
205207
from(indexes)
206208
from(indexesJs)
209+
from(indexesWasm)
207210
from(libJSFolder) { into(libJSFolder) }
208211
from(libWasmFolder) { into(libWasmFolder) }
209212
from(libJVMFolder) { into(libJVMFolder) }

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ 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/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
}

indexation/src/main/kotlin/JsIndexationBuilder.kt renamed to indexation/src/main/kotlin/WebIndexationBuilder.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@ package indexation
33
import model.ImportInfo
44
import component.KotlinEnvironment
55
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
6+
import org.jetbrains.kotlin.config.CompilerConfiguration
67
import org.jetbrains.kotlin.ir.backend.js.prepareAnalyzedSourceModule
7-
import org.jetbrains.kotlin.js.config.JsConfig
8-
import org.jetbrains.kotlin.resolve.CompilerEnvironment
98

10-
class JsIndexationBuilder(private val kotlinEnvironment: KotlinEnvironment): IndexationBuilder() {
9+
class WebIndexationBuilder(
10+
private val kotlinEnvironment: KotlinEnvironment,
11+
private val configuration: CompilerConfiguration,
12+
private val libraries: List<String>
13+
): IndexationBuilder() {
14+
1115
override fun getAllIndexes(): List<ImportInfo> =
1216
kotlinEnvironment.environment { coreEnvironment ->
1317
val project = coreEnvironment.project
1418

1519
val sourceModule = prepareAnalyzedSourceModule(
1620
project,
1721
coreEnvironment.getSourceFiles(),
18-
kotlinEnvironment.jsConfiguration,
19-
kotlinEnvironment.JS_LIBRARIES,
22+
configuration,
23+
libraries,
2024
friendDependencies = emptyList(),
2125
analyzer = AnalyzerWithCompilerReport(kotlinEnvironment.jsConfiguration),
2226
)
@@ -29,4 +33,4 @@ class JsIndexationBuilder(private val kotlinEnvironment: KotlinEnvironment): Ind
2933
moduleDescriptor.allImportsInfo()
3034
}.distinct()
3135
}
32-
}
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)