@@ -6,6 +6,7 @@ import com.intellij.codeInsight.lookup.LookupElement
66import com.intellij.psi.tree.IElementType
77import com.tang.intellij.lua.psi.LuaClassField
88import com.tang.intellij.lua.psi.LuaClassMember
9+ import com.tang.intellij.lua.psi.LuaParamInfo
910import com.tang.intellij.lua.psi.LuaPsiElement
1011import com.tang.intellij.lua.ty.IFunSignature
1112import com.tang.intellij.lua.ty.ITy
@@ -28,7 +29,7 @@ object LookupElementFactory {
2829 bold : Boolean ,
2930 ty : ITyFunction ,
3031 icon : Icon ? ): LookupElement {
31- val item = buildSignatureCompletionItem(name, signature)
32+ val item = buildSignatureCompletionItem(name, signature, false )
3233 item.kind = CompletionItemKind .Function
3334 return item
3435 }
@@ -42,7 +43,7 @@ object LookupElementFactory {
4243 fnTy : ITyFunction ,
4344 icon : Icon ? ): LuaLookupElement {
4445 val file = classMember.containingFile.virtualFile as ILuaFile
45- val item = buildSignatureCompletionItem(lookupString, signature)
46+ val item = buildSignatureCompletionItem(lookupString, signature, isColonStyle )
4647 item.kind = CompletionItemKind .Method
4748 item.itemText = " [$clazzName ]"
4849 item.data = " ${file.uri} |${classMember.textOffset} "
@@ -61,9 +62,34 @@ object LookupElementFactory {
6162 return element
6263 }
6364
64- private fun buildSignatureCompletionItem (name : String , signature : IFunSignature ): LuaLookupElement {
65- val item = LuaLookupElement (" $name${signature.paramSignature} " )
66- if (signature.params.isEmpty()) {
65+ private fun buildSignatureCompletionItem (name : String , signature : IFunSignature , isColonStyle : Boolean ): LuaLookupElement {
66+ var pIndex = 0
67+ val params = mutableListOf<LuaParamInfo >()
68+ if (isColonStyle) { // a:b()
69+ if (! signature.colonCall) { // function a.b() end
70+ pIndex++
71+ }
72+ } else { // a.b()
73+ if (signature.colonCall) { // function a:b() end
74+ params.add(LuaParamInfo .createSelf())
75+ }
76+ }
77+ params.addAll(signature.params)
78+
79+ val lookupString = buildString {
80+ append(name)
81+ append(" (" )
82+ val strings = mutableListOf<String >()
83+ for (i in pIndex until params.size) {
84+ val p = params[i]
85+ strings.add(p.name)
86+ }
87+ append(strings.joinToString(" ," ))
88+ append(" )" )
89+ }
90+
91+ val item = LuaLookupElement (lookupString)
92+ if (pIndex >= params.size) {
6793 item.insertText = " $name ()"
6894 } else {
6995 item.insertText = name
0 commit comments