@@ -71,10 +71,11 @@ object Completion:
71
71
mode : Mode ,
72
72
rawPrefix : String ,
73
73
tpdPath : List [tpd.Tree ],
74
- untpdPath : List [untpd.Tree ]
74
+ untpdPath : List [untpd.Tree ],
75
+ customMatcher : Option [Name => Boolean ] = None
75
76
)(using Context ): CompletionMap =
76
77
val adjustedPath = typeCheckExtensionConstructPath(untpdPath, tpdPath, pos)
77
- computeCompletions(pos, mode, rawPrefix, adjustedPath)
78
+ computeCompletions(pos, mode, rawPrefix, adjustedPath, customMatcher )
78
79
79
80
/**
80
81
* Inspect `path` to determine what kinds of symbols should be considered.
@@ -193,11 +194,12 @@ object Completion:
193
194
.flatten.getOrElse(tpdPath)
194
195
195
196
private def computeCompletions (
196
- pos : SourcePosition , mode : Mode , rawPrefix : String , adjustedPath : List [tpd.Tree ]
197
+ pos : SourcePosition , mode : Mode , rawPrefix : String , adjustedPath : List [tpd.Tree ], matches : Option [ Name => Boolean ]
197
198
)(using Context ): CompletionMap =
198
199
val hasBackTick = rawPrefix.headOption.contains('`' )
199
200
val prefix = if hasBackTick then rawPrefix.drop(1 ) else rawPrefix
200
- val completer = new Completer (mode, prefix, pos)
201
+ val matches0 = matches.getOrElse(_.startsWith(prefix))
202
+ val completer = new Completer (mode, pos, matches0)
201
203
202
204
val result = adjustedPath match
203
205
// Ignore synthetic select from `This` because in code it was `Ident`
@@ -209,7 +211,6 @@ object Completion:
209
211
case _ => completer.scopeCompletions
210
212
211
213
interactiv.println(i """ completion info with pos = $pos,
212
- | prefix = ${completer.prefix},
213
214
| term = ${completer.mode.is(Mode .Term )},
214
215
| type = ${completer.mode.is(Mode .Type )},
215
216
| scope = ${completer.mode.is(Mode .Scope )},
@@ -311,13 +312,13 @@ object Completion:
311
312
312
313
/** Computes code completions depending on the context in which completion is requested
313
314
* @param mode Should complete names of terms, types or both
314
- * @param prefix The prefix that all suggested completions should start with
315
315
* @param pos Cursor position where completion was requested
316
+ * @param matches Function taking name used to filter completions
316
317
*
317
318
* For the results of all `xyzCompletions` methods term names and type names are always treated as different keys in the same map
318
319
* and they never conflict with each other.
319
320
*/
320
- class Completer (val mode : Mode , val prefix : String , pos : SourcePosition ):
321
+ class Completer (val mode : Mode , pos : SourcePosition , matches : Name => Boolean ):
321
322
/** Completions for terms and types that are currently in scope:
322
323
* the members of the current class, local definitions and the symbols that have been imported,
323
324
* recursively adding completions from outer scopes.
@@ -524,7 +525,7 @@ object Completion:
524
525
// There are four possible ways for an extension method to be applicable
525
526
526
527
// 1. The extension method is visible under a simple name, by being defined or inherited or imported in a scope enclosing the reference.
527
- val termCompleter = new Completer (Mode .Term , prefix, pos )
528
+ val termCompleter = new Completer (Mode .Term , pos, matches )
528
529
val extMethodsInScope = termCompleter.scopeCompletions.toList.flatMap:
529
530
case (name, denots) => denots.collect:
530
531
case d : SymDenotation if d.isTerm && d.termRef.symbol.is(Extension ) => (d.termRef, name.asTermName)
@@ -556,7 +557,7 @@ object Completion:
556
557
* 2. satisfy [[Completion.isValidCompletionSymbol ]]
557
558
*/
558
559
private def include (denot : SingleDenotation , nameInScope : Name )(using Context ): Boolean =
559
- nameInScope.startsWith(prefix ) &&
560
+ matches(nameInScope ) &&
560
561
completionsFilter(NoType , nameInScope) &&
561
562
isValidCompletionSymbol(denot.symbol, mode)
562
563
@@ -605,7 +606,6 @@ object Completion:
605
606
private def implicitConversionTargets (qual : tpd.Tree )(using Context ): Set [SearchSuccess ] = {
606
607
val typer = ctx.typer
607
608
val conversions = new typer.ImplicitSearch (defn.AnyType , qual, pos.span).allImplicits
608
- conversions.map(_.tree.typeOpt)
609
609
610
610
interactiv.println(i " implicit conversion targets considered: ${conversions.toList}%, % " )
611
611
conversions
0 commit comments