@@ -35,6 +35,8 @@ import dotty.tools.dotc.core.Constants
3535import dotty .tools .dotc .core .TypeOps
3636import dotty .tools .dotc .core .StdNames
3737
38+ import java .util .logging .Logger
39+ 3840/**
3941 * One of the results of a completion query.
4042 *
@@ -48,6 +50,8 @@ case class Completion(label: String, description: String, symbols: List[Symbol])
4850
4951object Completion :
5052
53+ private val logger = Logger .getLogger(this .getClass.getName)
54+ 5155 def scopeContext (pos : SourcePosition )(using Context ): CompletionResult =
5256 val tpdPath = Interactive .pathTo(ctx.compilationUnit.tpdTree, pos.span)
5357 val completionContext = Interactive .contextOfPath(tpdPath).withPhase(Phases .typerPhase)
@@ -601,12 +605,19 @@ object Completion:
601605 case _ : MethodOrPoly => tpe
602606 case _ => ExprType (tpe)
603607
608+ // Try added due to https://github.com/scalameta/metals/issues/7872
604609 def tryApplyingReceiverToExtension (termRef : TermRef ): Option [SingleDenotation ] =
605- ctx.typer.tryApplyingExtensionMethod(termRef, qual)
606- .map { tree =>
607- val tpe = asDefLikeType(tree.typeOpt.dealias)
608- termRef.denot.asSingleDenotation.mapInfo(_ => tpe)
609- }
610+ try
611+ ctx.typer.tryApplyingExtensionMethod(termRef, qual)
612+ .map { tree =>
613+ val tpe = asDefLikeType(tree.typeOpt.dealias)
614+ termRef.denot.asSingleDenotation.mapInfo(_ => tpe)
615+ }
616+ catch case NonFatal (ex) =>
617+ logger.warning(
618+ s " Exception when trying to apply extension method: \n ${ex.getMessage()}\n ${ex.getStackTrace().mkString(" \n " )}"
619+ )
620+ None
610621
611622 def extractMemberExtensionMethods (types : Seq [Type ]): Seq [(TermRef , TermName )] =
612623 object DenotWithMatchingName :
@@ -704,13 +715,17 @@ object Completion:
704715 * @param qual The argument to which the implicit conversion should be applied.
705716 * @return The set of types after `qual` implicit conversion.
706717 */
707- private def implicitConversionTargets (qual : tpd.Tree )(using Context ): Set [SearchSuccess ] = {
718+ private def implicitConversionTargets (qual : tpd.Tree )(using Context ): Set [SearchSuccess ] = try {
708719 val typer = ctx.typer
709720 val conversions = new typer.ImplicitSearch (defn.AnyType , qual, pos.span, Set .empty).allImplicits
710721
711722 interactiv.println(i " implicit conversion targets considered: ${conversions.toList}%, % " )
712723 conversions
713- }
724+ } catch case NonFatal (ex) =>
725+ logger.warning(
726+ s " Exception when searching for implicit conversions: \n ${ex.getMessage()}\n ${ex.getStackTrace().mkString(" \n " )}"
727+ )
728+ Set .empty
714729
715730 /** Filter for names that should appear when looking for completions. */
716731 private object completionsFilter extends NameFilter :
0 commit comments