Skip to content

Commit 31b21cd

Browse files
committed
sync code from IntelliJ-EmmyLua
1 parent e67d2c9 commit 31b21cd

File tree

10 files changed

+136
-314
lines changed

10 files changed

+136
-314
lines changed

EmmyLua-Common/src/main/ext/com/tang/intellij/lua/project/LuaSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class LuaSettings {
6161
return instance.constructorNames.contains(name.toLowerCase())
6262
}
6363

64-
fun isImporterName(name: String): Boolean {
64+
fun isRequireLikeFunctionName(name: String): Boolean {
6565
return name == Constants.WORD_REQUIRE
6666
}
6767
}

EmmyLua-Common/src/main/java/com/tang/intellij/lua/editor/completion/ClassMemberCompletionProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ open class ClassMemberCompletionProvider : LuaCompletionProvider() {
142142
val bold = thisType == callType
143143
val className = thisType.displayName
144144
if (type is ITyFunction) {
145-
addFunction(completionResultSet, bold, completionMode != MemberCompletionMode.Dot, className, member, type, thisType, callType, handlerProcessor)
145+
val fn = type.substitute(TySelfSubstitutor(project, null, callType))
146+
if (fn is ITyFunction)
147+
addFunction(completionResultSet, bold, completionMode != MemberCompletionMode.Dot, className, member, fn, thisType, callType, handlerProcessor)
146148
} else if (member is LuaClassField) {
147149
if (completionMode != MemberCompletionMode.Colon)
148150
addField(completionResultSet, bold, className, member, type, handlerProcessor)

EmmyLua-Common/src/main/java/com/tang/intellij/lua/reference/LuaReferenceContributor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class LuaReferenceContributor : PsiReferenceContributor() {
6161
val expr = psiElement as LuaCallExpr
6262
val nameRef = expr.expr
6363
if (nameRef is LuaNameExpr) {
64-
if (LuaSettings.isImporterName(nameRef.getText())) {
64+
if (LuaSettings.isRequireLikeFunctionName(nameRef.getText())) {
6565
return arrayOf(LuaRequireReference(expr))
6666
}
6767
}

EmmyLua-Common/src/main/java/com/tang/intellij/lua/ty/Expressions.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,9 @@ fun LuaCallExpr.createSubstitutor(sig: IFunSignature, context: SearchContext): I
151151
}
152152

153153
private fun LuaCallExpr.getReturnTy(sig: IFunSignature, context: SearchContext): ITy? {
154-
var resultSig = sig
155154
val substitutor = createSubstitutor(sig, context)
156-
if (substitutor != null) {
157-
resultSig = sig.substitute(substitutor)
158-
}
159-
val returnTy = resultSig.returnTy
155+
var returnTy = if (substitutor != null) sig.returnTy.substitute(substitutor) else sig.returnTy
156+
returnTy = returnTy.substitute(TySelfSubstitutor(project, this))
160157
return if (returnTy is TyTuple) {
161158
if (context.guessTuple())
162159
returnTy
@@ -173,7 +170,7 @@ private fun LuaCallExpr.infer(context: SearchContext): ITy {
173170
// xxx()
174171
val expr = luaCallExpr.expr
175172
// 从 require 'xxx' 中获取返回类型
176-
if (expr is LuaNameExpr && LuaSettings.isImporterName(expr.name)) {
173+
if (expr is LuaNameExpr && LuaSettings.isRequireLikeFunctionName(expr.name)) {
177174
var filePath: String? = null
178175
val string = luaCallExpr.firstStringArg
179176
if (string is LuaLiteralExpr) {
@@ -362,11 +359,12 @@ private fun LuaIndexExpr.infer(context: SearchContext): ITy {
362359
val propName = indexExpr.name
363360
if (propName != null) {
364361
val prefixType = parentTy ?: indexExpr.guessParentType(context)
365-
366-
prefixType.eachTopClass(Processor {
367-
result = result.union(guessFieldType(propName, it, context))
368-
true
369-
})
362+
prefixType.each { ty ->
363+
if (ty is ITyClass)
364+
result = result.union(guessFieldType(propName, ty, context))
365+
else if (ty is ITyGeneric && ty.getParamTy(0) == Ty.STRING)
366+
result = result.union(ty.getParamTy(1))
367+
}
370368
}
371369
result
372370
})

0 commit comments

Comments
 (0)