@@ -184,12 +184,12 @@ object Completion:
184184 val completions = adjustedPath match
185185 // Ignore synthetic select from `This` because in code it was `Ident`
186186 // 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
193193
194194 val describedCompletions = describeCompletions(completions)
195195 val backtickedCompletions =
@@ -348,7 +348,7 @@ object Completion:
348348 /** Widen only those types which are applied or are exactly nothing
349349 */
350350 def widenQualifier (qual : Tree )(using Context ): Tree =
351- qual.tpe .widenDealias match
351+ qual.typeOpt .widenDealias match
352352 case widenedType if widenedType.isExactlyNothing => qual.withType(widenedType)
353353 case appliedType : AppliedType => qual.withType(appliedType)
354354 case _ => qual
@@ -368,10 +368,10 @@ object Completion:
368368 * These include inherited definitions but not members added by extensions or implicit conversions
369369 */
370370 def directMemberCompletions (qual : Tree )(using Context ): CompletionMap =
371- if qual.tpe .isExactlyNothing then
371+ if qual.typeOpt .isExactlyNothing then
372372 Map .empty
373373 else
374- accessibleMembers(qual.tpe ).groupByName
374+ accessibleMembers(qual.typeOpt ).groupByName
375375
376376 /** Completions introduced by imports directly in this context.
377377 * Completions from outer contexts are not included.
@@ -415,7 +415,7 @@ object Completion:
415415
416416 /** Completions from implicit conversions including old style extensions using implicit classes */
417417 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
419419 Map .empty
420420 else
421421 implicitConversionTargets(qual)(using ctx.fresh.setExploreTyperState())
@@ -432,7 +432,7 @@ object Completion:
432432 def tryApplyingReceiverToExtension (termRef : TermRef ): Option [SingleDenotation ] =
433433 ctx.typer.tryApplyingExtensionMethod(termRef, qual)
434434 .map { tree =>
435- val tpe = asDefLikeType(tree.tpe .dealias)
435+ val tpe = asDefLikeType(tree.typeOpt .dealias)
436436 termRef.denot.asSingleDenotation.mapInfo(_ => tpe)
437437 }
438438
@@ -453,16 +453,16 @@ object Completion:
453453
454454 // 1. The extension method is visible under a simple name, by being defined or inherited or imported in a scope enclosing the reference.
455455 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)
459459
460460 // 2. The extension method is a member of some given instance that is visible at the point of the reference.
461461 val givensInScope = ctx.implicits.eligible(defn.AnyType ).map(_.implicitRef.underlyingRef)
462462 val extMethodsFromGivensInScope = extractMemberExtensionMethods(givensInScope)
463463
464464 // 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
466466 val extMethodsFromImplicitScope = extractMemberExtensionMethods(implicitScopeCompanions)
467467
468468 // 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:
472472 val availableExtMethods = extMethodsFromGivensInImplicitScope ++ extMethodsFromImplicitScope ++ extMethodsFromGivensInScope ++ extMethodsInScope
473473 val extMethodsWithAppliedReceiver = availableExtMethods.flatMap {
474474 case (termRef, termName) =>
475- if termRef.symbol.is(ExtensionMethod ) && ! qual.tpe .isBottomType then
475+ if termRef.symbol.is(ExtensionMethod ) && ! qual.typeOpt .isBottomType then
476476 tryApplyingReceiverToExtension(termRef)
477477 .map(denot => termName -> denot)
478478 else None
@@ -551,21 +551,25 @@ object Completion:
551551 * @param qual The argument to which the implicit conversion should be applied.
552552 * @return The set of types after `qual` implicit conversion.
553553 */
554- private def implicitConversionTargets (qual : Tree )(using Context ): Set [Type ] = {
554+ private def implicitConversionTargets (qual : Tree )(using Context ): Set [Type ] =
555555 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+ }
558564
559565 interactiv.println(i " implicit conversion targets considered: ${targets.toList}%, % " )
560566 targets
561- }
562567
563568 /** Filter for names that should appear when looking for completions. */
564- private object completionsFilter extends NameFilter {
569+ private object completionsFilter extends NameFilter :
565570 def apply (pre : Type , name : Name )(using Context ): Boolean =
566571 ! name.isConstructorName && name.toTermName.info.kind == SimpleNameKind
567572 def isStable = true
568- }
569573
570574 extension (denotations : Seq [SingleDenotation ])
571575 def groupByName (using Context ): CompletionMap = denotations.groupBy(_.name)
0 commit comments