Skip to content

Commit 52ee535

Browse files
committed
修复扩展类的方法定位错误的问题
1 parent 93a3113 commit 52ee535

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ interface ITyClass : ITy {
8383
fun recoverAlias(context: SearchContext, aliasSubstitutor: TyAliasSubstitutor): ITy {
8484
return this
8585
}
86+
87+
fun getClassCallType(context: SearchContext): ITyFunction?
8688
}
8789

8890
fun ITyClass.isVisibleInScope(project: Project, contextTy: ITy, visibility: Visibility): Boolean {
@@ -261,6 +263,14 @@ abstract class TyClass(
261263
return result
262264
}
263265

266+
override fun getClassCallType(context: SearchContext): ITyFunction? {
267+
val ty = findMemberType("ctor", context)
268+
if(ty is ITyFunction){
269+
return ty
270+
}
271+
return null
272+
}
273+
264274
override fun subTypeOf(other: ITy, context: SearchContext, strict: Boolean): Boolean {
265275
// class extends table
266276
if (other == Ty.TABLE) return true

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import com.tang.intellij.lua.editor.completion.CompletionService
1414
import com.tang.intellij.lua.editor.completion.LuaLookupElement
1515
import com.tang.intellij.lua.editor.completion.asCompletionItem
1616
import com.tang.intellij.lua.psi.*
17-
import com.tang.intellij.lua.psi.search.LuaShortNamesManager
1817
import com.tang.intellij.lua.reference.ReferencesSearch
1918
import com.tang.intellij.lua.search.SearchContext
2019
import com.tang.intellij.lua.stubs.index.LuaClassMemberIndex
@@ -24,7 +23,6 @@ import com.tang.vscode.api.impl.LuaFile
2423
//import com.tang.vscode.color.ColorService
2524
import com.tang.vscode.documentation.LuaDocumentationProvider
2625
import com.tang.vscode.extendApi.ExtendApiService
27-
import com.tang.vscode.extendApi.LuaApiClass
2826
import com.tang.vscode.extendApi.LuaReportApiParams
2927
import com.tang.vscode.formatter.FormattingFormatter
3028
import com.tang.vscode.formatter.FormattingType
@@ -519,10 +517,16 @@ class LuaTextDocumentService(private val workspace: LuaWorkspaceService) : TextD
519517

520518
callExpr?.guessParentType(SearchContext.get(psiFile.project))?.let { parentType ->
521519
parentType.each { ty ->
522-
if (ty is ITyFunction) {
523-
val active = ty.findPerfectSignature(callExpr, nCommas + 1)
520+
var tyFunction: ITy? = ty
521+
if(tyFunction is ITyClass){
522+
val context = SearchContext.get(workspace.getProject())
523+
tyFunction = tyFunction.getClassCallType(context)
524+
}
525+
526+
if (tyFunction is ITyFunction) {
527+
val active = tyFunction.findPerfectSignature(callExpr, nCommas + 1)
524528
var idx = 0
525-
ty.process(Processor { sig ->
529+
tyFunction.process(Processor { sig ->
526530
val information = SignatureInformation()
527531
information.parameters = mutableListOf()
528532
sig.params.forEach { pi ->

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import com.tang.intellij.lua.ty.Ty
99
import com.tang.intellij.lua.ty.TySerializedFunction
1010

1111
object ExtendApiService {
12+
private var rootNamespaceName = "_G"
1213
private var rootNamespace: Namespace? = null
1314
private var namespaceMap: MutableMap<String, Namespace> = mutableMapOf()
1415
private var classMap: MutableMap<String, ExtendClass> = mutableMapOf()
1516

1617
fun loadApi(project: Project, api: LuaReportApiParams) {
1718
val mgr = PsiManager.getInstance(project)
19+
rootNamespaceName = api.root
1820
rootNamespace = Namespace(api.root, null, mgr, false)
1921
namespaceMap.clear()
2022
classMap.clear()
@@ -59,7 +61,7 @@ object ExtendApiService {
5961
emptyArray(),
6062
luaMethod.comment
6163
)
62-
extendClass.addMethod(luaMethod.name, signature)
64+
extendClass.addMethod(luaMethod.name, signature, luaMethod.comment, luaMethod.location)
6365
}
6466
}
6567
}
@@ -70,7 +72,7 @@ object ExtendApiService {
7072
}
7173

7274
fun getNsMember(name: String): NsMember? {
73-
if (name == "_G" || name == "CS") {
75+
if (name == rootNamespaceName) {
7476
return rootNamespace
7577
}
7678

@@ -83,6 +85,14 @@ object ExtendApiService {
8385
if (member != null) {
8486
return member
8587
}
88+
// generic workaround
89+
val genericIndex = name.indexOf('<')
90+
if(genericIndex != -1)
91+
{
92+
val baseTypeName = name.substring(0, genericIndex)
93+
return classMap[baseTypeName]
94+
}
95+
8696
return null
8797
}
8898

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ class TyExtendClass(val clazz: ExtendClass) : TyClass(
6666
override fun findMember(name: String, searchContext: SearchContext): LuaClassMember? {
6767
return clazz.findMember(name)
6868
}
69+
70+
override fun getClassCallType(context: SearchContext): ITyFunction? {
71+
val ty = clazz.findMember(".ctor")
72+
if(ty is ExtendClassMember){
73+
val funTy = ty.type
74+
if(funTy is ITyFunction){
75+
return funTy
76+
}
77+
}
78+
return null
79+
}
6980
}
7081

7182
class ExtendClass(
@@ -94,7 +105,7 @@ class ExtendClass(
94105
members.add(member)
95106
}
96107

97-
fun addMethod(name: String, signature: FunSignature) {
108+
fun addMethod(name: String, signature: FunSignature, comment: String, location: String) {
98109
if (!methods.containsKey(name)) {
99110
val ty = TyExtendFunction(this, name)
100111
methods[name] = mutableListOf(signature)

0 commit comments

Comments
 (0)