Support "default platform" in IDE via facet settings
This commit is contained in:
@@ -33,5 +33,6 @@
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="module" module-name="idea-core" />
|
||||
<orderEntry type="module" module-name="idea-jps-common" />
|
||||
<orderEntry type="module" module-name="cli-common" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.idea.project
|
||||
|
||||
import org.jetbrains.kotlin.analyzer.AnalyzerFacade
|
||||
import org.jetbrains.kotlin.analyzer.common.DefaultAnalyzerFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.JsAnalyzerFacade
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
@@ -29,8 +30,9 @@ object AnalyzerFacadeProvider {
|
||||
// otherwise we would be forced to add casts on the call site of setupResolverForProject
|
||||
fun getAnalyzerFacade(targetPlatform: TargetPlatform): AnalyzerFacade<JvmPlatformParameters> {
|
||||
return when (targetPlatform) {
|
||||
is JvmPlatform -> JvmAnalyzerFacade
|
||||
JvmPlatform -> JvmAnalyzerFacade
|
||||
JsPlatform -> JsAnalyzerFacade
|
||||
TargetPlatform.Default -> DefaultAnalyzerFacade
|
||||
else -> throw IllegalArgumentException("Unsupported platform: $targetPlatform")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ package org.jetbrains.kotlin.idea.project
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleUtilCore
|
||||
import com.sampullara.cli.Argument
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
@@ -30,13 +32,26 @@ val KtElement.platform: TargetPlatform
|
||||
val KtElement.builtIns: KotlinBuiltIns
|
||||
get() = getResolutionFacade().moduleDescriptor.builtIns
|
||||
|
||||
private val multiPlatformProjectsArg: String by lazy {
|
||||
"-" + CommonCompilerArguments::multiPlatform.annotations.filterIsInstance<Argument>().single().value
|
||||
}
|
||||
|
||||
val Module.languageVersionSettings: LanguageVersionSettings
|
||||
get() {
|
||||
val versionInfo = KotlinFacetSettingsProvider.getInstance(project).getSettings(this).versionInfo
|
||||
val facetSettings = KotlinFacetSettingsProvider.getInstance(project).getSettings(this)
|
||||
val versionInfo = facetSettings.versionInfo
|
||||
val languageVersion = versionInfo.languageLevel ?: LanguageVersion.LATEST
|
||||
val apiVersion = versionInfo.apiLevel ?: languageVersion
|
||||
return LanguageVersionSettingsImpl(languageVersion, ApiVersion.createByLanguageVersion(apiVersion))
|
||||
|
||||
val extraLanguageFeatures =
|
||||
if (versionInfo.targetPlatformKind == TargetPlatformKind.Default ||
|
||||
// TODO: this is a dirty hack, parse arguments correctly here
|
||||
facetSettings.compilerInfo.compilerSettings?.additionalArguments?.contains(multiPlatformProjectsArg) == true)
|
||||
listOf(LanguageFeature.MultiPlatformProjects)
|
||||
else emptyList()
|
||||
|
||||
return LanguageVersionSettingsImpl(languageVersion, ApiVersion.createByLanguageVersion(apiVersion), extraLanguageFeatures)
|
||||
}
|
||||
|
||||
val KtElement.languageVersionSettings: LanguageVersionSettings
|
||||
get() = ModuleUtilCore.findModuleForPsiElement(this)?.languageVersionSettings ?: LanguageVersionSettingsImpl.DEFAULT
|
||||
get() = ModuleUtilCore.findModuleForPsiElement(this)?.languageVersionSettings ?: LanguageVersionSettingsImpl.DEFAULT
|
||||
|
||||
@@ -44,6 +44,7 @@ public class ProjectStructureUtil {
|
||||
private ProjectStructureUtil() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
/* package */ static TargetPlatform getCachedPlatformForModule(@NotNull final Module module) {
|
||||
CachedValue<TargetPlatform> result = module.getUserData(PLATFORM_FOR_MODULE);
|
||||
if (result == null) {
|
||||
@@ -74,6 +75,9 @@ public class ProjectStructureUtil {
|
||||
if (kind instanceof TargetPlatformKind.JavaScript) {
|
||||
return JsPlatform.INSTANCE;
|
||||
}
|
||||
if (kind instanceof TargetPlatformKind.Default) {
|
||||
return TargetPlatform.Default.INSTANCE;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user