[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.PsiFileSystemItem
|
||||
import org.jetbrains.kotlin.analysis.project.structure.*
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.psi.psiUtil.contains
|
||||
import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
|
||||
class KtStaticModuleProvider(
|
||||
override val globalLanguageVersionSettings: LanguageVersionSettings,
|
||||
private val builtinsModule: KtBuiltinsModule,
|
||||
private val projectStructure: KtModuleProjectStructure,
|
||||
) : KtStaticProjectStructureProvider() {
|
||||
|
||||
+3
-1
@@ -64,9 +64,11 @@ class AnalysisApiEnvironmentManagerImpl(
|
||||
getProject()
|
||||
)
|
||||
|
||||
val globalLanguageVersionSettings = useSiteModule.languageVersionSettings
|
||||
|
||||
StandaloneProjectFactory.registerServicesForProjectEnvironment(
|
||||
_projectEnvironment,
|
||||
KtStaticModuleProvider(builtinsModule, ktModuleProjectStructure),
|
||||
KtStaticModuleProvider(globalLanguageVersionSettings, builtinsModule, ktModuleProjectStructure),
|
||||
useSiteCompilerConfiguration.languageVersionSettings,
|
||||
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 {
|
||||
val builtinsSession = LLFirBuiltinsSessionFactory.getInstance(project).getBuiltinsSession(JvmPlatforms.unspecifiedJvmPlatform)
|
||||
val languageVersionSettings = LanguageVersionSettingsImpl.DEFAULT
|
||||
val languageVersionSettings = ProjectStructureProvider.getInstance(project).globalLanguageVersionSettings
|
||||
val scopeProvider = FirKotlinScopeProvider(::wrapScopeWithJvmMapped)
|
||||
val components = LLFirModuleResolveComponents(module, globalResolveComponents, scopeProvider)
|
||||
|
||||
@@ -333,7 +333,7 @@ internal abstract class LLFirAbstractSessionFactory(protected val project: Proje
|
||||
|
||||
val platform = module.platform
|
||||
val builtinsSession = LLFirBuiltinsSessionFactory.getInstance(project).getBuiltinsSession(platform)
|
||||
val languageVersionSettings = LanguageVersionSettingsImpl.DEFAULT
|
||||
val languageVersionSettings = ProjectStructureProvider.getInstance(project).libraryLanguageVersionSettings
|
||||
|
||||
val scopeProvider = FirKotlinScopeProvider()
|
||||
val components = LLFirModuleResolveComponents(module, globalResolveComponents, scopeProvider)
|
||||
@@ -427,7 +427,7 @@ internal abstract class LLFirAbstractSessionFactory(protected val project: Proje
|
||||
registerModuleData(moduleData)
|
||||
registerIdeComponents(project)
|
||||
register(FirLazyDeclarationResolver::class, FirDummyCompilerLazyDeclarationResolver)
|
||||
registerCommonComponents(LanguageVersionSettingsImpl.DEFAULT/*TODO*/)
|
||||
registerCommonComponents(ProjectStructureProvider.getInstance(project).libraryLanguageVersionSettings)
|
||||
registerCommonComponentsAfterExtensionsAreConfigured()
|
||||
|
||||
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.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
|
||||
public abstract class ProjectStructureProvider {
|
||||
/**
|
||||
@@ -24,6 +26,19 @@ public abstract class ProjectStructureProvider {
|
||||
*/
|
||||
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 fun getInstance(project: Project): ProjectStructureProvider {
|
||||
return project.getService(ProjectStructureProvider::class.java)
|
||||
|
||||
Reference in New Issue
Block a user