@@ -184,12 +184,12 @@ object Completion:
184
184
val completions = adjustedPath match
185
185
// Ignore synthetic select from `This` because in code it was `Ident`
186
186
// See example in dotty.tools.languageserver.CompletionTest.syntheticThis
187
- case Select (qual @ This (_), _) :: _ if qual.span.isSynthetic => completer.scopeCompletions
188
- case Select (qual, _) :: _ if qual.tpe .hasSimpleKind => completer.selectionCompletions(qual)
189
- case Select (qual, _) :: _ => Map .empty
190
- case (tree : ImportOrExport ) :: _ => completer.directMemberCompletions(tree.expr)
191
- case (_ : untpd.ImportSelector ) :: Import (expr, _) :: _ => completer.directMemberCompletions(expr)
192
- case _ => completer.scopeCompletions
187
+ case Select (qual @ This (_), _) :: _ if qual.span.isSynthetic => completer.scopeCompletions
188
+ case Select (qual, _) :: _ if qual.typeOpt .hasSimpleKind => completer.selectionCompletions(qual)
189
+ case Select (qual, _) :: _ => Map .empty
190
+ case (tree : ImportOrExport ) :: _ => completer.directMemberCompletions(tree.expr)
191
+ case (_ : untpd.ImportSelector ) :: Import (expr, _) :: _ => completer.directMemberCompletions(expr)
192
+ case _ => completer.scopeCompletions
193
193
194
194
val describedCompletions = describeCompletions(completions)
195
195
val backtickedCompletions =
@@ -348,7 +348,7 @@ object Completion:
348
348
/** Widen only those types which are applied or are exactly nothing
349
349
*/
350
350
def widenQualifier (qual : Tree )(using Context ): Tree =
351
- qual.tpe .widenDealias match
351
+ qual.typeOpt .widenDealias match
352
352
case widenedType if widenedType.isExactlyNothing => qual.withType(widenedType)
353
353
case appliedType : AppliedType => qual.withType(appliedType)
354
354
case _ => qual
@@ -368,10 +368,10 @@ object Completion:
368
368
* These include inherited definitions but not members added by extensions or implicit conversions
369
369
*/
370
370
def directMemberCompletions (qual : Tree )(using Context ): CompletionMap =
371
- if qual.tpe .isExactlyNothing then
371
+ if qual.typeOpt .isExactlyNothing then
372
372
Map .empty
373
373
else
374
- accessibleMembers(qual.tpe ).groupByName
374
+ accessibleMembers(qual.typeOpt ).groupByName
375
375
376
376
/** Completions introduced by imports directly in this context.
377
377
* Completions from outer contexts are not included.
@@ -415,7 +415,7 @@ object Completion:
415
415
416
416
/** Completions from implicit conversions including old style extensions using implicit classes */
417
417
private def implicitConversionMemberCompletions (qual : Tree )(using Context ): CompletionMap =
418
- if qual.tpe .isExactlyNothing || qual.tpe .isNullType then
418
+ if qual.typeOpt .isExactlyNothing || qual.typeOpt .isNullType then
419
419
Map .empty
420
420
else
421
421
implicitConversionTargets(qual)(using ctx.fresh.setExploreTyperState())
@@ -432,7 +432,7 @@ object Completion:
432
432
def tryApplyingReceiverToExtension (termRef : TermRef ): Option [SingleDenotation ] =
433
433
ctx.typer.tryApplyingExtensionMethod(termRef, qual)
434
434
.map { tree =>
435
- val tpe = asDefLikeType(tree.tpe .dealias)
435
+ val tpe = asDefLikeType(tree.typeOpt .dealias)
436
436
termRef.denot.asSingleDenotation.mapInfo(_ => tpe)
437
437
}
438
438
@@ -453,16 +453,16 @@ object Completion:
453
453
454
454
// 1. The extension method is visible under a simple name, by being defined or inherited or imported in a scope enclosing the reference.
455
455
val termCompleter = new Completer (Mode .Term , prefix, pos)
456
- val extMethodsInScope = termCompleter.scopeCompletions.toList.flatMap {
457
- case (name, denots) => denots.collect { case d : SymDenotation if d.isTerm => (d.termRef, name.asTermName) }
458
- }
456
+ val extMethodsInScope = termCompleter.scopeCompletions.toList.flatMap:
457
+ case (name, denots) => denots.collect:
458
+ case d : SymDenotation if d.isTerm && d.termRef.symbol.is( Extension ) => (d.termRef, name.asTermName)
459
459
460
460
// 2. The extension method is a member of some given instance that is visible at the point of the reference.
461
461
val givensInScope = ctx.implicits.eligible(defn.AnyType ).map(_.implicitRef.underlyingRef)
462
462
val extMethodsFromGivensInScope = extractMemberExtensionMethods(givensInScope)
463
463
464
464
// 3. The reference is of the form r.m and the extension method is defined in the implicit scope of the type of r.
465
- val implicitScopeCompanions = ctx.run.nn.implicitScope(qual.tpe ).companionRefs.showAsList
465
+ val implicitScopeCompanions = ctx.run.nn.implicitScope(qual.typeOpt ).companionRefs.showAsList
466
466
val extMethodsFromImplicitScope = extractMemberExtensionMethods(implicitScopeCompanions)
467
467
468
468
// 4. The reference is of the form r.m and the extension method is defined in some given instance in the implicit scope of the type of r.
@@ -472,7 +472,7 @@ object Completion:
472
472
val availableExtMethods = extMethodsFromGivensInImplicitScope ++ extMethodsFromImplicitScope ++ extMethodsFromGivensInScope ++ extMethodsInScope
473
473
val extMethodsWithAppliedReceiver = availableExtMethods.flatMap {
474
474
case (termRef, termName) =>
475
- if termRef.symbol.is(ExtensionMethod ) && ! qual.tpe .isBottomType then
475
+ if termRef.symbol.is(ExtensionMethod ) && ! qual.typeOpt .isBottomType then
476
476
tryApplyingReceiverToExtension(termRef)
477
477
.map(denot => termName -> denot)
478
478
else None
@@ -551,21 +551,25 @@ object Completion:
551
551
* @param qual The argument to which the implicit conversion should be applied.
552
552
* @return The set of types after `qual` implicit conversion.
553
553
*/
554
- private def implicitConversionTargets (qual : Tree )(using Context ): Set [Type ] = {
554
+ private def implicitConversionTargets (qual : Tree )(using Context ): Set [Type ] =
555
555
val typer = ctx.typer
556
- val conversions = new typer.ImplicitSearch (defn.AnyType , qual, pos.span).allImplicits
557
- val targets = conversions.map(_.tree.tpe)
556
+ val targets = try {
557
+ val conversions = new typer.ImplicitSearch (defn.AnyType , qual, pos.span).allImplicits
558
+ conversions.map(_.tree.typeOpt)
559
+ } catch {
560
+ case _ =>
561
+ interactiv.println(i " implicit conversion targets failed: ${qual.show}" )
562
+ Set .empty
563
+ }
558
564
559
565
interactiv.println(i " implicit conversion targets considered: ${targets.toList}%, % " )
560
566
targets
561
- }
562
567
563
568
/** Filter for names that should appear when looking for completions. */
564
- private object completionsFilter extends NameFilter {
569
+ private object completionsFilter extends NameFilter :
565
570
def apply (pre : Type , name : Name )(using Context ): Boolean =
566
571
! name.isConstructorName && name.toTermName.info.kind == SimpleNameKind
567
572
def isStable = true
568
- }
569
573
570
574
extension (denotations : Seq [SingleDenotation ])
571
575
def groupByName (using Context ): CompletionMap = denotations.groupBy(_.name)
0 commit comments