@@ -166,38 +166,49 @@ object Interactive {
166
166
private def computeCompletions (pos : SourcePosition , path : List [Tree ])(implicit ctx : Context ): (Int , List [Symbol ]) = {
167
167
val completions = Scopes .newScope.openForMutations
168
168
169
+ /**
170
+ * The information about the current completion.
171
+ *
172
+ * @param position The position where the completion result should be inserted.
173
+ * @param prefix A prefix that potential completion results must match.
174
+ * @param termOnly If set, only terms should be considered as completion results.
175
+ * @param typeOnly If set, only types should be considered as completion results.
176
+ * @param inImport If set, indicates that this is the completion of an import node.
177
+ */
178
+ case class CompletionInfo (position : Int , prefix : String , termOnly : Boolean , typeOnly : Boolean , inImport : Boolean )
179
+
169
180
/**
170
181
* Extract basic info about completion location and the kind of symbols to include.
171
182
*
172
183
* @param path The path to the position where completion happens
173
184
* @param inImport If set, indicates that this is the completion of an import node. When
174
185
* completing imports, both types and terms are always included.
175
- * @return The point where to insert completion, whether terms should be included in results,
176
- * whether types should be included, and whether we're completing an import.
186
+ * @return The completion info
177
187
*/
178
- def completionInfo (path : List [Tree ], inImport : Boolean ): ( Int , String , Boolean , Boolean , Boolean ) = path match {
188
+ def completionInfo (path : List [Tree ], inImport : Boolean ): CompletionInfo = path match {
179
189
case (ref : RefTree ) :: _ =>
180
190
if (ref.name == nme.ERROR )
181
- (ref.pos.point, " " , false , false , inImport)
191
+ CompletionInfo (ref.pos.point, " " , false , false , inImport)
182
192
else
183
- (ref.pos.point,
184
- ref.name.toString.take(pos.pos.point - ref.pos.point),
185
- ! inImport && ref.name.isTermName, // Types and terms are always accepted in imports
186
- ! inImport && ref.name.isTypeName,
187
- inImport)
193
+ CompletionInfo (
194
+ ref.pos.point,
195
+ ref.name.toString.take(pos.pos.point - ref.pos.point),
196
+ ! inImport && ref.name.isTermName, // Types and terms are always accepted in imports
197
+ ! inImport && ref.name.isTypeName,
198
+ inImport)
188
199
case _ =>
189
- (0 , " " , false , false , false )
200
+ CompletionInfo (0 , " " , false , false , false )
190
201
}
191
202
192
- val (completionPos, prefix, termOnly, typeOnly, inImport) = path match {
203
+ val info = path match {
193
204
case (Thicket (name :: _ :: Nil )) :: (imp : Import ) :: _ =>
194
205
if (name.pos.contains(pos.pos))
195
206
completionInfo(name.asInstanceOf [tpd.Tree ] :: Nil , /* inImport = */ true )
196
207
else completionInfo(path, /* inImport = */ true )
197
208
198
209
case (imp : Import ) :: _ =>
199
210
imp.selectors.find(_.pos.contains(pos.pos)) match {
200
- case None => (imp.expr.pos.point, " " , false , false , true )
211
+ case None => CompletionInfo (imp.expr.pos.point, " " , false , false , true )
201
212
case Some (sel) => completionInfo(sel.asInstanceOf [tpd.Tree ] :: Nil , /* inImport = */ true )
202
213
}
203
214
@@ -225,15 +236,15 @@ object Interactive {
225
236
* classes.
226
237
*/
227
238
def include (sym : Symbol ) =
228
- sym.name.startsWith(prefix) &&
229
- ! sym.name.toString.drop(prefix.length).contains('$' ) &&
239
+ sym.name.startsWith(info. prefix) &&
240
+ ! sym.name.toString.drop(info. prefix.length).contains('$' ) &&
230
241
! sym.isPrimaryConstructor &&
231
242
sym.sourceSymbol.exists &&
232
243
(! sym.is(Package ) || ! sym.moduleClass.exists) &&
233
- (! inImport || ! sym.is(allOf(JavaDefined , Module ), butNot = Package )) &&
244
+ (! info. inImport || ! sym.is(allOf(JavaDefined , Module ), butNot = Package )) &&
234
245
! sym.is(allOf(Mutable , Accessor )) &&
235
- (! termOnly || sym.isTerm) &&
236
- (! typeOnly || sym.isType)
246
+ (! info. termOnly || sym.isTerm) &&
247
+ (! info. typeOnly || sym.isType)
237
248
238
249
def enter (sym : Symbol ) =
239
250
if (include(sym)) completions.enter(sym)
@@ -311,7 +322,7 @@ object Interactive {
311
322
312
323
def getMemberCompletions (qual : Tree ): Unit = {
313
324
addAccessibleMembers(qual.tpe)
314
- if (! inImport) {
325
+ if (! info. inImport) {
315
326
// Implicit conversions do not kick in when importing
316
327
implicitConversionTargets(qual)(ctx.fresh.setExploreTyperState())
317
328
.foreach(addAccessibleMembers(_))
@@ -326,8 +337,8 @@ object Interactive {
326
337
}
327
338
328
339
val completionList = completions.toList
329
- interactiv.println(i " completion with pos = $pos, prefix = $prefix, termOnly = $termOnly, typeOnly = $typeOnly = $completionList%, % " )
330
- (completionPos , completionList)
340
+ interactiv.println(i " completion with pos = $pos, prefix = $info . prefix, termOnly = $info . termOnly, typeOnly = $info . typeOnly = $completionList%, % " )
341
+ (info.position , completionList)
331
342
}
332
343
333
344
/** Possible completions of members of `prefix` which are accessible when called inside `boundary` */
0 commit comments