Skip to content

Commit

Permalink
Revert "很多卡死问题的根源都是 Indexing 造成的,暂时将造成问题的 Indexing 去除。后续思考改进 Indexing"
Browse files Browse the repository at this point in the history
This reverts commit 9c69042.
  • Loading branch information
tangzx committed Dec 27, 2023
1 parent 7d58076 commit d700664
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/com/tang/intellij/lua/stubs/LuaClassMethodStub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.intellij.util.BitUtil
import com.intellij.util.io.StringRef
import com.tang.intellij.lua.psi.*
import com.tang.intellij.lua.psi.impl.LuaClassMethodDefImpl
import com.tang.intellij.lua.search.SearchContext
import com.tang.intellij.lua.stubs.index.LuaClassMemberIndex
import com.tang.intellij.lua.stubs.index.StubKeys
import com.tang.intellij.lua.ty.*
Expand All @@ -39,8 +40,18 @@ class LuaClassMethodType : LuaStubElementType<LuaClassMethodStub, LuaClassMethod
override fun createStub(methodDef: LuaClassMethodDef, stubElement: StubElement<*>): LuaClassMethodStub {
val methodName = methodDef.classMethodName
val id = methodDef.nameIdentifier
// val expr = methodName.expr
val expr = methodName.expr
val classNameSet = mutableListOf<ITyClass>()

val ty = SearchContext.withStub(methodDef.project, methodDef.containingFile, Ty.UNKNOWN) {
SearchContext.infer(expr, it)
}
TyUnion.each(ty) {
if (it is ITyClass)
classNameSet.add(it)
}
if (classNameSet.isEmpty()) classNameSet.add(createSerializedClass(expr.text))

var flags = 0

val isStatic = methodName.dot != null
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/tang/intellij/lua/stubs/LuaIndexExprStub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ import com.intellij.util.BitUtil
import com.intellij.util.io.StringRef
import com.tang.intellij.lua.psi.*
import com.tang.intellij.lua.psi.impl.LuaIndexExprImpl
import com.tang.intellij.lua.search.SearchContext
import com.tang.intellij.lua.stubs.index.LuaClassMemberIndex
import com.tang.intellij.lua.stubs.index.StubKeys
import com.tang.intellij.lua.ty.ITy
import com.tang.intellij.lua.ty.ITyClass
import com.tang.intellij.lua.ty.Ty
import com.tang.intellij.lua.ty.TyUnion

/**
Expand All @@ -38,10 +42,41 @@ class LuaIndexExprType : LuaStubElementType<LuaIndexExprStub, LuaIndexExpr>("IND
return LuaIndexExprImpl(indexStub, this)
}

/**
* a.b.c => true
* a.b().c => false
* a().b.c => false
*/
private fun LuaIndexExpr.isPure(): Boolean {
var prev = this.prefixExpr
while (true) {
when (prev) {
is LuaNameExpr -> return true
is LuaIndexExpr -> prev = prev.prefixExpr
else -> return false
}
}
}

/*override fun shouldCreateStub(node: ASTNode): Boolean {
val psi = node.psi as LuaIndexExpr
return psi.isPure()
}*/

override fun createStub(indexExpr: LuaIndexExpr, stubElement: StubElement<*>): LuaIndexExprStub {
val stat = indexExpr.assignStat
val docTy = stat?.comment?.docTy
val classNameSet = mutableSetOf<String>()

if (stat != null) {
val ty = SearchContext.withStub(indexExpr.project, indexExpr.containingFile, Ty.UNKNOWN) {
indexExpr.guessParentType(it)
}
TyUnion.each(ty) {
if (it is ITyClass)
classNameSet.add(it.className)
}
}
val visibility = indexExpr.visibility

var flags = BitUtil.set(0, visibility.bitMask, true)
Expand Down

0 comments on commit d700664

Please sign in to comment.