Skip to content

Commit 40e5191

Browse files
committed
0.4.19
1 parent 6dfab10 commit 40e5191

File tree

4 files changed

+55
-44
lines changed

4 files changed

+55
-44
lines changed

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

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,29 @@ class EmitterOverloadProvider : LuaCompletionProvider() {
3838
parentType.each { ty ->
3939
if (ty is ITyFunction) {
4040
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)
41+
if(firstParam != null) {
42+
if(firstParam.ty.subTypeOf(Ty.STRING, searchContext, true)) {
43+
ty.process(Processor { sig ->
44+
sig.params.firstOrNull()?.let {
45+
val paramType = it.ty
46+
if (paramType is TyStringLiteral) {
47+
addStringOverload(psi, paramType, sig, completionResultSet)
48+
}
4749
}
48-
}
49-
true
50-
})
50+
true
51+
})
52+
}
53+
else if (firstParam.ty.subTypeOf(Ty.NUMBER, searchContext, true)){
54+
ty.process(Processor { sig ->
55+
sig.params.firstOrNull()?.let {
56+
val paramType = it.ty
57+
if (paramType is TyStringLiteral) {
58+
addNumberOverload(psi, paramType, sig, completionResultSet)
59+
}
60+
}
61+
true
62+
})
63+
}
5164
}
5265
}
5366
}
@@ -56,7 +69,7 @@ class EmitterOverloadProvider : LuaCompletionProvider() {
5669
}
5770
}
5871

59-
private fun addOverload(
72+
private fun addStringOverload(
6073
psiElement: PsiElement,
6174
tyStringLiteral: TyStringLiteral,
6275
signature: IFunSignature,
@@ -74,37 +87,19 @@ class EmitterOverloadProvider : LuaCompletionProvider() {
7487
completionResultSet.addElement(element)
7588
}
7689
}
77-
// private fun addEnum(
78-
// luaType: ITyClass,
79-
// searchContext: SearchContext,
80-
// completionResultSet: CompletionResultSet
81-
// ) {
82-
// luaType.lazyInit(searchContext)
83-
// luaType.processMembers(searchContext) { curType, member ->
84-
// ProgressManager.checkCanceled()
85-
// member.name?.let {
86-
// val name = "${luaType.className}.${member.name}"
87-
// if (completionResultSet.prefixMatcher.prefixMatches(name)) {
88-
// addEnumField(completionResultSet, member, name, curType)
89-
// }
90-
// }
91-
//
92-
// }
93-
// }
94-
//
95-
// private fun addEnumField(
96-
// completionResultSet: CompletionResultSet,
97-
// member: LuaClassMember,
98-
// name: String,
99-
// fieldType: ITyClass
100-
// ) {
101-
//
102-
// if (member is LuaClassField) {
103-
// val element =
104-
// LookupElementFactory.createFieldLookupElement(fieldType.className, name, member, fieldType, true)
105-
// element.kind = CompletionItemKind.Enum
106-
// completionResultSet.addElement(element)
107-
// }
108-
// }
90+
91+
private fun addNumberOverload(
92+
psiElement: PsiElement,
93+
tyStringLiteral: TyStringLiteral,
94+
signature: IFunSignature,
95+
completionResultSet: CompletionResultSet
96+
) {
97+
if(psiElement.node.elementType != LuaTypes.STRING) {
98+
val element = LuaLookupElement(tyStringLiteral.content)
99+
element.isEnumMember = true
100+
element.kind = CompletionItemKind.EnumMember
101+
completionResultSet.addElement(element)
102+
}
103+
}
109104

110105
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,23 @@ fun ITyFunction.findPerfectSignature(call: LuaCallExpr, paramSize: Int = 0): IFu
293293
}
294294
true
295295
})
296-
} else if (firstParamTy is TyClass && firstParamTy.isEnum(call.project, searchContext)) {
296+
}
297+
else if(firstParamTy.subTypeOf(Ty.NUMBER, searchContext, true)){
298+
process(Processor {
299+
val params = it.params
300+
if (params.isNotEmpty()) {
301+
val sigFirstParamTy = params.first().ty
302+
if (sigFirstParamTy is TyStringLiteral
303+
&& (sigFirstParamTy.content == callArgs.first().text)
304+
) {
305+
sig = it
306+
return@Processor false
307+
}
308+
}
309+
true
310+
})
311+
}
312+
else if (firstParamTy is TyClass && firstParamTy.isEnum(call.project, searchContext)) {
297313
process(Processor {
298314
val params = it.params
299315
if (params.isNotEmpty()) {

EmmyLua-LS/src/main/kotlin/com/tang/vscode/documentation/LuaDocumentationProvider.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ class LuaDocumentationProvider : DocumentationProvider {
9090
is LuaPsiFile -> {
9191
sb.append(element.virtualFile.path.substringAfter("file:/"))
9292
}
93-
9493
}
9594
if (sb.isNotEmpty()) return sb.toString()
9695

EmmyLua-LS/src/main/kotlin/com/tang/vscode/formatter/FormattingFormatter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.tang.lsp.ILuaFile
88
import kotlin.math.max
99
import kotlin.math.min
1010

11+
// 弃了,建议使用EmmyLuaCodeStyle
1112
class FormattingFormatter(val file: ILuaFile, val psi: PsiFile) {
1213
private var fileElement: FormattingElement =
1314
FormattingElement(psi, FormattingType.Block, psi.textRange, mutableListOf());

0 commit comments

Comments
 (0)