Skip to content

Commit 8e26caa

Browse files
authored
Merge pull request #33 from CppCXY/master
功能改进
2 parents 63d897a + 4b52013 commit 8e26caa

File tree

12 files changed

+195
-78
lines changed

12 files changed

+195
-78
lines changed

EmmyLua-Common/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies {
1818
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
1919
}
2020
buildscript {
21-
ext.kotlin_version = '1.2.30'
21+
ext.kotlin_version = '1.6.0'
2222
repositories {
2323
mavenCentral()
2424
}

EmmyLua-Common/src/main/ext/com/tang/intellij/lua/editor/completion/LuaCompletionContributor.kt

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,19 @@ class LuaCompletionContributor : CompletionContributor() {
7676
//提示属性, 提示方法
7777
extend(CompletionType.BASIC, SHOW_CLASS_FIELD, ClassMemberCompletionProvider())
7878
//提示全局函数,local变量,local函数
79-
extend(CompletionType.BASIC, IN_NAME_EXPR, LocalAndGlobalCompletionProvider(LocalAndGlobalCompletionProvider.ALL))
79+
extend(
80+
CompletionType.BASIC,
81+
IN_NAME_EXPR,
82+
LocalAndGlobalCompletionProvider(LocalAndGlobalCompletionProvider.ALL)
83+
)
8084
// 表的[]索引方式提示
8185
extend(CompletionType.BASIC, IN_TABLE_STRING_INDEX, TableStringIndexCompletionProvider())
8286
// lua5.4
8387
extend(CompletionType.BASIC, ATTRIBUTE, AttributeCompletionProvider())
8488
// enum
8589
extend(CompletionType.BASIC, SHOW_ENUM, EnumCompletionProvider())
8690

91+
extend(CompletionType.BASIC, SHOW_CALLBACK, CallbackCompletionProvider())
8792
}
8893

8994
/*override fun fillCompletionVariants(parameters: CompletionParameters, result: CompletionResultSet) {
@@ -121,57 +126,63 @@ class LuaCompletionContributor : CompletionContributor() {
121126
private val IGNORE_SET = TokenSet.create(LuaTypes.STRING, LuaTypes.NUMBER, LuaTypes.CONCAT)
122127

123128
private val SHOW_CLASS_FIELD = psiElement(LuaTypes.ID)
124-
.withParent(LuaIndexExpr::class.java)
129+
.withParent(LuaIndexExpr::class.java)
125130

126131
private val IN_FUNC_NAME = psiElement(LuaTypes.ID)
127-
.withParent(LuaIndexExpr::class.java)
128-
.inside(LuaClassMethodName::class.java)
132+
.withParent(LuaIndexExpr::class.java)
133+
.inside(LuaClassMethodName::class.java)
129134
private val AFTER_FUNCTION = psiElement()
130-
.afterLeaf(psiElement(LuaTypes.FUNCTION))
135+
.afterLeaf(psiElement(LuaTypes.FUNCTION))
131136
private val IN_CLASS_METHOD_NAME = psiElement().andOr(IN_FUNC_NAME, AFTER_FUNCTION)
132137

133138
private val IN_NAME_EXPR = psiElement(LuaTypes.ID)
134-
.withParent(LuaNameExpr::class.java)
139+
.withParent(LuaNameExpr::class.java)
135140

136141
private val SHOW_OVERRIDE = psiElement()
137-
.withParent(LuaClassMethodName::class.java)
142+
.withParent(LuaClassMethodName::class.java)
138143
private val IN_CLASS_METHOD = psiElement(LuaTypes.ID)
139-
.withParent(LuaNameExpr::class.java)
140-
.inside(LuaClassMethodDef::class.java)
144+
.withParent(LuaNameExpr::class.java)
145+
.inside(LuaClassMethodDef::class.java)
141146
private val SHOW_REQUIRE_PATH = psiElement(LuaTypes.STRING)
142-
.withParent(
143-
psiElement(LuaTypes.LITERAL_EXPR).withParent(
144-
psiElement(LuaArgs::class.java).afterSibling(
145-
psiElement().with(RequireLikePatternCondition())
146-
)
147-
)
147+
.withParent(
148+
psiElement(LuaTypes.LITERAL_EXPR).withParent(
149+
psiElement(LuaArgs::class.java).afterSibling(
150+
psiElement().with(RequireLikePatternCondition())
151+
)
148152
)
153+
)
149154

150155
private val SHOW_ENUM = psiElement(LuaTypes.ID)
151-
.withParent(psiElement(LuaNameExpr::class.java)
152-
.withParent(psiElement(LuaArgs::class.java))
153-
)
156+
.withParent(
157+
psiElement(LuaNameExpr::class.java)
158+
.withParent(psiElement(LuaArgs::class.java))
159+
)
154160

161+
private val SHOW_CALLBACK = psiElement(LuaTypes.ID)
162+
.withParent(
163+
psiElement(LuaNameExpr::class.java)
164+
.withParent(psiElement(LuaArgs::class.java))
165+
)
155166

156167
private val GOTO = psiElement(LuaTypes.ID).withParent(LuaGotoStat::class.java)
157168

158169
private val IN_TABLE_FIELD = psiElement().andOr(
159-
psiElement().withParent(
160-
psiElement(LuaTypes.NAME_EXPR).withParent(LuaTableField::class.java)
161-
),
162-
psiElement(LuaTypes.ID).withParent(LuaTableField::class.java)
170+
psiElement().withParent(
171+
psiElement(LuaTypes.NAME_EXPR).withParent(LuaTableField::class.java)
172+
),
173+
psiElement(LuaTypes.ID).withParent(LuaTableField::class.java)
163174
)
164175

165176
private val IN_TABLE_STRING_INDEX = psiElement().andOr(
166177
// psiElement(LuaTypes.LITERAL_EXPR).withParent(
167178
// psiElement(LuaIndexExpr::class.java)
168179
// ),
169-
psiElement(LuaTypes.STRING)
170-
.withParent(
171-
psiElement(LuaTypes.LITERAL_EXPR).withParent(
172-
psiElement(LuaIndexExpr::class.java)
173-
)
174-
)
180+
psiElement(LuaTypes.STRING)
181+
.withParent(
182+
psiElement(LuaTypes.LITERAL_EXPR).withParent(
183+
psiElement(LuaIndexExpr::class.java)
184+
)
185+
)
175186
)
176187

177188
private val ATTRIBUTE = psiElement(LuaTypes.ID).withParent(LuaAttribute::class.java)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.tang.intellij.lua.editor.completion
2+
3+
import com.intellij.codeInsight.completion.CompletionResultSet
4+
import com.intellij.openapi.progress.ProgressManager
5+
import com.intellij.psi.PsiElement
6+
import com.intellij.util.Processor
7+
import com.tang.intellij.lua.comment.psi.LuaDocTagClass
8+
import com.tang.intellij.lua.psi.LuaCallExpr
9+
import com.tang.intellij.lua.psi.LuaTypes
10+
import com.tang.intellij.lua.psi.search.LuaShortNamesManager
11+
import com.tang.intellij.lua.search.SearchContext
12+
import com.tang.intellij.lua.ty.*
13+
import com.tang.lsp.ILuaFile
14+
import org.eclipse.lsp4j.CompletionItemKind
15+
16+
class CallbackCompletionProvider : LuaCompletionProvider() {
17+
override fun addCompletions(session: CompletionSession) {
18+
val completionParameters = session.parameters
19+
val completionResultSet = session.resultSet
20+
21+
val psi = completionParameters.position
22+
val callExpr = psi.parent.parent.parent
23+
24+
if (callExpr is LuaCallExpr) {
25+
var activeParameter = 0
26+
var nCommas = 0
27+
28+
callExpr.args.firstChild?.let { firstChild ->
29+
var child: PsiElement? = firstChild
30+
while (child != null) {
31+
if (child.node.elementType == LuaTypes.COMMA) {
32+
activeParameter++
33+
nCommas++
34+
}
35+
child = child.nextSibling
36+
}
37+
}
38+
val searchContext = SearchContext.get(callExpr.project)
39+
callExpr.guessParentType(searchContext).let { parentType ->
40+
parentType.each { ty ->
41+
if (ty is ITyFunction) {
42+
val active = ty.findPerfectSignature(nCommas + 1)
43+
ty.process(Processor { sig ->
44+
if (sig == active) {
45+
if (activeParameter < sig.params.size) {
46+
sig.params[activeParameter].let {
47+
val paramType = it.ty
48+
if (paramType is TyFunction) {
49+
addCallback(paramType, searchContext, completionResultSet)
50+
}
51+
}
52+
}
53+
54+
}
55+
56+
true
57+
})
58+
}
59+
}
60+
}
61+
}
62+
}
63+
64+
65+
private fun addCallback(
66+
luaType: TyFunction,
67+
searchContext: SearchContext,
68+
completionResultSet: CompletionResultSet
69+
) {
70+
val params = luaType.mainSignature.params
71+
val element = LuaLookupElement("function(${params.map { it.name }.joinToString(", ")}) end")
72+
element.kind = CompletionItemKind.Function
73+
completionResultSet.addElement(element)
74+
}
75+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ abstract class FunSignatureBase(override val colonCall: Boolean,
132132
paramSB.add("...:"+ it.displayName)
133133
}
134134
}
135-
"fun(${paramSB.joinToString(", ")}):${returnTy.displayName}"
135+
"(${paramSB.joinToString(", ")}) -> ${returnTy.displayName}"
136136
}
137137

138138
override val paramSignature: String get() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ open class TyRenderer : TyVisitor(), ITyRenderer {
100100
"{ ${list.joinToString(", ")} }"
101101
}
102102
clazz.hasFlag(TyFlags.ANONYMOUS_TABLE) -> renderType(Constants.WORD_TABLE)
103-
clazz.isAnonymous -> "[local ${clazz.varName}]"
104-
clazz.isGlobal -> "[global ${clazz.varName}]"
103+
clazz.isAnonymous -> clazz.varName
104+
clazz.isGlobal -> clazz.varName
105105
else -> renderType(clazz.className)
106106
}
107107
}

EmmyLua-LS/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
buildscript {
2-
ext.kotlin_version = '1.2.31'
2+
ext.kotlin_version = '1.6.0'
33
repositories {
44
mavenCentral()
55
}
@@ -9,8 +9,8 @@ buildscript {
99
}
1010

1111
plugins {
12-
id "org.jetbrains.kotlin.jvm" version "1.2.30"
13-
id 'com.github.johnrengelman.shadow' version '4.0.3'
12+
id "org.jetbrains.kotlin.jvm" version "1.6.0"
13+
id 'com.github.johnrengelman.shadow' version '6.1.0'
1414
}
1515

1616
apply plugin: "java"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class LuaLanguageServer : LanguageServer, LanguageClientAware {
9090
capabilities.codeLensProvider = CodeLensOptions(true)
9191
capabilities.documentHighlightProvider = true
9292
capabilities.renameProvider = true
93+
9394
capabilities.signatureHelpProvider = SignatureHelpOptions(listOf(",", "("))
9495
capabilities.documentSymbolProvider = true
9596
capabilities.workspaceSymbolProvider = true
@@ -99,7 +100,7 @@ class LuaLanguageServer : LanguageServer, LanguageClientAware {
99100
capabilities.workspace.workspaceFolders.supported = true
100101
capabilities.workspace.workspaceFolders.changeNotifications = Either.forLeft(WORKSPACE_FOLDERS_CAPABILITY_ID)
101102
capabilities.foldingRangeProvider = Either.forLeft(true)
102-
capabilities.documentFormattingProvider = true
103+
// capabilities.documentFormattingProvider = true
103104

104105
capabilities.textDocumentSync = Either.forLeft(TextDocumentSyncKind.Full)
105106

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.tang.vscode.diagnostics
22

33
object DiagnosticsOptions {
44
// 参数验证诊断
5-
var parameterValidation = true
5+
var parameterValidation = false
66

77
// any 类型是否可以赋值给其他类型
88
var anyTypeCanAssignToAnyDefineType = true

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ internal fun renderTy(sb: StringBuilder, ty: ITy) {
8585
}
8686

8787
internal fun renderSignature(sb: StringBuilder, sig: IFunSignature) {
88-
sb.wrap("(", "): ") {
88+
sb.wrap("(", ") -> ") {
8989
var idx = 0
9090
sig.params.forEach {
9191
if (idx++ != 0) sb.append(", ")
@@ -171,10 +171,11 @@ internal fun renderFieldDef(sb: StringBuilder, def: LuaDocTagField) {
171171

172172
internal fun renderDocParam(sb: StringBuilder, child: LuaDocTagParam) {
173173
val paramNameRef = child.paramNameRef
174-
if (paramNameRef != null) {
174+
val commentString = child.commentString
175+
if (paramNameRef != null && commentString != null && commentString.text.isNotEmpty()) {
175176
sb.appendLine("@_param_ `${paramNameRef.text}`: ")
176177
renderTypeUnion(null, null, sb, child.ty)
177-
renderCommentString(" ", null, sb, child.commentString)
178+
renderCommentString(" ", null, sb, commentString)
178179
}
179180
}
180181

0 commit comments

Comments
 (0)