Skip to content

Commit

Permalink
1.3.0 支持在多行的脚本参数值中使用内联脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonKnightOfBreeze committed Dec 1, 2023
1 parent f48bf12 commit f07784d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* [ ] 可以设置是否启用基于扩展的CWT规则文件以及基于使用的各类推断,默认启用前者
* [ ] 导入CWT规则分组后,尝试优化为仅需重新解析和重新索引必要的文件
* [ ] 完善对脚本文件和本地化文件中的转义字符的支持
* [ ] 修复一个关于作用域上下文的问题:`from.from`应当等同于`this`,而非`fromfrom`
* [X] 支持在多行的脚本参数值中使用内联脚本 *
* [ ] BUG修复:对于作用域上下文,`from.from`应当等同于`this`,而非`fromfrom`

> 检查:
> * [ ] lexer 代码检查 - 本地化文件的语法
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CwtBaseConfigContextProvider : CwtConfigContextProvider {
val elementPathFromRoot = context.elementPathFromRoot ?: return null // null -> unexpected
val contextElement = context.element ?: return null
val isPropertyValue = contextElement is ParadoxScriptValue && contextElement.isPropertyValue()
return "b@$gameTypeId:${matchOptions}#${isPropertyValue.toInt()}#${declarationConfigCacheKey.substringAfterLast('#')}\n${elementPathFromRoot}"
return "b@$gameTypeId:${matchOptions}#${isPropertyValue.toInt()}#${declarationConfigCacheKey.substringAfterLast('#')}:${elementPathFromRoot}"
}

override fun getConfigs(context: CwtConfigContext, matchOptions: Int): List<CwtMemberConfig<*>>? {
Expand Down Expand Up @@ -97,8 +97,8 @@ class CwtInlineScriptUsageConfigContextProvider : CwtConfigContextProvider {
if(rootIndex == -1) return null

ProgressManager.checkCanceled()
val fileInfo = vFile.fileInfo ?: return null
val gameType = fileInfo.rootInfo.gameType
val gameType = selectGameType(file) ?: return null
val fileInfo = vFile.fileInfo //注意这里的fileInfo可能为null,例如,在内联脚本参数的多行参数值中
val elementPathFromRoot = ParadoxElementPath.resolve(elementPath.rawSubPaths.let { it.subList(rootIndex + 1, it.size) })
val configGroup = getConfigGroup(file.project, gameType)
val configContext = CwtConfigContext(element, fileInfo, elementPath, gameType, configGroup)
Expand All @@ -108,11 +108,10 @@ class CwtInlineScriptUsageConfigContextProvider : CwtConfigContextProvider {

override fun getCacheKey(context: CwtConfigContext, matchOptions: Int): String? {
val gameTypeId = context.gameType.id
val path = context.fileInfo?.path ?: return null // null -> unexpected
val elementPathFromRoot = context.elementPathFromRoot ?: return null // null -> unexpected
val contextElement = context.element ?: return null
val isPropertyValue = contextElement is ParadoxScriptValue && contextElement.isPropertyValue()
return "isu@$gameTypeId:${matchOptions}#${isPropertyValue.toInt()}#${path.path}\n${elementPathFromRoot.path}"
return "isu@$gameTypeId:${matchOptions}#${isPropertyValue.toInt()}:${elementPathFromRoot.path}"
}

override fun getConfigs(context: CwtConfigContext, matchOptions: Int): List<CwtMemberConfig<*>>? {
Expand Down Expand Up @@ -150,8 +149,8 @@ class CwtInlineScriptConfigContextProvider : CwtConfigContextProvider {
if(inlineScriptExpression == null) return null

ProgressManager.checkCanceled()
val gameType = selectGameType(file) ?: return null
val fileInfo = vFile.fileInfo ?: return null
val gameType = fileInfo.rootInfo.gameType
val elementPathFromRoot = elementPath
val configGroup = getConfigGroup(file.project, gameType)
val configContext = CwtConfigContext(element, fileInfo, elementPath, gameType, configGroup)
Expand All @@ -169,7 +168,7 @@ class CwtInlineScriptConfigContextProvider : CwtConfigContextProvider {
val elementPathFromRoot = context.elementPathFromRoot ?: return null // null -> unexpected
val contextElement = context.element ?: return null
val isPropertyValue = contextElement is ParadoxScriptValue && contextElement.isPropertyValue()
return "is@$gameTypeId:${matchOptions}#${isPropertyValue.toInt()}#${inlineScriptExpression}\n${elementPathFromRoot.path}"
return "is@$gameTypeId:${matchOptions}#${isPropertyValue.toInt()}#${inlineScriptExpression}:${elementPathFromRoot.path}"
}

//获取CWT规则后才能确定是否存在冲突以及是否存在递归
Expand Down Expand Up @@ -259,8 +258,9 @@ class CwtParameterValueConfigContextProvider : CwtConfigContextProvider {
val injectionInfo = getInjectionInfo(file, host)
if(injectionInfo == null) return null

val parameterElement = injectionInfo.parameterElement ?: return null
ProgressManager.checkCanceled()
val gameType = selectGameType(file) ?: return null
val parameterElement = injectionInfo.parameterElement ?: return null
val elementPathFromRoot = elementPath
val configGroup = getConfigGroup(file.project, gameType)
val configContext = CwtConfigContext(element, null, elementPath, gameType, configGroup)
Expand Down Expand Up @@ -297,7 +297,7 @@ class CwtParameterValueConfigContextProvider : CwtConfigContextProvider {
val elementPathFromRoot = context.elementPathFromRoot ?: return null // null -> unexpected
val contextElement = context.element ?: return null
val isPropertyValue = contextElement is ParadoxScriptValue && contextElement.isPropertyValue()
return "is@$gameTypeId:${matchOptions}#${isPropertyValue.toInt()}#${parameterElement.contextKey}@${parameterElement.name}\n${elementPathFromRoot.path}"
return "is@$gameTypeId:${matchOptions}#${isPropertyValue.toInt()}#${parameterElement.contextKey}@${parameterElement.name}:${elementPathFromRoot.path}"
}

override fun getConfigs(context: CwtConfigContext, matchOptions: Int): List<CwtMemberConfig<*>>? {
Expand Down

0 comments on commit f07784d

Please sign in to comment.