Skip to content

Commit 2c804af

Browse files
committed
优化语言服务
1 parent 16890cf commit 2c804af

File tree

10 files changed

+29
-32
lines changed

10 files changed

+29
-32
lines changed

EmmyLua-Common/src/main/ext/com/tang/intellij/lua/lang/LuaParserDefinition.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ class LuaParserDefinition : ParserDefinition {
146146
LuaDocTypes.TAG_NAME_SEE,
147147
LuaDocTypes.TAG_NAME_GENERIC,
148148
LuaDocTypes.TAG_NAME_VARARG,
149-
LuaDocTypes.TAG_NAME_ALIAS
149+
LuaDocTypes.TAG_NAME_ALIAS,
150+
LuaDocTypes.TAG_NAME_INTERFACE
150151
)
151152
val DOC_KEYWORD_TOKENS = TokenSet.create(
152153
LuaDocTypes.FUN,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ open class ClassMemberCompletionProvider : LuaCompletionProvider() {
222222
val name = field.name
223223
if (name != null) {
224224
val element = LookupElementFactory.createFieldLookupElement(clazzName, name, field, ty, bold)
225-
val ele = handlerProcessor?.process(element, field, null) ?: element
225+
val ele = handlerProcessor?.process(element, field, ty) ?: element
226226
completionResultSet.addElement(ele)
227227
return
228228
}
@@ -275,6 +275,7 @@ open class ClassMemberCompletionProvider : LuaCompletionProvider() {
275275
&& callType is TyClass
276276
&& callType !is TySerializedClass
277277
&& callType !is TyTable
278+
&& callType != TyClass.G
278279
) {
279280
val colonElement = LookupElementFactory.createShouldBeMethodLookupElement(
280281
clazzName,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class EnumCompletionProvider : LuaCompletionProvider() {
4848
if (activeParameter < activeSig.params.size) {
4949
activeSig.params[activeParameter].let {
5050
val paramType = it.ty
51-
if (paramType is TyClass && paramType.isEnum(callExpr.project, searchContext)) {
51+
if (paramType is TyClass && paramType.isEnum) {
5252
addEnum(paramType, searchContext, completionResultSet)
5353
}
5454
}

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ import com.tang.intellij.lua.psi.LuaTableExpr
2828
import com.tang.intellij.lua.psi.shouldBe
2929
import com.tang.intellij.lua.search.SearchContext
3030
import com.tang.intellij.lua.ty.ITy
31+
import org.eclipse.lsp4j.CompletionItemKind
3132

3233
class TableCompletionProvider : ClassMemberCompletionProvider() {
3334

3435
companion object {
35-
private val metaMethodNames = mapOf(
36+
public val metaMethodNames = mapOf(
3637
"__add" to "a + b",
3738
"__sub" to "a - b",
3839
"__mul" to "a * b",
@@ -56,9 +57,9 @@ class TableCompletionProvider : ClassMemberCompletionProvider() {
5657
val completionParameters = session.parameters
5758
val completionResultSet = session.resultSet
5859
metaMethodNames.forEach {
59-
val b = LookupElementBuilder.create(it.key)
60-
//.withTypeText(it.value)
61-
.withIcon(LuaIcons.META_METHOD)
60+
val b = LuaLookupElement(it.key)
61+
b.kind = CompletionItemKind.Method
62+
b.additionDetailDescription = "[${it.value}]"
6263
completionResultSet.addElement(b)
6364
}
6465

@@ -77,9 +78,10 @@ class TableCompletionProvider : ClassMemberCompletionProvider() {
7778
if (member is LuaClassField) {
7879
addField(completionResultSet, curType === luaType, className, member, null, object : HandlerProcessor() {
7980
override fun process(element: LuaLookupElement, member: LuaClassMember, memberTy: ITy?): LookupElement {
80-
element.itemText = "$className = "
81+
element.itemText = "[$className]"
8182
element.lookupString = element.lookupString + " = "
82-
83+
element.additionDetailDescription = memberTy?.displayName
84+
element.kind = CompletionItemKind.Property
8385
return PrioritizedLookupElement.withPriority(element, 10.0)
8486
}
8587
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum class TyPrimitiveKind {
4444
Number,
4545
Boolean,
4646
Table,
47-
Function
47+
Function,
4848
}
4949

5050
class TyFlags {

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.tang.intellij.lua.ty
1818

19-
import com.intellij.openapi.progress.ProgressManager
2019
import com.intellij.openapi.project.Project
2120
import com.intellij.psi.search.GlobalSearchScope
2221
import com.intellij.psi.stubs.StubInputStream
@@ -32,7 +31,6 @@ import com.tang.intellij.lua.psi.search.LuaClassInheritorsSearch
3231
import com.tang.intellij.lua.psi.search.LuaShortNamesManager
3332
import com.tang.intellij.lua.search.SearchContext
3433
import com.tang.intellij.lua.stubs.index.LuaClassMemberIndex
35-
import com.tang.lsp.nameRange
3634

3735
interface ITyClass : ITy {
3836
val className: String
@@ -41,6 +39,7 @@ interface ITyClass : ITy {
4139
var interfaceNames: List<String>?
4240
var aliasName: String?
4341
var isInterface: Boolean
42+
var isEnum: Boolean
4443
fun processAlias(processor: Processor<String>): Boolean
4544
fun lazyInit(searchContext: SearchContext)
4645
fun processMembers(context: SearchContext, processor: (ITyClass, LuaClassMember) -> Unit, deep: Boolean = true)
@@ -113,7 +112,8 @@ abstract class TyClass(
113112
override val varName: String = "",
114113
override var superClassName: String? = null,
115114
override var interfaceNames: List<String>? = null,
116-
override var isInterface: Boolean = false
115+
override var isInterface: Boolean = false,
116+
override var isEnum: Boolean = false
117117
) : Ty(TyKind.Class), ITyClass {
118118
final override var aliasName: String? = null
119119
private var _lazyInitialized: Boolean = false
@@ -165,7 +165,6 @@ abstract class TyClass(
165165
}
166166

167167
override fun getIndexResultType(element: LuaLiteralExpr): ITy? {
168-
169168
val context = SearchContext.get(element.project)
170169
when (element.kind) {
171170
LuaLiteralKind.Number -> {
@@ -229,6 +228,7 @@ abstract class TyClass(
229228
superClassName = tyClass.superClassName
230229
interfaceNames = tyClass.interfaceNames
231230
isInterface = tyClass.isInterface
231+
isEnum = tyClass.isEnum
232232
}
233233
}
234234

@@ -309,12 +309,6 @@ abstract class TyClass(
309309
return substitutor.substitute(this)
310310
}
311311

312-
fun isEnum(project: Project, searchContext: SearchContext): Boolean{
313-
val enumClass = LuaShortNamesManager.getInstance(project)
314-
.findClass(className, searchContext)
315-
return enumClass is LuaDocTagClass && enumClass.enum != null
316-
}
317-
318312
companion object {
319313
// for _G
320314
val G: TyClass = createSerializedClass(Constants.WORD_G)
@@ -418,6 +412,9 @@ class TyPsiDocClass(tagClass: LuaDocTagClass) : TyClass(tagClass.name) {
418412
if (tagClass.`interface` != null) {
419413
isInterface = true
420414
}
415+
else if(tagClass.enum != null){
416+
isEnum = true
417+
}
421418

422419
aliasName = tagClass.aliasName
423420
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ fun ITyFunction.findPerfectSignature(call: LuaCallExpr, paramSize: Int = 0): IFu
293293
}
294294
true
295295
})
296-
}
297-
else if(firstParamTy.subTypeOf(Ty.NUMBER, searchContext, true)){
296+
} else if (firstParamTy.subTypeOf(Ty.NUMBER, searchContext, true)) {
298297
process(Processor {
299298
val params = it.params
300299
if (params.isNotEmpty()) {
@@ -308,8 +307,7 @@ fun ITyFunction.findPerfectSignature(call: LuaCallExpr, paramSize: Int = 0): IFu
308307
}
309308
true
310309
})
311-
}
312-
else if (firstParamTy is TyClass && firstParamTy.isEnum(call.project, searchContext)) {
310+
} else if (firstParamTy is TyClass && firstParamTy.isEnum) {
313311
process(Processor {
314312
val params = it.params
315313
if (params.isNotEmpty()) {
@@ -348,7 +346,7 @@ fun ITyFunction.findPerfectSignature(call: LuaCallExpr, paramSize: Int = 0): IFu
348346
else if (!isColonCall && call.isMethodColonCall) {
349347
val originSig = findPerfectSignature(nArgs + 1)
350348

351-
if(originSig.params.isNotEmpty()) {
349+
if (originSig.params.isNotEmpty()) {
352350
val luaParamInfoList = originSig.params.toMutableList()
353351
luaParamInfoList.removeAt(0)
354352
val luaParamInfoArray = luaParamInfoList.toTypedArray()
@@ -358,8 +356,7 @@ fun ITyFunction.findPerfectSignature(call: LuaCallExpr, paramSize: Int = 0): IFu
358356
originSig.varargTy,
359357
luaParamInfoArray
360358
)
361-
}
362-
else{
359+
} else {
363360
sig = FunSignature(
364361
true,
365362
originSig.returnTy,

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,14 @@ object FunctionInspection {
121121
if (isUnionCheckPass) {
122122
return true
123123
}
124-
} else if (defineType is TyClass && defineType.isEnum(context.project, context)) {
124+
} else if (defineType is TyClass && defineType.isEnum) {
125125
val superClass = defineType.getSuperClass(context)
126126
return if (superClass != null) {
127127
variableType.subTypeOf(superClass, context, true)
128128
} else {
129129
false
130130
}
131-
}
132-
else if(defineType is TyStringLiteral){
131+
} else if (defineType is TyStringLiteral) {
133132
return true
134133
}
135134

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ internal fun renderDocParam(sb: StringBuilder, child: LuaDocTagParam) {
177177
val paramNameRef = child.paramNameRef
178178
val commentString = child.commentString
179179
if (paramNameRef != null && commentString != null && commentString.text.isNotEmpty()) {
180-
sb.appendLine("@_param_ `${paramNameRef.text}${if (child.isNullable) "?" else ""}`: ")
180+
sb.appendLine("(parameter) `${paramNameRef.text}${if (child.isNullable) "?" else ""}`: ")
181181
renderTypeUnion(null, null, sb, child.ty)
182182
renderCommentString(" ", null, sb, commentString)
183183
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class LuaDocumentationProvider : DocumentationProvider {
246246
renderDocParam(sb, docParamDef)
247247
} else {
248248
val ty = infer(paramNameDef, SearchContext.get(paramNameDef.project))
249-
sb.appendLine("@param `${paramNameDef.name}`:")
249+
sb.appendLine("(parameter) `${paramNameDef.name}`:")
250250
renderTy(sb, ty)
251251
}
252252
}

0 commit comments

Comments
 (0)