Skip to content

Commit 6dfab10

Browse files
committed
修改参数诊断
1 parent 11d5154 commit 6dfab10

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ class EmitterOverloadProvider : LuaCompletionProvider() {
3737
callExpr.guessParentType(searchContext).let { parentType ->
3838
parentType.each { ty ->
3939
if (ty is ITyFunction) {
40-
ty.process(Processor { sig ->
41-
sig.params.firstOrNull()?.let {
42-
val paramType = it.ty
43-
if (paramType is TyStringLiteral) {
44-
addOverload(psi, paramType, sig, completionResultSet)
40+
val firstParam = ty.mainSignature.params.firstOrNull()
41+
if(firstParam != null && firstParam.ty.subTypeOf(Ty.STRING, searchContext, true)) {
42+
ty.process(Processor { sig ->
43+
sig.params.firstOrNull()?.let {
44+
val paramType = it.ty
45+
if (paramType is TyStringLiteral) {
46+
addOverload(psi, paramType, sig, completionResultSet)
47+
}
4548
}
46-
}
47-
true
48-
})
49+
true
50+
})
51+
}
4952
}
5053
}
5154
}

EmmyLua-LS/src/main/kotlin/com/tang/vscode/diagnostics/inspections/FunctionInspection.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ object FunctionInspection {
4040
sig.params.forEach { pi ->
4141
val param = paramMap[index]
4242
if (param != null) {
43-
val paramType = param.guessType(context)
4443
if (!paramTypeCheck(pi, param, context)) {
44+
val paramType = param.guessType(context)
4545
val pDeclaredType = pi.ty
4646
val diagnostic = Diagnostic()
4747
diagnostic.message = if (pDeclaredType is TyClass && pDeclaredType.isInterface) {
@@ -121,6 +121,16 @@ object FunctionInspection {
121121
if (isUnionCheckPass) {
122122
return true
123123
}
124+
} else if (defineType is TyClass && defineType.isEnum(context.project, context)) {
125+
val superClass = defineType.getSuperClass(context)
126+
return if (superClass != null) {
127+
variableType.subTypeOf(superClass, context, true)
128+
} else {
129+
false
130+
}
131+
}
132+
else if(defineType is TyStringLiteral){
133+
return true
124134
}
125135

126136
return variableType.subTypeOf(defineType, context, true)

0 commit comments

Comments
 (0)