From 608ce7900d3af8e30dd747711d41ffc809278743 Mon Sep 17 00:00:00 2001 From: DragonKnightOfBreeze Date: Sat, 9 Sep 2023 18:14:00 +0800 Subject: [PATCH] =?UTF-8?q?1.1.8=20=E4=BC=98=E5=8C=96=E4=B8=8EBUG=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pls/core/psi/ParadoxParameterElement.kt | 2 +- .../windea/pls/lang/ParadoxModifierHandler.kt | 35 +++-- .../pls/lang/ParadoxParameterHandler.kt | 122 ++++++------------ .../lang/StellarisEconomicCategoryHandler.kt | 1 + ...adoxParameterValueConfigContextProvider.kt | 5 +- .../pls/lang/cwt/config/CwtConfigType.kt | 2 +- .../modifier/ParadoxModifierIconProvider.kt | 2 +- .../ParadoxModifierNameDescProvider.kt | 2 +- .../lang/modifier/ParadoxModifierSupport.kt | 4 +- .../impl/ParadoxModifierIconProviders.kt | 1 + .../impl/ParadoxModifierNameDescProviders.kt | 2 +- .../impl/ParadoxPredefinedModifierSupport.kt | 2 +- .../impl/ParadoxTemplateModifierSupport.kt | 2 + ...tellarisEconomicCategoryModifierSupport.kt | 4 +- .../lang/parameter/ParadoxParameterSupport.kt | 21 ++- .../impl/ParadoxDefinitionParameterSupport.kt | 7 +- .../ParadoxInlineScriptParameterSupport.kt | 5 +- .../model/{ => data}/ParadoxModifierData.kt | 23 ++-- .../pls/model/data/ParadoxParameterData.kt | 34 +++++ 19 files changed, 156 insertions(+), 120 deletions(-) rename src/main/kotlin/icu/windea/pls/model/{ => data}/ParadoxModifierData.kt (52%) create mode 100644 src/main/kotlin/icu/windea/pls/model/data/ParadoxParameterData.kt diff --git a/src/main/kotlin/icu/windea/pls/core/psi/ParadoxParameterElement.kt b/src/main/kotlin/icu/windea/pls/core/psi/ParadoxParameterElement.kt index cd27ed988..8e3c063dc 100644 --- a/src/main/kotlin/icu/windea/pls/core/psi/ParadoxParameterElement.kt +++ b/src/main/kotlin/icu/windea/pls/core/psi/ParadoxParameterElement.kt @@ -23,7 +23,7 @@ class ParadoxParameterElement( parent: PsiElement, private val name: String, val contextName: String, - val contextIcon: Icon, + val contextIcon: Icon?, val contextKey: String, val rangeInParent: TextRange?, val readWriteAccess: ReadWriteAccessDetector.Access, diff --git a/src/main/kotlin/icu/windea/pls/lang/ParadoxModifierHandler.kt b/src/main/kotlin/icu/windea/pls/lang/ParadoxModifierHandler.kt index cb328189e..cc377375e 100644 --- a/src/main/kotlin/icu/windea/pls/lang/ParadoxModifierHandler.kt +++ b/src/main/kotlin/icu/windea/pls/lang/ParadoxModifierHandler.kt @@ -22,6 +22,7 @@ import icu.windea.pls.lang.modifier.* import icu.windea.pls.lang.modifier.impl.* import icu.windea.pls.model.* import icu.windea.pls.model.constraints.* +import icu.windea.pls.model.data.* import icu.windea.pls.script.psi.* import icu.windea.pls.tool.localisation.* @@ -51,7 +52,7 @@ object ParadoxModifierHandler { fun resolveModifier(name: String, element: PsiElement, configGroup: CwtConfigGroup, useSupport: ParadoxModifierSupport? = null): ParadoxModifierElement? { val modifierData = getModifierData(name, element, configGroup, useSupport) - return modifierData?.toModifierElement(element) + return modifierData?.toPsiElement(element) } fun completeModifier(context: ProcessingContext, result: CompletionResultSet) { @@ -62,13 +63,6 @@ object ParadoxModifierHandler { ParadoxModifierSupport.completeModifier(context, result, modifierNames) } - fun getModifierData(name: String, element: PsiElement): ParadoxModifierData? { - val gameType = selectGameType(element) ?: return null - val project = element.project - val configGroup = getConfigGroups(project).get(gameType) - return getModifierData(name, element, configGroup) - } - fun getModifierData(name: String, element: PsiElement, configGroup: CwtConfigGroup, useSupport: ParadoxModifierSupport? = null): ParadoxModifierData? { val rootFile = selectRootFile(element) ?: return null val project = configGroup.project @@ -84,6 +78,31 @@ object ParadoxModifierHandler { return modifierData } + fun getModifierData(name: String, element: PsiElement): ParadoxModifierData? { + val gameType = selectGameType(element) ?: return null + val rootFile = selectRootFile(element) ?: return null + val project = element.project + val cache = project.modifierDataCache.get(rootFile) + val configGroup = getConfigGroups(project).get(gameType) + val cacheKey = name + val modifierData = cache.getOrPut(cacheKey) { + ParadoxModifierSupport.resolveModifier(name, element, configGroup) ?: ParadoxModifierData.EMPTY + } + if(modifierData == ParadoxModifierData.EMPTY) return null + return modifierData + } + + fun getModifierData(modifierElement: ParadoxModifierElement): ParadoxModifierData? { + val rootFile = selectRootFile(modifierElement) ?: return null + val project = modifierElement.project + val cache = project.modifierDataCache.get(rootFile) + val cacheKey = modifierElement.name + val modifierData = cache.getOrPut(cacheKey) { + modifierElement.toData() + } + return modifierData + } + fun getModifierNameKeys(name: String, element: PsiElement): Set { val modifierData = getModifierData(name, element) ?: return emptySet() return modifierData.getOrPutUserData(PlsKeys.modifierNameKeys) { diff --git a/src/main/kotlin/icu/windea/pls/lang/ParadoxParameterHandler.kt b/src/main/kotlin/icu/windea/pls/lang/ParadoxParameterHandler.kt index 4cb840ce2..c274b9900 100644 --- a/src/main/kotlin/icu/windea/pls/lang/ParadoxParameterHandler.kt +++ b/src/main/kotlin/icu/windea/pls/lang/ParadoxParameterHandler.kt @@ -7,7 +7,9 @@ import com.intellij.codeInsight.highlighting.* import com.intellij.codeInsight.lookup.* import com.intellij.openapi.editor.* import com.intellij.openapi.progress.* +import com.intellij.openapi.project.* import com.intellij.openapi.util.* +import com.intellij.openapi.vfs.* import com.intellij.psi.* import com.intellij.psi.util.* import com.intellij.util.* @@ -22,20 +24,13 @@ import icu.windea.pls.lang.cwt.config.* import icu.windea.pls.lang.cwt.expression.* import icu.windea.pls.lang.parameter.* import icu.windea.pls.model.* +import icu.windea.pls.model.data.* import icu.windea.pls.script.codeStyle.* import icu.windea.pls.script.psi.* import java.util.* @Suppress("UNUSED_PARAMETER") object ParadoxParameterHandler { - object Keys { - val inferredConfig = Key.create("paradox.parameter.inferredConfig") - val inferredContextConfigs = Key.create>>("paradox.parameter.inferredContextConfigs") - val parameterCache = KeyWithDefaultValue.create>("paradox.parameter.cache") { CacheBuilder.newBuilder().buildCache() } - val parameterModificationTracker = Key.create("paradox.parameter.modificationTracker") - val parameterModificationCount = Key.create("paradox.parameter.modificationCount") - } - /** * 得到[element]对应的参数上下文信息。 * @@ -166,47 +161,32 @@ object ParadoxParameterHandler { } } + fun getParameterData(parameterElement: ParadoxParameterElement): ParadoxParameterData? { + val rootFile = selectRootFile(parameterElement) ?: return null + val project = parameterElement.project + val cache = project.parameterDataCache.get(rootFile) + val cacheKey = parameterElement.name + "@" + parameterElement.contextKey + val parameterData = cache.getOrPut(cacheKey) { + parameterElement.toData() + } + return parameterData + } + /** * 尝试推断得到参数对应的CWT规则。 */ fun getInferredConfig(parameterElement: ParadoxParameterElement): CwtValueConfig? { - val cacheKey = parameterElement.contextKey + "@" + parameterElement.name - val parameterCache = selectRootFile(parameterElement.parent)?.getUserData(Keys.parameterCache) ?: return null - val cached = parameterCache.get(cacheKey) - if(cached != null) { - val modificationTracker = cached.getUserData(Keys.parameterModificationTracker) - if(modificationTracker != null) { - val modificationCount = cached.getUserData(Keys.parameterModificationCount) ?: 0 - if(modificationCount == modificationTracker.modificationCount) { - val resolved = cached.getUserData(Keys.inferredConfig) - if(resolved != null) { - return resolved.takeIf { it !== CwtValueConfig.EmptyConfig } - } - } - } - } - - val result = Ref.create() - ParadoxParameterSupport.processContext(parameterElement, true) p@{ context -> - ProgressManager.checkCanceled() - val contextInfo = ParadoxParameterSupport.getContextInfo(context) ?: return@p true - val config = getInferredConfig(parameterElement.name, contextInfo) - result.mergeValue(config) { v1, v2 -> ParadoxConfigMerger.mergeValueConfig(v1, v2) } - } - val resolved = result.get() - - val ep = parameterElement.getUserData(ParadoxParameterSupport.Keys.support) - if(ep != null) { - val modificationTracker = ep.getModificationTracker(parameterElement) - if(modificationTracker != null) { - parameterElement.putUserData(Keys.inferredConfig, resolved ?: CwtValueConfig.EmptyConfig) - parameterElement.putUserData(Keys.parameterModificationTracker, modificationTracker) - parameterElement.putUserData(Keys.parameterModificationCount, modificationTracker.modificationCount) - parameterCache.put(cacheKey, parameterElement) + val parameterData = getParameterData(parameterElement) ?: return null + return parameterData.getOrPutUserData(PlsKeys.parameterInferredConfig, CwtValueConfig.EmptyConfig) { + val result = Ref.create() + ParadoxParameterSupport.processContext(parameterElement, true) p@{ context -> + ProgressManager.checkCanceled() + val contextInfo = ParadoxParameterSupport.getContextInfo(context) ?: return@p true + val config = getInferredConfig(parameterElement.name, contextInfo) + result.mergeValue(config) { v1, v2 -> ParadoxConfigMerger.mergeValueConfig(v1, v2) } } + result.get() } - - return resolved } fun getInferredConfig(parameterName: String, parameterContextInfo: ParadoxParameterContextInfo): CwtValueConfig? { @@ -226,43 +206,17 @@ object ParadoxParameterHandler { * 尝试推断得到参数对应的上下文CWT规则。 */ fun getInferredContextConfigs(parameterElement: ParadoxParameterElement): List> { - val cacheKey = parameterElement.contextKey + "@" + parameterElement.name - val parameterCache = selectRootFile(parameterElement.parent)?.getUserData(Keys.parameterCache) ?: return emptyList() - val cached = parameterCache.get(cacheKey) - if(cached != null) { - val modificationTracker = cached.getUserData(Keys.parameterModificationTracker) - if(modificationTracker != null) { - val modificationCount = cached.getUserData(Keys.parameterModificationCount) ?: 0 - if(modificationCount == modificationTracker.modificationCount) { - val resolved = cached.getUserData(Keys.inferredContextConfigs) - if(resolved != null) { - return resolved - } - } - } - } - - val result = Ref.create>>() - ParadoxParameterSupport.processContext(parameterElement, true) p@{ context -> - ProgressManager.checkCanceled() - val contextInfo = ParadoxParameterSupport.getContextInfo(context) ?: return@p true - val contextConfigs = getInferredContextConfigs(parameterElement.name, contextInfo).orNull() - result.mergeValue(contextConfigs) { v1, v2 -> ParadoxConfigMerger.mergeConfigs(v1, v2) } - } - val resolved = result.get().orEmpty() - - val ep = parameterElement.getUserData(ParadoxParameterSupport.Keys.support) - if(ep != null) { - val modificationTracker = ep.getModificationTracker(parameterElement) - if(modificationTracker != null) { - parameterElement.putUserData(Keys.inferredContextConfigs, resolved) - parameterElement.putUserData(Keys.parameterModificationTracker, modificationTracker) - parameterElement.putUserData(Keys.parameterModificationCount, modificationTracker.modificationCount) - parameterCache.put(cacheKey, parameterElement) + val parameterData = getParameterData(parameterElement) ?: return emptyList() + return parameterData.getOrPutUserData(PlsKeys.parameterInferredContextConfigs) { + val result = Ref.create>>() + ParadoxParameterSupport.processContext(parameterElement, true) p@{ context -> + ProgressManager.checkCanceled() + val contextInfo = ParadoxParameterSupport.getContextInfo(context) ?: return@p true + val contextConfigs = getInferredContextConfigs(parameterElement.name, contextInfo).orNull() + result.mergeValue(contextConfigs) { v1, v2 -> ParadoxConfigMerger.mergeConfigs(v1, v2) } } + return result.get().orEmpty() } - - return resolved } fun getInferredContextConfigs(parameterName: String, parameterContextInfo: ParadoxParameterContextInfo): List> { @@ -272,7 +226,7 @@ object ParadoxParameterHandler { parameterInfos.process { parameterInfo -> ProgressManager.checkCanceled() val contextConfigs = ParadoxParameterInferredConfigProvider.getContextConfigs(parameterInfo, parameterContextInfo).orNull() - result.mergeValue(contextConfigs) { v1,v2 -> ParadoxConfigMerger.mergeConfigs(v1, v2) } + result.mergeValue(contextConfigs) { v1, v2 -> ParadoxConfigMerger.mergeConfigs(v1, v2) } } return result.get().orEmpty() } @@ -283,4 +237,12 @@ object ParadoxParameterHandler { else -> false } } -} \ No newline at end of file +} + +private val PlsKeys.parameterDataCache by createKey("paradox.parameterDataCache") { + NestedCache { CacheBuilder.newBuilder().buildCache().trackedBy { it.modificationTracker } } +} +private val Project.parameterDataCache by PlsKeys.parameterDataCache + +private val PlsKeys.parameterInferredConfig by Key.create("paradox.parameterInferredConfig") +private val PlsKeys.parameterInferredContextConfigs by Key.create>>("paradox.parameterInferredContextConfigs") \ No newline at end of file diff --git a/src/main/kotlin/icu/windea/pls/lang/StellarisEconomicCategoryHandler.kt b/src/main/kotlin/icu/windea/pls/lang/StellarisEconomicCategoryHandler.kt index f92414657..705c057a8 100644 --- a/src/main/kotlin/icu/windea/pls/lang/StellarisEconomicCategoryHandler.kt +++ b/src/main/kotlin/icu/windea/pls/lang/StellarisEconomicCategoryHandler.kt @@ -65,6 +65,7 @@ object StellarisEconomicCategoryHandler { // __enum[economic_modifier_categories]_enum[economic_modifier_types] = { "AI Economy" } fun addModifier(key: String, category: String, type: String, triggered: Boolean, useParentIcon: Boolean) { + if(key.isEmpty()) return //skip invalid keys if(useForAiBudget || (type == "mult" && useForAiBudgetForMult)) { modifiers.add(StellarisEconomicCategoryModifierInfo(key, null, category, type, triggered, useParentIcon)) } diff --git a/src/main/kotlin/icu/windea/pls/lang/config/impl/ParadoxParameterValueConfigContextProvider.kt b/src/main/kotlin/icu/windea/pls/lang/config/impl/ParadoxParameterValueConfigContextProvider.kt index 5c317c047..a6649b116 100644 --- a/src/main/kotlin/icu/windea/pls/lang/config/impl/ParadoxParameterValueConfigContextProvider.kt +++ b/src/main/kotlin/icu/windea/pls/lang/config/impl/ParadoxParameterValueConfigContextProvider.kt @@ -89,10 +89,7 @@ class ParadoxParameterValueConfigContextProvider : ParadoxConfigContextProvider val parameterElement = configContext.parameterElement ?: return null - //unsupported -> return null - val inferredContextConfigs = ParadoxParameterHandler.getInferredContextConfigs(parameterElement) - if(inferredContextConfigs.singleOrNull() == CwtValueConfig.EmptyConfig) return null - return inferredContextConfigs + return ParadoxParameterHandler.getInferredContextConfigs(parameterElement) } //skip MissingExpressionInspection and TooManyExpressionInspection at root level diff --git a/src/main/kotlin/icu/windea/pls/lang/cwt/config/CwtConfigType.kt b/src/main/kotlin/icu/windea/pls/lang/cwt/config/CwtConfigType.kt index ceb725246..c47cab1ba 100644 --- a/src/main/kotlin/icu/windea/pls/lang/cwt/config/CwtConfigType.kt +++ b/src/main/kotlin/icu/windea/pls/lang/cwt/config/CwtConfigType.kt @@ -119,7 +119,7 @@ enum class CwtConfigType( return when(this) { Type, Subtype, Enum, ComplexEnum, ValueSet -> name.substringIn('[',']') SingleAlias -> name.substringIn('[',']') - Alias, Modifier, Trigger, Effect -> name.substringIn('[',']').substringAfter(':') + Alias, Trigger, Effect -> name.substringIn('[',']').substringAfter(':') else -> name } } diff --git a/src/main/kotlin/icu/windea/pls/lang/modifier/ParadoxModifierIconProvider.kt b/src/main/kotlin/icu/windea/pls/lang/modifier/ParadoxModifierIconProvider.kt index 4e41ef507..a21df6af7 100644 --- a/src/main/kotlin/icu/windea/pls/lang/modifier/ParadoxModifierIconProvider.kt +++ b/src/main/kotlin/icu/windea/pls/lang/modifier/ParadoxModifierIconProvider.kt @@ -5,7 +5,7 @@ import com.intellij.psi.* import icu.windea.pls.core.* import icu.windea.pls.core.annotations.* import icu.windea.pls.core.collections.* -import icu.windea.pls.model.* +import icu.windea.pls.model.data.* /** * 用于为修正提供图标的图片。 diff --git a/src/main/kotlin/icu/windea/pls/lang/modifier/ParadoxModifierNameDescProvider.kt b/src/main/kotlin/icu/windea/pls/lang/modifier/ParadoxModifierNameDescProvider.kt index 929e3441f..21b5acb75 100644 --- a/src/main/kotlin/icu/windea/pls/lang/modifier/ParadoxModifierNameDescProvider.kt +++ b/src/main/kotlin/icu/windea/pls/lang/modifier/ParadoxModifierNameDescProvider.kt @@ -5,7 +5,7 @@ import com.intellij.psi.* import icu.windea.pls.core.* import icu.windea.pls.core.annotations.* import icu.windea.pls.core.collections.* -import icu.windea.pls.model.* +import icu.windea.pls.model.data.* /** * 用于为修正提供名字和描述的本地化。 diff --git a/src/main/kotlin/icu/windea/pls/lang/modifier/ParadoxModifierSupport.kt b/src/main/kotlin/icu/windea/pls/lang/modifier/ParadoxModifierSupport.kt index 15e4d1acc..b33e4f4fe 100644 --- a/src/main/kotlin/icu/windea/pls/lang/modifier/ParadoxModifierSupport.kt +++ b/src/main/kotlin/icu/windea/pls/lang/modifier/ParadoxModifierSupport.kt @@ -13,6 +13,7 @@ import icu.windea.pls.core.psi.* import icu.windea.pls.lang.cwt.* import icu.windea.pls.lang.cwt.config.* import icu.windea.pls.model.* +import icu.windea.pls.model.data.* import icu.windea.pls.script.psi.* /** @@ -106,6 +107,7 @@ val ParadoxModifierSupport.Keys.support by createKey("pa val ParadoxModifierSupport.Keys.modifierConfig by createKey("paradox.modifier.support.modifierConfig") var ParadoxModifierData.support by ParadoxModifierSupport.Keys.support -var ParadoxModifierElement.support by ParadoxModifierSupport.Keys.support var ParadoxModifierData.modifierConfig by ParadoxModifierSupport.Keys.modifierConfig + +var ParadoxModifierElement.support by ParadoxModifierSupport.Keys.support var ParadoxModifierElement.modifierConfig by ParadoxModifierSupport.Keys.modifierConfig diff --git a/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxModifierIconProviders.kt b/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxModifierIconProviders.kt index 3cbe23898..6b0899c52 100644 --- a/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxModifierIconProviders.kt +++ b/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxModifierIconProviders.kt @@ -12,6 +12,7 @@ import icu.windea.pls.lang.cwt.config.* import icu.windea.pls.lang.cwt.expression.* import icu.windea.pls.lang.modifier.* import icu.windea.pls.model.* +import icu.windea.pls.model.data.* import icu.windea.pls.script.psi.* class ParadoxBaseModifierIconProvider : ParadoxModifierIconProvider { diff --git a/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxModifierNameDescProviders.kt b/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxModifierNameDescProviders.kt index ccaa7c49b..c088864df 100644 --- a/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxModifierNameDescProviders.kt +++ b/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxModifierNameDescProviders.kt @@ -2,7 +2,7 @@ package icu.windea.pls.lang.modifier.impl import com.intellij.psi.* import icu.windea.pls.lang.modifier.* -import icu.windea.pls.model.* +import icu.windea.pls.model.data.* class ParadoxBaseModifierNameDescProvider : ParadoxModifierNameDescProvider { override fun addModifierNameKey(modifierData: ParadoxModifierData, element: PsiElement, registry: MutableSet) { diff --git a/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxPredefinedModifierSupport.kt b/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxPredefinedModifierSupport.kt index 281ae43b5..ad656c720 100644 --- a/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxPredefinedModifierSupport.kt +++ b/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxPredefinedModifierSupport.kt @@ -12,7 +12,7 @@ import icu.windea.pls.lang.* import icu.windea.pls.lang.cwt.* import icu.windea.pls.lang.cwt.config.* import icu.windea.pls.lang.modifier.* -import icu.windea.pls.model.* +import icu.windea.pls.model.data.* import icu.windea.pls.script.psi.* /** diff --git a/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxTemplateModifierSupport.kt b/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxTemplateModifierSupport.kt index 0d230e088..5fc038045 100644 --- a/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxTemplateModifierSupport.kt +++ b/src/main/kotlin/icu/windea/pls/lang/modifier/impl/ParadoxTemplateModifierSupport.kt @@ -19,6 +19,7 @@ import icu.windea.pls.lang.cwt.config.* import icu.windea.pls.lang.cwt.expression.* import icu.windea.pls.lang.modifier.* import icu.windea.pls.model.* +import icu.windea.pls.model.data.* import icu.windea.pls.script.psi.* /** @@ -209,4 +210,5 @@ class ParadoxTemplateModifierSupport : ParadoxModifierSupport { val ParadoxModifierSupport.Keys.templateReferences by createKey>("paradox.modifier.support.templateReferences") var ParadoxModifierData.templateReferences by ParadoxModifierSupport.Keys.templateReferences + var ParadoxModifierElement.templateReferences by ParadoxModifierSupport.Keys.templateReferences \ No newline at end of file diff --git a/src/main/kotlin/icu/windea/pls/lang/modifier/impl/StellarisEconomicCategoryModifierSupport.kt b/src/main/kotlin/icu/windea/pls/lang/modifier/impl/StellarisEconomicCategoryModifierSupport.kt index 875d7aaa2..e3a869202 100644 --- a/src/main/kotlin/icu/windea/pls/lang/modifier/impl/StellarisEconomicCategoryModifierSupport.kt +++ b/src/main/kotlin/icu/windea/pls/lang/modifier/impl/StellarisEconomicCategoryModifierSupport.kt @@ -19,6 +19,7 @@ import icu.windea.pls.lang.cwt.* import icu.windea.pls.lang.cwt.config.* import icu.windea.pls.lang.modifier.* import icu.windea.pls.model.* +import icu.windea.pls.model.data.* import icu.windea.pls.script.psi.* /** @@ -186,6 +187,7 @@ val ParadoxModifierSupport.Keys.economicCategoryInfo by createKey("paradox.modifier.support.economicCategoryModifierInfo") var ParadoxModifierData.economicCategoryInfo by ParadoxModifierSupport.Keys.economicCategoryInfo -var ParadoxModifierElement.economicCategoryInfo by ParadoxModifierSupport.Keys.economicCategoryInfo var ParadoxModifierData.economicCategoryModifierInfo by ParadoxModifierSupport.Keys.economicCategoryModifierInfo + +var ParadoxModifierElement.economicCategoryInfo by ParadoxModifierSupport.Keys.economicCategoryInfo var ParadoxModifierElement.economicCategoryModifierInfo by ParadoxModifierSupport.Keys.economicCategoryModifierInfo \ No newline at end of file diff --git a/src/main/kotlin/icu/windea/pls/lang/parameter/ParadoxParameterSupport.kt b/src/main/kotlin/icu/windea/pls/lang/parameter/ParadoxParameterSupport.kt index b7c867d60..5bbc8e226 100644 --- a/src/main/kotlin/icu/windea/pls/lang/parameter/ParadoxParameterSupport.kt +++ b/src/main/kotlin/icu/windea/pls/lang/parameter/ParadoxParameterSupport.kt @@ -7,6 +7,7 @@ import icu.windea.pls.core.* import icu.windea.pls.core.psi.* import icu.windea.pls.lang.cwt.config.* import icu.windea.pls.model.* +import icu.windea.pls.model.data.* import icu.windea.pls.script.psi.* /** @@ -49,7 +50,7 @@ interface ParadoxParameterSupport { */ fun processContext(element: PsiElement, contextReferenceInfo: ParadoxParameterContextReferenceInfo, onlyMostRelevant: Boolean, processor: (ParadoxScriptDefinitionElement) -> Boolean): Boolean - fun getModificationTracker(parameterElement: ParadoxParameterElement): ModificationTracker? = null + fun getModificationTracker(parameterData: ParadoxParameterData): ModificationTracker? = null /** * 构建参数的快速文档中的定义部分。 @@ -127,15 +128,23 @@ val ParadoxParameterSupport.Keys.definitionName by createKey("paradox.pa val ParadoxParameterSupport.Keys.definitionTypes by createKey>("paradox.parameter.support.definitionTypes") val ParadoxParameterSupport.Keys.inlineScriptExpression by createKey("paradox.parameter.support.inlineScriptExpression") +var ParadoxParameterData.support by ParadoxParameterSupport.Keys.support +var ParadoxParameterData.containingContext by ParadoxParameterSupport.Keys.containingContext +var ParadoxParameterData.containingContextReference by ParadoxParameterSupport.Keys.containingContextReference +var ParadoxParameterData.definitionName by ParadoxParameterSupport.Keys.definitionName +var ParadoxParameterData.definitionTypes by ParadoxParameterSupport.Keys.definitionTypes +var ParadoxParameterData.inlineScriptExpression by ParadoxParameterSupport.Keys.inlineScriptExpression + var ParadoxParameterElement.support by ParadoxParameterSupport.Keys.support -var ParadoxParameterContextReferenceInfo.support by ParadoxParameterSupport.Keys.support var ParadoxParameterElement.containingContext by ParadoxParameterSupport.Keys.containingContext -var ParadoxParameterContextReferenceInfo.containingContext by ParadoxParameterSupport.Keys.containingContext var ParadoxParameterElement.containingContextReference by ParadoxParameterSupport.Keys.containingContextReference -var ParadoxParameterContextReferenceInfo.containingContextReference by ParadoxParameterSupport.Keys.containingContextReference var ParadoxParameterElement.definitionName by ParadoxParameterSupport.Keys.definitionName -var ParadoxParameterContextReferenceInfo.definitionName by ParadoxParameterSupport.Keys.definitionName var ParadoxParameterElement.definitionTypes by ParadoxParameterSupport.Keys.definitionTypes -var ParadoxParameterContextReferenceInfo.definitionTypes by ParadoxParameterSupport.Keys.definitionTypes var ParadoxParameterElement.inlineScriptExpression by ParadoxParameterSupport.Keys.inlineScriptExpression + +var ParadoxParameterContextReferenceInfo.support by ParadoxParameterSupport.Keys.support +var ParadoxParameterContextReferenceInfo.containingContext by ParadoxParameterSupport.Keys.containingContext +var ParadoxParameterContextReferenceInfo.containingContextReference by ParadoxParameterSupport.Keys.containingContextReference +var ParadoxParameterContextReferenceInfo.definitionName by ParadoxParameterSupport.Keys.definitionName +var ParadoxParameterContextReferenceInfo.definitionTypes by ParadoxParameterSupport.Keys.definitionTypes var ParadoxParameterContextReferenceInfo.inlineScriptExpression by ParadoxParameterSupport.Keys.inlineScriptExpression \ No newline at end of file diff --git a/src/main/kotlin/icu/windea/pls/lang/parameter/impl/ParadoxDefinitionParameterSupport.kt b/src/main/kotlin/icu/windea/pls/lang/parameter/impl/ParadoxDefinitionParameterSupport.kt index aa8c59951..380aefc97 100644 --- a/src/main/kotlin/icu/windea/pls/lang/parameter/impl/ParadoxDefinitionParameterSupport.kt +++ b/src/main/kotlin/icu/windea/pls/lang/parameter/impl/ParadoxDefinitionParameterSupport.kt @@ -16,6 +16,7 @@ import icu.windea.pls.lang.cwt.config.* import icu.windea.pls.lang.cwt.expression.* import icu.windea.pls.lang.parameter.* import icu.windea.pls.model.* +import icu.windea.pls.model.data.* import icu.windea.pls.script.psi.* open class ParadoxDefinitionParameterSupport : ParadoxParameterSupport { @@ -179,9 +180,9 @@ open class ParadoxDefinitionParameterSupport : ParadoxParameterSupport { return true } - override fun getModificationTracker(parameterElement: ParadoxParameterElement): ModificationTracker { - val project = parameterElement.project - val configGroup = getConfigGroups(project).get(parameterElement.gameType) + override fun getModificationTracker(parameterData: ParadoxParameterData): ModificationTracker? { + val project = parameterData.project + val configGroup = getConfigGroups(project).get(parameterData.gameType) return configGroup.getOrPutUserData(CwtConfigGroup.Keys.parameterModificationTracker) { val definitionTypes = configGroup.definitionTypesSupportParameters val builder = StringBuilder() diff --git a/src/main/kotlin/icu/windea/pls/lang/parameter/impl/ParadoxInlineScriptParameterSupport.kt b/src/main/kotlin/icu/windea/pls/lang/parameter/impl/ParadoxInlineScriptParameterSupport.kt index 1004aa792..39983fd42 100644 --- a/src/main/kotlin/icu/windea/pls/lang/parameter/impl/ParadoxInlineScriptParameterSupport.kt +++ b/src/main/kotlin/icu/windea/pls/lang/parameter/impl/ParadoxInlineScriptParameterSupport.kt @@ -14,6 +14,7 @@ import icu.windea.pls.lang.cwt.config.* import icu.windea.pls.lang.cwt.expression.* import icu.windea.pls.lang.parameter.* import icu.windea.pls.model.* +import icu.windea.pls.model.data.* import icu.windea.pls.script.psi.* open class ParadoxInlineScriptParameterSupport : ParadoxParameterSupport { @@ -166,8 +167,8 @@ open class ParadoxInlineScriptParameterSupport : ParadoxParameterSupport { return true } - override fun getModificationTracker(parameterElement: ParadoxParameterElement): ModificationTracker { - return ParadoxPsiModificationTracker.getInstance(parameterElement.project).InlineScriptsTracker + override fun getModificationTracker(parameterData: ParadoxParameterData): ModificationTracker { + return ParadoxPsiModificationTracker.getInstance(parameterData.project).InlineScriptsTracker } override fun buildDocumentationDefinition(parameterElement: ParadoxParameterElement, builder: StringBuilder): Boolean = with(builder) { diff --git a/src/main/kotlin/icu/windea/pls/model/ParadoxModifierData.kt b/src/main/kotlin/icu/windea/pls/model/data/ParadoxModifierData.kt similarity index 52% rename from src/main/kotlin/icu/windea/pls/model/ParadoxModifierData.kt rename to src/main/kotlin/icu/windea/pls/model/data/ParadoxModifierData.kt index 0c9f76f4b..1220d2b72 100644 --- a/src/main/kotlin/icu/windea/pls/model/ParadoxModifierData.kt +++ b/src/main/kotlin/icu/windea/pls/model/data/ParadoxModifierData.kt @@ -1,25 +1,30 @@ -package icu.windea.pls.model +package icu.windea.pls.model.data import com.intellij.openapi.project.* import com.intellij.openapi.util.* -import com.intellij.psi.PsiElement +import com.intellij.psi.* import icu.windea.pls.core.* import icu.windea.pls.core.psi.* -import icu.windea.pls.lang.cwt.config.* import icu.windea.pls.lang.modifier.* +import icu.windea.pls.model.* data class ParadoxModifierData( val name: String, val gameType: ParadoxGameType, val project: Project, -): UserDataHolderBase() { +) : UserDataHolderBase() { val modificationTracker by lazy { support?.getModificationTracker(this) } - fun toModifierElement(element: PsiElement) : ParadoxModifierElement{ - return ParadoxModifierElement(element, name, gameType, project).also { copyUserDataTo(it) } - } - companion object { val EMPTY = ParadoxModifierData("", ParadoxGameType.placeholder(), getDefaultProject()) } -} \ No newline at end of file +} + +fun ParadoxModifierData.toPsiElement(parent: PsiElement): ParadoxModifierElement { + return ParadoxModifierElement(parent, name, gameType, project).also { copyUserDataTo(it) } +} + +fun ParadoxModifierElement.toData(): ParadoxModifierData { + return ParadoxModifierData(name, gameType, project).also { copyUserDataTo(it) } +} + diff --git a/src/main/kotlin/icu/windea/pls/model/data/ParadoxParameterData.kt b/src/main/kotlin/icu/windea/pls/model/data/ParadoxParameterData.kt new file mode 100644 index 000000000..e7f8ddddc --- /dev/null +++ b/src/main/kotlin/icu/windea/pls/model/data/ParadoxParameterData.kt @@ -0,0 +1,34 @@ +package icu.windea.pls.model.data + +import com.intellij.codeInsight.highlighting.* +import com.intellij.openapi.project.* +import com.intellij.openapi.util.* +import com.intellij.psi.* +import icu.windea.pls.core.* +import icu.windea.pls.core.psi.* +import icu.windea.pls.lang.parameter.* +import icu.windea.pls.model.* +import javax.swing.* + +data class ParadoxParameterData( + val name: String, + val contextName: String, + val contextIcon: Icon?, + val contextKey: String, + val gameType: ParadoxGameType, + val project: Project, +) : UserDataHolderBase() { + val modificationTracker by lazy { support?.getModificationTracker(this) } + + companion object { + val EMPTY = ParadoxParameterData("", "", null, "", ParadoxGameType.placeholder(), getDefaultProject()) + } +} + +fun ParadoxParameterData.toPsiElement(parent: PsiElement, rangeInParent: TextRange?, readWriteAccess: ReadWriteAccessDetector.Access): ParadoxParameterElement { + return ParadoxParameterElement(parent, name, contextName, contextIcon, contextKey, rangeInParent, readWriteAccess, gameType, project) +} + +fun ParadoxParameterElement.toData(): ParadoxParameterData { + return ParadoxParameterData(name, contextName, contextIcon, contextKey, gameType, project) +} \ No newline at end of file