Skip to content

Commit b8fd576

Browse files
committed
sync code from IntelliJ-EmmyLua
1 parent 6e431e4 commit b8fd576

File tree

19 files changed

+335
-231
lines changed

19 files changed

+335
-231
lines changed

EmmyLua-Common/src/main/ext/com/tang/intellij/lua/project/LuaSettings.kt

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

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

19+
import com.tang.intellij.lua.Constants
1920
import com.tang.intellij.lua.lang.LuaLanguageLevel
2021

2122
/**
@@ -59,5 +60,9 @@ class LuaSettings {
5960
fun isConstructorName(name: String): Boolean {
6061
return instance.constructorNames.contains(name.toLowerCase())
6162
}
63+
64+
fun isImporterName(name: String): Boolean {
65+
return name == Constants.WORD_REQUIRE
66+
}
6267
}
6368
}

EmmyLua-Common/src/main/ext/com/tang/intellij/lua/psi/LuaPsiFile.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class LuaPsiFile(private val myNode: ASTNode) : ASTDelegatePsiElement(), PsiFile
5454
return 0
5555
}
5656

57+
val isContentsLoaded: Boolean get() = true
58+
5759
companion object {
5860
private var idCount = 0
5961
}

EmmyLua-Common/src/main/gen/com/tang/intellij/lua/lexer/_LuaLexer.java

Lines changed: 190 additions & 187 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ open class ClassMemberCompletionProvider : LuaCompletionProvider() {
6262
complete(isColon, project, contextTy, prefixType, completionResultSet, completionResultSet.prefixMatcher, null)
6363
}
6464
//smart
65-
/*val nameExpr = indexExpr.prefixExpr
65+
val nameExpr = indexExpr.prefixExpr
6666
if (nameExpr is LuaNameExpr) {
6767
val colon = if (isColon) ":" else "."
6868
val prefixName = nameExpr.text
@@ -88,7 +88,7 @@ open class ClassMemberCompletionProvider : LuaCompletionProvider() {
8888
}
8989
true
9090
}
91-
}*/
91+
}
9292
}
9393
}
9494

EmmyLua-Common/src/main/java/com/tang/intellij/lua/lang/LuaLanguage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import com.intellij.lang.Language;
2020

