@@ -5,13 +5,22 @@ import com.intellij.lang.javascript.psi.{JSCallExpression, JSExpression, JSRefer
5
5
import com .intellij .openapi .project .Project
6
6
import com .intellij .psi .PsiElement
7
7
import org .klesun .deep_js_completion .completion_providers .PropNamePvdr
8
+ import org .klesun .deep_js_completion .helpers .Mt
8
9
import org .klesun .deep_js_completion .resolvers .MainRes
9
10
import org .klesun .lang .DeepJsLang ._
10
11
11
12
import scala .collection .{GenTraversableOnce , mutable }
12
13
13
14
object SearchCtx {
14
15
val DEBUG = false
16
+ val DEBUG_OBJ = new {
17
+ val PRINT_PSI_TREE = true
18
+ }
19
+ def formatPsi (element : PsiElement ): String = {
20
+ val line = element.getContainingFile.getText
21
+ .slice(0 , element.getTextOffset).split(" \n " ).length
22
+ element.getText.replace(" \n " , " \\ n " ) + " :" + line
23
+ }
15
24
}
16
25
17
26
class SearchCtx (
@@ -82,11 +91,11 @@ class SearchCtx(
82
91
var chain : List [PsiElement ] = List ()
83
92
while (ctx != null ) {
84
93
if (! chain.lastOption.contains(ctx.expr)) {
85
- chain = List (ctx.expr) ++ chain
94
+ chain = chain ++ List (ctx.expr)
86
95
}
87
96
ctx = ctx.parent.orNull
88
97
}
89
- chain
98
+ chain.reverse
90
99
}
91
100
92
101
private def endsWith [T ](superList : List [T ], subList : List [T ]): Boolean = {
@@ -141,16 +150,17 @@ class SearchCtx(
141
150
None
142
151
} else if (expressionsResolved >= 7500 ) {
143
152
None
144
- // } else if (isRecursion(exprCtx)) {
145
- // None
153
+ } else if (isRecursion(exprCtx)) {
154
+ // Console.println("ololo recursion")
155
+ None
146
156
} else {
147
157
putToCache(exprCtx, expr, Iterator .empty.mem())
148
158
val resolved = MainRes .resolveIn(expr, exprCtx).itr
149
159
// no point getting built-in type here, IDEA will show it itself
150
160
val isAtCaret = exprCtx.parent.isEmpty
151
161
val builtIn = getWsType(expr).filter(t => ! isAtCaret)
152
162
var result = frs(resolved, builtIn)
153
- val mit = result.mem()
163
+ val mit = result.flatMap(t => Mt .flattenTypes(t)).unq(). mem()
154
164
if (SearchCtx .DEBUG ) {
155
165
val postfix = " ||| " + singleLine(expr.getText, 350 )
156
166
// TODO: one of types happens to be null sometimes - fix!
0 commit comments