@@ -34,48 +34,20 @@ object Completion {
34
34
35
35
private def computeCompletions (pos : SourcePosition , path : List [Tree ])(implicit ctx : Context ): (Int , List [Symbol ]) = {
36
36
37
- /**
38
- * Extract basic info about completion location and the kind of symbols to include.
39
- *
40
- * @param path The path to the position where completion happens
41
- * @param inImport If set, indicates that this is the completion of an import node. When
42
- * completing imports, both types and terms are always included.
43
- * @return The information about completion (offset, kinds of symbol, etc.)
44
- */
45
- def completionInfo (path : List [Tree ], inImport : Boolean ): CompletionInfo = path match {
46
- case (ref : RefTree ) :: _ =>
47
- if (ref.name == nme.ERROR )
48
- CompletionInfo (ref.pos.point, " " , Mode .None )
49
- else {
50
- val mode =
51
- if (inImport) Mode .Import
52
- else if (ref.name.isTermName) Mode .Term
53
- else Mode .Type
54
-
55
- CompletionInfo (
56
- ref.pos.point,
57
- ref.name.toString.take(pos.pos.point - ref.pos.point),
58
- mode)
59
- }
60
-
61
- case _ =>
62
- CompletionInfo (0 , " " , Mode .None )
63
- }
64
-
65
37
val info = path match {
66
38
case (Thicket (name :: _ :: Nil )) :: (imp : Import ) :: _ =>
67
39
if (name.pos.contains(pos.pos))
68
- completionInfo (name.asInstanceOf [Tree ] :: Nil , /* inImport = */ true )
69
- else completionInfo (path, /* inImport = */ true )
40
+ CompletionInfo (name.asInstanceOf [Tree ] :: Nil , pos, inImport = true )
41
+ else CompletionInfo (path, pos, inImport = true )
70
42
71
43
case (imp : Import ) :: _ =>
72
44
imp.selectors.find(_.pos.contains(pos.pos)) match {
73
- case None => CompletionInfo (imp.expr.pos.point, " " , Mode .Import )
74
- case Some (sel) => completionInfo (sel.asInstanceOf [Tree ] :: Nil , /* inImport = */ true )
45
+ case None => new CompletionInfo (imp.expr.pos.point, " " , Mode .Import )
46
+ case Some (sel) => CompletionInfo (sel.asInstanceOf [Tree ] :: Nil , pos, inImport = true )
75
47
}
76
48
77
49
case other =>
78
- completionInfo (other, /* inImport = */ false )
50
+ CompletionInfo (other, pos, inImport = false )
79
51
}
80
52
81
53
def accessibleMembers (site : Type , superAccess : Boolean = true ): Seq [Symbol ] = site match {
@@ -177,7 +149,7 @@ object Completion {
177
149
* @param prefix A prefix that potential completion results must match.
178
150
* @param mode The completion mode.
179
151
*/
180
- private case class CompletionInfo (offset : Int , prefix : String , mode : Mode ) {
152
+ private class CompletionInfo (val offset : Int , val prefix : String , val mode : Mode ) {
181
153
182
154
private [this ] val completions = Scopes .newScope.openForMutations
183
155
@@ -234,6 +206,36 @@ object Completion {
234
206
}
235
207
}
236
208
}
209
+ private object CompletionInfo {
210
+
211
+ /**
212
+ * Extract basic info about completion location and the kind of symbols to include.
213
+ *
214
+ * @param path The path to the position where completion happens
215
+ * @param inImport If set, indicates that this is the completion of an import node. When
216
+ * completing imports, both types and terms are always included.
217
+ * @return The information about completion (offset, kinds of symbol, etc.)
218
+ */
219
+ def apply (path : List [Tree ], pos : SourcePosition , inImport : Boolean ): CompletionInfo = path match {
220
+ case (ref : RefTree ) :: _ =>
221
+ if (ref.name == nme.ERROR )
222
+ new CompletionInfo (ref.pos.point, " " , Mode .None )
223
+ else {
224
+ val mode =
225
+ if (inImport) Mode .Import
226
+ else if (ref.name.isTermName) Mode .Term
227
+ else Mode .Type
228
+
229
+ new CompletionInfo (
230
+ ref.pos.point,
231
+ ref.name.toString.take(pos.pos.point - ref.pos.point),
232
+ mode)
233
+ }
234
+
235
+ case _ =>
236
+ new CompletionInfo (0 , " " , Mode .None )
237
+ }
238
+ }
237
239
238
240
/**
239
241
* The completion mode: defines what kinds of symbols should be included in the completion
0 commit comments