diff --git a/src/main/kotlin/icu/windea/pls/PlsConstants.kt b/src/main/kotlin/icu/windea/pls/PlsConstants.kt index aca5990ba..067763cbb 100644 --- a/src/main/kotlin/icu/windea/pls/PlsConstants.kt +++ b/src/main/kotlin/icu/windea/pls/PlsConstants.kt @@ -39,14 +39,13 @@ object PlsConstants { const val defaultScriptedVariableName = "var" - //目前认为定义相对于脚本文件的最大深度是4(最多跳过3个rootKey),在索引之外的某些场合需要加上针挑 + //定义相对于脚本文件的最大深度(目前指定为4,即最多跳过3个rootKey) - 用于优化性能 const val maxDefinitionDepth = 4 //在提示信息中最多显示的键的个数 const val keysTruncateLimit = 5 //val eraseMarker = TextAttributes() - - val onlyForegroundAttributesFlags = WithAttributesPresentation.AttributesFlags().withSkipBackground(true).withSkipEffects(true) + //val onlyForegroundAttributesFlags = WithAttributesPresentation.AttributesFlags().withSkipBackground(true).withSkipEffects(true) object Patterns { val scriptParameterNameRegex = """[a-zA-Z_][a-zA-Z0-9_]*""".toRegex() diff --git a/src/main/kotlin/icu/windea/pls/script/psi/ParadoxScriptFileStubElementType.kt b/src/main/kotlin/icu/windea/pls/script/psi/ParadoxScriptFileStubElementType.kt index 81ff554f7..895582e42 100644 --- a/src/main/kotlin/icu/windea/pls/script/psi/ParadoxScriptFileStubElementType.kt +++ b/src/main/kotlin/icu/windea/pls/script/psi/ParadoxScriptFileStubElementType.kt @@ -88,7 +88,7 @@ object ParadoxScriptFileStubElementType : ILightStubFileElementType false type == SCRIPTED_VARIABLE -> parentType != ROOT_BLOCK type == PROPERTY -> false - type == BLOCK -> false + type == BLOCK -> skipBlock(node, { this.treeParent }, { this.elementType }) else -> true } } @@ -101,9 +101,22 @@ object ParadoxScriptFileStubElementType : ILightStubFileElementType false type == SCRIPTED_VARIABLE -> parentType != ROOT_BLOCK type == PROPERTY -> false - type == BLOCK -> false + type == BLOCK -> skipBlock(node, { tree.getParent(this) }, { this.tokenType }) else -> true } } + + private inline fun skipBlock(node: T, parentProvider: T.() -> T?, typeProvider: T.() -> IElementType): Boolean { + //优化:跳过深度过高的属性(认为它们不可能是定义) + var current = node + var i = 1 + val max = PlsConstants.maxDefinitionDepth + while(true) { + current = current.parentProvider() ?: break + if(current.typeProvider() == BLOCK) i++ + if(i > max) return true + } + return false + } } }