@@ -166,38 +166,49 @@ object Interactive {
166166 private def computeCompletions (pos : SourcePosition , path : List [Tree ])(implicit ctx : Context ): (Int , List [Symbol ]) = {
167167 val completions = Scopes .newScope.openForMutations
168168
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+
169180 /**
170181 * Extract basic info about completion location and the kind of symbols to include.
171182 *
172183 * @param path The path to the position where completion happens
173184 * @param inImport If set, indicates that this is the completion of an import node. When
174185 * 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
177187 */
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 {
179189 case (ref : RefTree ) :: _ =>
180190 if (ref.name == nme.ERROR )
181- (ref.pos.point, " " , false , false , inImport)
191+ CompletionInfo (ref.pos.point, " " , false , false , inImport)
182192 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)
188199 case _ =>
189- (0 , " " , false , false , false )
200+ CompletionInfo (0 , " " , false , false , false )
190201 }
191202
192- val (completionPos, prefix, termOnly, typeOnly, inImport) = path match {
203+ val info = path match {
193204 case (Thicket (name :: _ :: Nil )) :: (imp : Import ) :: _ =>
194205 if (name.pos.contains(pos.pos))
195206 completionInfo(name.asInstanceOf [tpd.Tree ] :: Nil , /* inImport = */ true )
196207 else completionInfo(path, /* inImport = */ true )
197208
198209 case (imp : Import ) :: _ =>
199210 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 )
201212 case Some (sel) => completionInfo(sel.asInstanceOf [tpd.Tree ] :: Nil , /* inImport = */ true )
202213 }
203214
@@ -225,15 +236,15 @@ object Interactive {
225236 * classes.
226237 */
227238 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('$' ) &&
230241 ! sym.isPrimaryConstructor &&
231242 sym.sourceSymbol.exists &&
232243 (! 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 )) &&
234245 ! sym.is(allOf(Mutable , Accessor )) &&
235- (! termOnly || sym.isTerm) &&
236- (! typeOnly || sym.isType)
246+ (! info. termOnly || sym.isTerm) &&
247+ (! info. typeOnly || sym.isType)
237248
238249 def enter (sym : Symbol ) =
239250 if (include(sym)) completions.enter(sym)
@@ -311,7 +322,7 @@ object Interactive {
311322
312323 def getMemberCompletions (qual : Tree ): Unit = {
313324 addAccessibleMembers(qual.tpe)
314- if (! inImport) {
325+ if (! info. inImport) {
315326 // Implicit conversions do not kick in when importing
316327 implicitConversionTargets(qual)(ctx.fresh.setExploreTyperState())
317328 .foreach(addAccessibleMembers(_))
@@ -326,8 +337,8 @@ object Interactive {
326337 }
327338
328339 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)
331342 }
332343
333344 /** Possible completions of members of `prefix` which are accessible when called inside `boundary` */
0 commit comments