@@ -4,6 +4,7 @@ package com.tang.intellij.lua.editor.completion
44
55import com.intellij.codeInsight.lookup.LookupElement
66import com.intellij.psi.tree.IElementType
7+ import com.tang.intellij.lua.lang.LuaIcons
78import com.tang.intellij.lua.psi.LuaClassField
89import com.tang.intellij.lua.psi.LuaClassMember
910import com.tang.intellij.lua.psi.LuaParamInfo
@@ -20,51 +21,68 @@ object LookupElementFactory {
2021
2122 fun createGuessableLookupElement (name : String , psi : LuaPsiElement , ty : ITy , icon : Icon ? ): LookupElement {
2223 val element = LuaLookupElement (name)
23- element.kind = CompletionItemKind .Value
24+ element.kind = when (icon) {
25+ LuaIcons .LOCAL_VAR -> {
26+ CompletionItemKind .Variable
27+ }
28+ LuaIcons .PARAMETER -> {
29+ CompletionItemKind .TypeParameter
30+ }
31+ else -> {
32+ CompletionItemKind .Value
33+ }
34+ }
35+ element.additionDetailDescription = ty.displayName
2436 return element
2537 }
2638
27- fun createFunctionLookupElement (name : String ,
28- psi : LuaPsiElement ,
29- signature : IFunSignature ,
30- bold : Boolean ,
31- ty : ITyFunction ,
32- icon : Icon ? ): LookupElement {
39+ fun createFunctionLookupElement (
40+ name : String ,
41+ psi : LuaPsiElement ,
42+ signature : IFunSignature ,
43+ bold : Boolean ,
44+ ty : ITyFunction ,
45+ icon : Icon ?
46+ ): LookupElement {
3347 val item = buildSignatureCompletionItem(name, signature, false )
3448 item.kind = CompletionItemKind .Function
3549
3650 return item
3751 }
3852
39- fun createMethodLookupElement (clazzName : String ,
40- lookupString : String ,
41- classMember : LuaClassMember ,
42- signature : IFunSignature ,
43- bold : Boolean ,
44- isColonStyle : Boolean ,
45- fnTy : ITyFunction ,
46- icon : Icon ? ): LuaLookupElement {
53+ fun createMethodLookupElement (
54+ clazzName : String ,
55+ lookupString : String ,
56+ classMember : LuaClassMember ,
57+ signature : IFunSignature ,
58+ bold : Boolean ,
59+ isColonStyle : Boolean ,
60+ fnTy : ITyFunction ,
61+ icon : Icon ?
62+ ): LuaLookupElement {
4763 val item = buildSignatureCompletionItem(lookupString, signature, isColonStyle)
4864 item.kind = CompletionItemKind .Method
4965 item.itemText = " [$clazzName ]"
5066 val file = classMember.containingFile?.virtualFile as ? ILuaFile
5167 if (file != null ) {
5268 item.data = " ${file.uri} |${classMember.textOffset} "
5369 }
54- if (classMember.isDeprecated){
70+ if (classMember.isDeprecated) {
5571 item.deprecated = true
5672 }
5773
5874 return item
5975 }
6076
61- fun createShouldBeMethodLookupElement (clazzName : String ,
62- lookupString : String ,
63- classMember : LuaClassMember ,
64- signature : IFunSignature ,
65- bold : Boolean ,
66- fnTy : ITyFunction ,
67- icon : Icon ? ): LuaLookupElement {
77+ fun createShouldBeMethodLookupElement (
78+ clazzName : String ,
79+ lookupString : String ,
80+ classMember : LuaClassMember ,
81+ signature : IFunSignature ,
82+ bold : Boolean ,
83+ fnTy : ITyFunction ,
84+ icon : Icon ?
85+ ): LuaLookupElement {
6886 val item = buildSignatureCompletionItem(lookupString, signature, true )
6987 item.lookupString = " :${item.lookupString} "
7088 item.kind = CompletionItemKind .Method
@@ -73,32 +91,39 @@ object LookupElementFactory {
7391 if (file != null ) {
7492 item.data = " ${file.uri} |${classMember.textOffset} "
7593 }
76- if (classMember.isDeprecated){
94+ if (classMember.isDeprecated) {
7795 item.deprecated = true
7896 }
7997
8098 return item
8199 }
82100
83- fun createFieldLookupElement (clazzName : String ,
84- name : String ,
85- field : LuaClassField ,
86- ty : ITy ? ,
87- bold : Boolean ): LuaLookupElement {
101+ fun createFieldLookupElement (
102+ clazzName : String ,
103+ name : String ,
104+ field : LuaClassField ,
105+ ty : ITy ? ,
106+ bold : Boolean
107+ ): LuaLookupElement {
88108 val element = LuaLookupElement (name)
89109 element.kind = CompletionItemKind .Field
110+ element.additionDetailDescription = ty?.displayName
90111 val file = field.containingFile?.virtualFile as ? ILuaFile
91112 if (file != null ) {
92113 element.data = " ${file.uri} |${field.textOffset} "
93114 }
94- if (field.isDeprecated){
115+ if (field.isDeprecated) {
95116 element.deprecated = true
96117 }
97118
98119 return element
99120 }
100121
101- private fun buildSignatureCompletionItem (name : String , signature : IFunSignature , isColonStyle : Boolean ): LuaLookupElement {
122+ private fun buildSignatureCompletionItem (
123+ name : String ,
124+ signature : IFunSignature ,
125+ isColonStyle : Boolean
126+ ): LuaLookupElement {
102127 var pIndex = 0
103128 val params = mutableListOf<LuaParamInfo >()
104129 if (isColonStyle) { // a:b()
@@ -112,22 +137,22 @@ object LookupElementFactory {
112137 }
113138 params.addAll(signature.params)
114139
115- val lookupString = buildString {
116- append(name)
140+ val item = LuaLookupElement (name)
141+ item.additionDetail = buildString {
117142 append(" (" )
118143 val strings = mutableListOf<String >()
119144 for (i in pIndex until params.size) {
120145 val p = params[i]
121146 strings.add(p.name)
122147 }
123- if (signature.hasVarargs()){
148+ if (signature.hasVarargs()) {
124149 strings.add(" ..." )
125150 }
126151 append(strings.joinToString(" ," ))
127152 append(" )" )
128153 }
154+ item.additionDetailDescription = signature.returnTy.displayName
129155
130- val item = LuaLookupElement (lookupString)
131156 if (pIndex >= params.size) {
132157 item.insertText = " $name ()"
133158 } else {
0 commit comments