2121
/**
22-
* Created by TangZhiXu on 2015/11/15.
23-
* Email:272669294@qq.com
22+
* Created by tangzx on 2015/11/15.
23+
* Email:love.tangzx@qq.com
2424
*/
2525
public class LuaLanguage extends Language {
2626

EmmyLua-Common/src/main/java/com/tang/intellij/lua/lua.flex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ n=[0-9]+
6868
h=[0-9a-fA-F]+
6969
exp=[Ee]([+-]?{n})?
7070
ppp=[Pp][+-]{n}
71-
NUMBER=(0[xX]({h}|{h}[.]{h})({exp}|{ppp})?|({n}|{n}[.]{n}){exp}?|[.]{n}|{n}[.])
71+
// 123ULL/123LL
72+
// 0x123FFULL/0x123FFLL
73+
JIT_EXT_NUMBER=(0[xX]{h}|{n})U?LL
74+
HEX_NUMBER=0[xX]({h}|{h}[.]{h})({exp}|{ppp})?
75+
NUMBER={JIT_EXT_NUMBER}|{HEX_NUMBER}|({n}|{n}[.]{n}){exp}?|[.]{n}|{n}[.]
7276

7377
//Comments
7478
REGION_START =--(region|\{\{\{)([^\r\n]*)*

EmmyLua-Common/src/main/java/com/tang/intellij/lua/psi/LuaDeclarationTree.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,19 @@ interface LuaDeclarationTree {
3333
ret = null
3434
}
3535
if (ret == null) {
36-
val manager = if (file is LuaPsiFile && file.fileElement == null) LuaDeclarationTreeStub(file) else LuaDeclarationTreePsi(file)
37-
manager.buildTree(file)
36+
var manager: LuaDeclarationTree? = null
37+
if (file is LuaPsiFile && !file.isContentsLoaded) {
38+
manager = LuaDeclarationTreeStub(file)
39+
try {
40+
manager.buildTree(file)
41+
} catch (e: Exception) {
42+
manager = null
43+
}
44+
}
45+
if (manager == null) {
46+
manager = LuaDeclarationTreePsi(file)
47+
manager.buildTree(file)
48+
}
3849
file.putUserData(key, manager)
3950
ret = manager
4051
}
@@ -356,6 +367,7 @@ private class LuaDeclarationTreePsi(file: PsiFile) : LuaDeclarationTreeBase(file
356367
}
357368

358369
override fun getPosition(psi: PsiElement): Int {
370+
if (psi is PsiFile) return 0
359371
return psi.node.startOffset
360372
}
361373
}
@@ -365,7 +377,7 @@ private class LuaDeclarationTreeStub(file: PsiFile) : LuaDeclarationTreeBase(fil
365377
var count = 0
366378

367379
override fun shouldRebuild(): Boolean {
368-
return super.shouldRebuild() || (file as? LuaPsiFile)?.fileElement != null
380+
return super.shouldRebuild() || (file as? LuaPsiFile)?.isContentsLoaded == true
369381
}
370382

371383
override fun visitElementExt(element: PsiElement) {

EmmyLua-Common/src/main/java/com/tang/intellij/lua/psi/LuaParserUtil.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,15 @@ private static boolean matchEnd(boolean advanced, PsiBuilder builder, int level,
191191
}
192192

193193
while (!skips.contains(type)) {
194-
// if (BRACE_R_SET.contains(type)) {
195-
// return false;
196-
// }
197194
if (types.contains(type)) {
198195
if (level != 0)
199196
builder.advanceLexer();
200197
return true;
201198
}
199+
// bug fix https://github.com/EmmyLua/IntelliJ-EmmyLua/issues/276
200+
// todo: optimize it
201+
if (type == UNTIL)
202+
return true;
202203
boolean isMatched = matchStart(false, builder, level + 1, type);
203204
if (!isMatched)
204205
break;

EmmyLua-Common/src/main/java/com/tang/intellij/lua/psi/LuaPsiResolveUtil.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,26 @@ fun multiResolve(ref: LuaNameExpr, context: SearchContext): Array<PsiElement> {
118118
return list.toTypedArray()
119119
}
120120

121+
fun multiResolve(indexExpr: LuaIndexExpr, context: SearchContext): List<PsiElement> {
122+
val list = mutableListOf<PsiElement>()
123+
val name = indexExpr.name ?: return list
124+
val type = indexExpr.guessParentType(context)
125+
type.eachTopClass(Processor { ty ->
126+
val m = ty.findMember(name, context)
127+
if (m != null)
128+
list.add(m)
129+
true
130+
})
131+
if (list.isEmpty()) {
132+
val tree = LuaDeclarationTree.get(indexExpr.containingFile)
133+
val declaration = tree.find(indexExpr)
134+
if (declaration != null) {
135+
list.add(declaration.psi)
136+
}
137+
}
138+
return list
139+
}
140+
121141
fun resolve(indexExpr: LuaIndexExpr, context: SearchContext): PsiElement? {
122142
val name = indexExpr.name ?: return null
123143
return resolve(indexExpr, name, context)

EmmyLua-Common/src/main/java/com/tang/intellij/lua/psi/LuaTokenType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import com.tang.intellij.lua.lang.LuaLanguage;
2121

2222
/**
23-
* Created by TangZhiXu on 2015/11/15.
24-
* Email:272669294@qq.com
23+
* Created by tangzx on 2015/11/15.
24+
* Email:love.tangzx@qq.com
2525
*/
2626
public class LuaTokenType extends IElementType {
2727
public LuaTokenType(String debugName) {

0 commit comments

Comments
 (0)