Skip to content

Commit 0e24502

Browse files
committed
upgrade emmy core
1 parent 4b1e065 commit 0e24502

30 files changed

+387
-157
lines changed

EmmyLua-Common/src/main/java/com/tang/intellij/lua/comment/reference/LuaClassNameReference.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class LuaClassNameReference(element: LuaDocClassNameRef) : PsiReferenceBase<LuaD
5151
// generic in docFunction
5252
val fn = PsiTreeUtil.getParentOfType(myElement, LuaDocFunctionTy::class.java)
5353
var genericDefList: Collection<LuaDocGenericDef>? = fn?.genericDefList
54-
if (genericDefList == null) {
54+
if (genericDefList == null || genericDefList.isEmpty()) {
5555
// generic in comments ?
5656
val comment = LuaCommentUtil.findContainer(myElement)
5757
genericDefList = comment.findTags(LuaDocGenericDef::class.java)

EmmyLua-Common/src/main/java/com/tang/intellij/lua/comment/reference/LuaDocSeeReference.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class LuaDocSeeReference(see: LuaDocTagSee) :
4949
override fun multiResolve(incomplete: Boolean): Array<ResolveResult> {
5050
val list = mutableListOf<ResolveResult>()
5151
val type = myElement.classNameRef?.resolveType() as ITyClass
52-
LuaClassMemberIndex.process(type.className, id.text, SearchContext(myElement.project), Processor {
52+
LuaClassMemberIndex.process(type.className, id.text, SearchContext.get(myElement.project), Processor {
5353
list.add(PsiElementResolveResult(it))
5454
true
5555
})

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
TAG_NAME_SEE = 'see'
7474
TAG_NAME_GENERIC = 'generic'
7575
TAG_NAME_ALIAS = 'alias'
76+
TAG_NAME_SUPPRESS = 'suppress'
7677
]
7778
implements("tag.*") = [
7879
"com.tang.intellij.lua.comment.psi.LuaDocTag"
@@ -85,6 +86,7 @@ private after_dash ::= doc_item | STRING { recoverWhile=after_dash_recover }
8586
private after_dash_recover ::= !(DASHES)
8687
private doc_item ::= '@' (tag_param
8788
| tag_alias
89+
| tag_suppress
8890
| tag_vararg
8991
| tag_return
9092
| tag_class
@@ -310,4 +312,8 @@ tag_alias ::= TAG_NAME_ALIAS ID ty {
310312
getType
311313
]
312314
stubClass = "com.tang.intellij.lua.stubs.LuaDocTagAliasStub"
315+
}
316+
317+
tag_suppress ::= TAG_NAME_SUPPRESS ID (',' ID)* {
318+
pin = 1
313319
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ SINGLE_QUOTED_STRING='([^\\\']|\\\S|\\[\r\n])*'? //'([^\\'\r\n]|\\[^\r\n])*'?
6565
%state xFIELD_ID
6666
%state xGENERIC
6767
%state xALIAS
68+
%state xSUPPRESS
6869
%state xDOUBLE_QUOTED_STRING
6970
%state xSINGLE_QUOTED_STRING
7071

@@ -78,7 +79,7 @@ SINGLE_QUOTED_STRING='([^\\\']|\\\S|\\[\r\n])*'? //'([^\\'\r\n]|\\[^\r\n])*'?
7879
. { yybegin(xCOMMENT_STRING); yypushback(yylength()); }
7980
}
8081

81-
<xTAG, xTAG_WITH_ID, xTAG_NAME, xPARAM, xTYPE_REF, xCLASS, xCLASS_EXTEND, xFIELD, xFIELD_ID, xCOMMENT_STRING, xGENERIC, xALIAS> {
82+
<xTAG, xTAG_WITH_ID, xTAG_NAME, xPARAM, xTYPE_REF, xCLASS, xCLASS_EXTEND, xFIELD, xFIELD_ID, xCOMMENT_STRING, xGENERIC, xALIAS, xSUPPRESS> {
8283
{EOL} { yybegin(YYINITIAL);return com.intellij.psi.TokenType.WHITE_SPACE;}
8384
{LINE_WS}+ { return com.intellij.psi.TokenType.WHITE_SPACE; }
8485
}
@@ -99,10 +100,17 @@ SINGLE_QUOTED_STRING='([^\\\']|\\\S|\\[\r\n])*'? //'([^\\'\r\n]|\\[^\r\n])*'?
99100
"generic" { yybegin(xGENERIC); return TAG_NAME_GENERIC; }
100101
"see" { yybegin(xTAG); return TAG_NAME_SEE; }
101102
"alias" { yybegin(xALIAS); return TAG_NAME_ALIAS; }
103+
"suppress" { yybegin(xSUPPRESS); return TAG_NAME_SUPPRESS; }
102104
{ID} { yybegin(xCOMMENT_STRING); return TAG_NAME; }
103105
[^] { return com.intellij.psi.TokenType.BAD_CHARACTER; }
104106
}
105107

108+
<xSUPPRESS> {
109+
{ID} { return ID; }
110+
"," { return COMMA; }
111+
[^] { yybegin(YYINITIAL); yypushback(yylength()); }
112+
}
113+
106114
<xALIAS> {
107115
{ID} { beginType(); return ID; }
108116
[^] { yybegin(YYINITIAL); yypushback(yylength()); }

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616

1717
package com.tang.intellij.lua.editor.completion
1818

19-
import com.intellij.codeInsight.completion.CompletionInitializationContext
2019
import com.intellij.codeInsight.completion.CompletionResultSet
2120
import com.intellij.codeInsight.completion.PrefixMatcher
22-
import com.intellij.codeInsight.completion.PrioritizedLookupElement
2321
import com.intellij.codeInsight.lookup.LookupElement
2422
import com.intellij.openapi.progress.ProgressManager
2523
import com.intellij.openapi.project.Project
2624
import com.intellij.util.Processor
2725
import com.tang.intellij.lua.lang.LuaIcons
28-
import com.tang.intellij.lua.psi.*
26+
import com.tang.intellij.lua.psi.LuaClassField
27+
import com.tang.intellij.lua.psi.LuaClassMember
28+
import com.tang.intellij.lua.psi.LuaIndexExpr
29+
import com.tang.intellij.lua.psi.LuaPsiTreeUtil
2930
import com.tang.intellij.lua.search.SearchContext
3031
import com.tang.intellij.lua.ty.*
3132

@@ -55,9 +56,8 @@ open class ClassMemberCompletionProvider : LuaCompletionProvider() {
5556
if (indexExpr is LuaIndexExpr) {
5657
val isColon = indexExpr.colon != null
5758
val project = indexExpr.project
58-
val searchContext = SearchContext(project)
5959
val contextTy = LuaPsiTreeUtil.findContextClass(indexExpr)
60-
val prefixType = indexExpr.guessParentType(searchContext)
60+
val prefixType = SearchContext.with(project) { indexExpr.guessParentType(it) }
6161
if (!Ty.isInvalid(prefixType)) {
6262
complete(isColon, project, contextTy, prefixType, completionResultSet, completionResultSet.prefixMatcher, null)
6363
}
@@ -73,7 +73,7 @@ open class ClassMemberCompletionProvider : LuaCompletionProvider() {
7373
val it = d.firstDeclaration.psi
7474
val txt = it.name
7575
if (it is LuaTypeGuessable && txt != null && prefixName != txt && matcher.prefixMatches(txt)) {
76-
val type = it.guessType(searchContext)
76+
val type = SearchContext.infer(it)
7777
if (!Ty.isInvalid(prefixType)) {
7878
val prefixMatcher = completionResultSet.prefixMatcher
7979
val resultSet = completionResultSet.withPrefixMatcher("$prefixName*$postfixName")
@@ -113,7 +113,7 @@ open class ClassMemberCompletionProvider : LuaCompletionProvider() {
113113
completionResultSet: CompletionResultSet,
114114
prefixMatcher: PrefixMatcher,
115115
handlerProcessor: HandlerProcessor?) {
116-
val context = SearchContext(project)
116+
val context = SearchContext.get(project)
117117
luaType.lazyInit(context)
118118
luaType.processMembers(context) { curType, member ->
119119
ProgressManager.checkCanceled()
@@ -138,7 +138,7 @@ open class ClassMemberCompletionProvider : LuaCompletionProvider() {
138138
completionMode: MemberCompletionMode,
139139
project: Project,
140140
handlerProcessor: HandlerProcessor?) {
141-
val type = member.guessType(SearchContext(project))
141+
val type = member.guessType(SearchContext.get(project))
142142
val bold = thisType == callType
143143
val className = thisType.displayName
144144
if (type is ITyFunction) {
@@ -179,7 +179,7 @@ open class ClassMemberCompletionProvider : LuaCompletionProvider() {
179179
val firstParam = it.getFirstParam(thisType, isColonStyle)
180180
if (isColonStyle) {
181181
if (firstParam == null) return@Processor true
182-
if (!callType.subTypeOf(firstParam.ty, SearchContext(classMember.project), true))
182+
if (!callType.subTypeOf(firstParam.ty, SearchContext.get(classMember.project), true))
183183
return@Processor true
184184
}
185185

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ class LocalAndGlobalCompletionProvider(private val mask: Int) : ClassMemberCompl
5151
}
5252
when (psi) {
5353
is LuaFuncBodyOwner -> {
54-
addTy(psi.guessType(SearchContext(psi.project)) as ITyFunction)
54+
addTy(SearchContext.infer(psi) as ITyFunction)
5555
}
5656
is LuaTypeGuessable -> {
57-
val type = psi.guessType(SearchContext(psi.project))
57+
val type = SearchContext.infer(psi)
5858
var isFn = false
5959
TyUnion.each(type) {
6060
if (it is ITyFunction) {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ class LuaDocCompletionContributor : CompletionContributor() {
114114
val classDef = PsiTreeUtil.findChildOfType(comment, LuaDocTagClass::class.java)
115115
if (classDef != null) {
116116
val classType = classDef.type
117-
classType.processMembers(SearchContext(classDef.project)) { _, member ->
117+
val ctx = SearchContext.get(classDef.project)
118+
classType.processMembers(ctx) { _, member ->
118119
if (member is LuaClassField)
119120
completionResultSet.addElement(LookupElementBuilder.create(member.name!!).withIcon(LuaIcons.CLASS_FIELD))
120121
Unit
@@ -130,7 +131,8 @@ class LuaDocCompletionContributor : CompletionContributor() {
130131
val seeRefTag = PsiTreeUtil.getParentOfType(position, LuaDocTagSee::class.java)
131132
if (seeRefTag != null) {
132133
val classType = seeRefTag.classNameRef?.resolveType() as? ITyClass
133-
classType?.processMembers(SearchContext(seeRefTag.project)) { _, member ->
134+
val ctx = SearchContext.get(seeRefTag.project)
135+
classType?.processMembers(ctx) { _, member ->
134136
completionResultSet.addElement(LookupElementBuilder.create(member.name!!).withIcon(LuaIcons.CLASS_FIELD))
135137
Unit
136138
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import com.tang.intellij.lua.psi.LuaNameExpr
2424
import com.tang.intellij.lua.psi.LuaTypes
2525
import com.tang.intellij.lua.psi.shouldBe
2626
import com.tang.intellij.lua.search.SearchContext
27-
import com.tang.intellij.lua.ty.TyAliasSubstitutor
2827
import com.tang.intellij.lua.ty.TyStringLiteral
2928
import org.eclipse.lsp4j.CompletionItemKind
3029

@@ -34,7 +33,7 @@ class SmartCompletionContributor : CompletionContributor() {
3433
override fun addCompletions(completionParameters: CompletionParameters, processingContext: ProcessingContext, completionResultSet: CompletionResultSet) {
3534
val id = completionParameters.position
3635
val expr = PsiTreeUtil.getParentOfType(id, LuaNameExpr::class.java) ?: return
37-
val ty = expr.shouldBe(SearchContext(expr.project)).substitute(TyAliasSubstitutor(expr.project))
36+
val ty = expr.shouldBe(SearchContext.get(expr.project))
3837
ty.each {
3938
if (it is TyStringLiteral) {
4039
val lookupElement = LuaLookupElement(it.content)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
public class LuaLanguage extends Language {
2626

27-
public static final int INDEX_VERSION = 34;
27+
public static final int INDEX_VERSION = 36;
2828

2929
public static final LuaLanguage INSTANCE = new LuaLanguage();
3030

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

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private open class Scope(
187187
}
188188
}
189189

190-
private abstract class LuaDeclarationTreeBase(val file: PsiFile) : LuaStubRecursiveVisitor(), LuaDeclarationTree {
190+
private abstract class LuaDeclarationTreeBase(val file: PsiFile) : LuaRecursiveVisitor(), LuaDeclarationTree {
191191
companion object {
192192
val scopeKey = Key.create<Scope>("lua.object.tree.scope")
193193
}
@@ -229,28 +229,34 @@ private abstract class LuaDeclarationTreeBase(val file: PsiFile) : LuaStubRecurs
229229
}
230230

231231
private fun push(scope: Scope, psi: PsiElement): Scope {
232-
scopes.push(scope)
233-
if (topScope == null)
234-
topScope = scope
235-
psi.putUserData(scopeKey, scope)
236-
curScope?.add(scope)
237-
curScope = scope
232+
synchronized(scope) {
233+
scopes.push(scope)
234+
if (topScope == null)
235+
topScope = scope
236+
psi.putUserData(scopeKey, scope)
237+
curScope?.add(scope)
238+
curScope = scope
239+
}
238240
return scope
239241
}
240242

241243
private fun pop(): Scope {
242-
val pop = scopes.pop()
243-
curScope = if (scopes.isEmpty()) topScope else scopes.peek()
244-
return pop
244+
synchronized(scopes) {
245+
val pop = scopes.pop()
246+
curScope = if (scopes.isEmpty()) topScope else scopes.peek()
247+
return pop
248+
}
245249
}
246250

247251
fun buildTree(file: PsiFile) {
248-
//val t = System.currentTimeMillis()
249-
scopes.clear()
250-
topScope = null
251-
curScope = null
252-
file.accept(this)
253-
//println("build tree : ${file.name}, ${System.currentTimeMillis() - t}")
252+
synchronized(scopes) {
253+
//val t = System.currentTimeMillis()
254+
scopes.clear()
255+
topScope = null
256+
curScope = null
257+
file.accept(this)
258+
//println("build tree : ${file.name}, ${System.currentTimeMillis() - t}")
259+
}
254260
}
255261

256262
abstract fun findScope(psi: PsiElement): Scope?
@@ -319,12 +325,16 @@ private abstract class LuaDeclarationTreeBase(val file: PsiFile) : LuaStubRecurs
319325
super.visitAssignStat(o)
320326
}
321327

328+
protected open fun visitElementExt(element: PsiElement) {
329+
super.visitElement(element)
330+
}
331+
322332
override fun visitElement(element: PsiElement) {
323333
if (element is LuaDeclarationScope) {
324334
push(element)
325-
super.visitElement(element)
335+
visitElementExt(element)
326336
pop()
327-
} else super.visitElement(element)
337+
} else visitElementExt(element)
328338
}
329339
}
330340

@@ -358,6 +368,21 @@ private class LuaDeclarationTreeStub(file: PsiFile) : LuaDeclarationTreeBase(fil
358368
return super.shouldRebuild() || (file as? LuaPsiFile)?.fileElement != null
359369
}
360370

371+
override fun visitElementExt(element: PsiElement) {
372+
var stub: STUB_ELE? = null
373+
if (element is LuaPsiFile) {
374+
stub = element.stub
375+
}
376+
if (element is STUB_PSI) {
377+
stub = element.stub
378+
}
379+
if (stub != null) {
380+
for (child in stub.childrenStubs) {
381+
child.psi.accept(this)
382+
}
383+
} else super.visitElementExt(element)
384+
}
385+
361386
override fun findScope(psi: PsiElement): Scope? {
362387
if (psi is STUB_PSI) {
363388
val stub = psi.stub

0 commit comments

Comments
 (0)