Skip to content

Commit

Permalink
Merge pull request #681 from JetBrains/ilgonmic/wasm-frontend
Browse files Browse the repository at this point in the history
Use wasm frontend for wasm target
  • Loading branch information
nikpachoo authored Nov 13, 2023
2 parents 2696f48 + 667d2b4 commit 19a25ed
Show file tree
Hide file tree
Showing 20 changed files with 275 additions and 160 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
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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 @@ -160,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 Down Expand Up @@ -204,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
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ 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"
)
}
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ 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
import org.jetbrains.kotlin.js.config.JsConfig
import org.jetbrains.kotlin.resolve.CompilerEnvironment

class JsIndexationBuilder(private val kotlinEnvironment: KotlinEnvironment): IndexationBuilder() {
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(),
kotlinEnvironment.jsConfiguration,
kotlinEnvironment.JS_LIBRARIES,
configuration,
libraries,
friendDependencies = emptyList(),
analyzer = AnalyzerWithCompilerReport(kotlinEnvironment.jsConfiguration),
)
Expand All @@ -29,4 +33,4 @@ class JsIndexationBuilder(private val kotlinEnvironment: KotlinEnvironment): Ind
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 19a25ed

Please sign in to comment.