Skip to content

Commit

Permalink
1.1.6 优化编制定义索引时的性能
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonKnightOfBreeze committed Aug 10, 2023
1 parent 00b94d8 commit f0f77f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/main/kotlin/icu/windea/pls/PlsConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object ParadoxScriptFileStubElementType : ILightStubFileElementType<PsiFileStub<
type == ROOT_BLOCK -> false
type == SCRIPTED_VARIABLE -> parentType != ROOT_BLOCK
type == PROPERTY -> false
type == BLOCK -> false
type == BLOCK -> skipBlock(node, { this.treeParent }, { this.elementType })
else -> true
}
}
Expand All @@ -101,9 +101,22 @@ object ParadoxScriptFileStubElementType : ILightStubFileElementType<PsiFileStub<
type == ROOT_BLOCK -> 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 <T> 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
}
}
}

0 comments on commit f0f77f0

Please sign in to comment.