[LL API] Provide customizable default language version settings
This commit is contained in:
+2
@@ -8,11 +8,13 @@ package org.jetbrains.kotlin.analysis.api.standalone.base.project.structure
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiFileSystemItem
|
import com.intellij.psi.PsiFileSystemItem
|
||||||
import org.jetbrains.kotlin.analysis.project.structure.*
|
import org.jetbrains.kotlin.analysis.project.structure.*
|
||||||
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.contains
|
import org.jetbrains.kotlin.psi.psiUtil.contains
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol
|
import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol
|
||||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||||
|
|
||||||
class KtStaticModuleProvider(
|
class KtStaticModuleProvider(
|
||||||
|
override val globalLanguageVersionSettings: LanguageVersionSettings,
|
||||||
private val builtinsModule: KtBuiltinsModule,
|
private val builtinsModule: KtBuiltinsModule,
|
||||||
private val projectStructure: KtModuleProjectStructure,
|
private val projectStructure: KtModuleProjectStructure,
|
||||||
) : KtStaticProjectStructureProvider() {
|
) : KtStaticProjectStructureProvider() {
|
||||||
|
|||||||
+3
-1
@@ -64,9 +64,11 @@ class AnalysisApiEnvironmentManagerImpl(
|
|||||||
getProject()
|
getProject()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val globalLanguageVersionSettings = useSiteModule.languageVersionSettings
|
||||||
|
|
||||||
StandaloneProjectFactory.registerServicesForProjectEnvironment(
|
StandaloneProjectFactory.registerServicesForProjectEnvironment(
|
||||||
_projectEnvironment,
|
_projectEnvironment,
|
||||||
KtStaticModuleProvider(builtinsModule, ktModuleProjectStructure),
|
KtStaticModuleProvider(globalLanguageVersionSettings, builtinsModule, ktModuleProjectStructure),
|
||||||
useSiteCompilerConfiguration.languageVersionSettings,
|
useSiteCompilerConfiguration.languageVersionSettings,
|
||||||
useSiteCompilerConfiguration.get(JVMConfigurationKeys.JDK_HOME)?.toPath(),
|
useSiteCompilerConfiguration.get(JVMConfigurationKeys.JDK_HOME)?.toPath(),
|
||||||
)
|
)
|
||||||
|
|||||||
+3
-3
@@ -179,7 +179,7 @@ internal abstract class LLFirAbstractSessionFactory(protected val project: Proje
|
|||||||
|
|
||||||
fun createNotUnderContentRootResolvableSession(module: KtNotUnderContentRootModule): LLFirNotUnderContentRootResolvableModuleSession {
|
fun createNotUnderContentRootResolvableSession(module: KtNotUnderContentRootModule): LLFirNotUnderContentRootResolvableModuleSession {
|
||||||
val builtinsSession = LLFirBuiltinsSessionFactory.getInstance(project).getBuiltinsSession(JvmPlatforms.unspecifiedJvmPlatform)
|
val builtinsSession = LLFirBuiltinsSessionFactory.getInstance(project).getBuiltinsSession(JvmPlatforms.unspecifiedJvmPlatform)
|
||||||
val languageVersionSettings = LanguageVersionSettingsImpl.DEFAULT
|
val languageVersionSettings = ProjectStructureProvider.getInstance(project).globalLanguageVersionSettings
|
||||||
val scopeProvider = FirKotlinScopeProvider(::wrapScopeWithJvmMapped)
|
val scopeProvider = FirKotlinScopeProvider(::wrapScopeWithJvmMapped)
|
||||||
val components = LLFirModuleResolveComponents(module, globalResolveComponents, scopeProvider)
|
val components = LLFirModuleResolveComponents(module, globalResolveComponents, scopeProvider)
|
||||||
|
|
||||||
@@ -333,7 +333,7 @@ internal abstract class LLFirAbstractSessionFactory(protected val project: Proje
|
|||||||
|
|
||||||
val platform = module.platform
|
val platform = module.platform
|
||||||
val builtinsSession = LLFirBuiltinsSessionFactory.getInstance(project).getBuiltinsSession(platform)
|
val builtinsSession = LLFirBuiltinsSessionFactory.getInstance(project).getBuiltinsSession(platform)
|
||||||
val languageVersionSettings = LanguageVersionSettingsImpl.DEFAULT
|
val languageVersionSettings = ProjectStructureProvider.getInstance(project).libraryLanguageVersionSettings
|
||||||
|
|
||||||
val scopeProvider = FirKotlinScopeProvider()
|
val scopeProvider = FirKotlinScopeProvider()
|
||||||
val components = LLFirModuleResolveComponents(module, globalResolveComponents, scopeProvider)
|
val components = LLFirModuleResolveComponents(module, globalResolveComponents, scopeProvider)
|
||||||
@@ -427,7 +427,7 @@ internal abstract class LLFirAbstractSessionFactory(protected val project: Proje
|
|||||||
registerModuleData(moduleData)
|
registerModuleData(moduleData)
|
||||||
registerIdeComponents(project)
|
registerIdeComponents(project)
|
||||||
register(FirLazyDeclarationResolver::class, FirDummyCompilerLazyDeclarationResolver)
|
register(FirLazyDeclarationResolver::class, FirDummyCompilerLazyDeclarationResolver)
|
||||||
registerCommonComponents(LanguageVersionSettingsImpl.DEFAULT/*TODO*/)
|
registerCommonComponents(ProjectStructureProvider.getInstance(project).libraryLanguageVersionSettings)
|
||||||
registerCommonComponentsAfterExtensionsAreConfigured()
|
registerCommonComponentsAfterExtensionsAreConfigured()
|
||||||
|
|
||||||
val kotlinScopeProvider = FirKotlinScopeProvider(::wrapScopeWithJvmMapped)
|
val kotlinScopeProvider = FirKotlinScopeProvider(::wrapScopeWithJvmMapped)
|
||||||
|
|||||||
+15
@@ -7,6 +7,8 @@ package org.jetbrains.kotlin.analysis.project.structure
|
|||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
|
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||||
|
|
||||||
public abstract class ProjectStructureProvider {
|
public abstract class ProjectStructureProvider {
|
||||||
/**
|
/**
|
||||||
@@ -24,6 +26,19 @@ public abstract class ProjectStructureProvider {
|
|||||||
*/
|
*/
|
||||||
public abstract fun getModule(element: PsiElement, contextualModule: KtModule?): KtModule
|
public abstract fun getModule(element: PsiElement, contextualModule: KtModule?): KtModule
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project-global [LanguageVersionSettings]. For source modules lacking [LanguageVersionSettings]
|
||||||
|
* (such as [KtNotUnderContentRootModule]), the default settings apply.
|
||||||
|
*/
|
||||||
|
public open val globalLanguageVersionSettings: LanguageVersionSettings
|
||||||
|
get() = LanguageVersionSettingsImpl.DEFAULT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project-global [LanguageVersionSettings] for [KtLibraryModule]s and [KtLibrarySourceModule]s.
|
||||||
|
*/
|
||||||
|
public open val libraryLanguageVersionSettings: LanguageVersionSettings
|
||||||
|
get() = globalLanguageVersionSettings
|
||||||
|
|
||||||
public companion object {
|
public companion object {
|
||||||
public fun getInstance(project: Project): ProjectStructureProvider {
|
public fun getInstance(project: Project): ProjectStructureProvider {
|
||||||
return project.getService(ProjectStructureProvider::class.java)
|
return project.getService(ProjectStructureProvider::class.java)
|
||||||
|
|||||||
Reference in New Issue
Block a user