From d700664e4807495b278ce716614e8432dd3507c1 Mon Sep 17 00:00:00 2001 From: tangzx Date: Thu, 28 Dec 2023 00:36:03 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E5=BE=88=E5=A4=9A=E5=8D=A1=E6=AD=BB?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E7=9A=84=E6=A0=B9=E6=BA=90=E9=83=BD=E6=98=AF?= =?UTF-8?q?=20Indexing=20=E9=80=A0=E6=88=90=E7=9A=84=EF=BC=8C=E6=9A=82?= =?UTF-8?q?=E6=97=B6=E5=B0=86=E9=80=A0=E6=88=90=E9=97=AE=E9=A2=98=E7=9A=84?= =?UTF-8?q?=20Indexing=20=E5=8E=BB=E9=99=A4=E3=80=82=E5=90=8E=E7=BB=AD?= =?UTF-8?q?=E6=80=9D=E8=80=83=E6=94=B9=E8=BF=9B=20Indexing"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 9c690422e293c952e01bdc6915f301595eb0d2cc. --- .../intellij/lua/stubs/LuaClassMethodStub.kt | 13 ++++++- .../intellij/lua/stubs/LuaIndexExprStub.kt | 35 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tang/intellij/lua/stubs/LuaClassMethodStub.kt b/src/main/java/com/tang/intellij/lua/stubs/LuaClassMethodStub.kt index 8698b0b27..94f4a86c2 100644 --- a/src/main/java/com/tang/intellij/lua/stubs/LuaClassMethodStub.kt +++ b/src/main/java/com/tang/intellij/lua/stubs/LuaClassMethodStub.kt @@ -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.* @@ -39,8 +40,18 @@ class LuaClassMethodType : LuaStubElementType): LuaClassMethodStub { val methodName = methodDef.classMethodName val id = methodDef.nameIdentifier - // val expr = methodName.expr + val expr = methodName.expr val classNameSet = mutableListOf() + + 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 diff --git a/src/main/java/com/tang/intellij/lua/stubs/LuaIndexExprStub.kt b/src/main/java/com/tang/intellij/lua/stubs/LuaIndexExprStub.kt index 02cd1d388..f345365a8 100644 --- a/src/main/java/com/tang/intellij/lua/stubs/LuaIndexExprStub.kt +++ b/src/main/java/com/tang/intellij/lua/stubs/LuaIndexExprStub.kt @@ -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 /** @@ -38,10 +42,41 @@ class LuaIndexExprType : LuaStubElementType("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() + + 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)