@@ -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)
@@ -591,12 +595,19 @@ object Completion:
591595        case  _ : MethodOrPoly  =>  tpe
592596        case  _ =>  ExprType (tpe)
593597
598+       //  Try added due to https://github.com/scalameta/metals/issues/7872
594599      def  tryApplyingReceiverToExtension (termRef : TermRef ):  Option [SingleDenotation ] = 
595-         ctx.typer.tryApplyingExtensionMethod(termRef, qual)
596-           .map { tree => 
597-             val  tpe  =  asDefLikeType(tree.typeOpt.dealias)
598-             termRef.denot.asSingleDenotation.mapInfo(_ =>  tpe)
599-           }
600+         try 
601+           ctx.typer.tryApplyingExtensionMethod(termRef, qual)
602+             .map { tree => 
603+              val  tpe  =  asDefLikeType(tree.typeOpt.dealias)
604+               termRef.denot.asSingleDenotation.mapInfo(_ =>  tpe)
605+             }
606+         catch  case  NonFatal (ex) => 
607+           logger.warning(
608+             s " Exception when trying to apply extension method: \n   ${ex.getMessage()}\n ${ex.getStackTrace().mkString(" \n "  )}" 
609+           )
610+           None 
600611
601612      def  extractMemberExtensionMethods (types : Seq [Type ]):  Seq [(TermRef , TermName )] = 
602613        object  DenotWithMatchingName : 
@@ -694,13 +705,17 @@ object Completion:
694705     * @param  qual  The argument to which the implicit conversion should be applied. 
695706     * @return  The set of types after `qual` implicit conversion. 
696707     */  
697-     private  def  implicitConversionTargets (qual : tpd.Tree )(using  Context ):  Set [SearchSuccess ] =  {
708+     private  def  implicitConversionTargets (qual : tpd.Tree )(using  Context ):  Set [SearchSuccess ] =  try   {
698709      val  typer  =  ctx.typer
699710      val  conversions  =  new  typer.ImplicitSearch (defn.AnyType , qual, pos.span, Set .empty).allImplicits
700711
701712      interactiv.println(i " implicit conversion targets considered:  ${conversions.toList}%, % " )
702713      conversions
703-     }
714+     } catch  case  NonFatal (ex) => 
715+       logger.warning(
716+         s " Exception when searching for implicit conversions: \n   ${ex.getMessage()}\n ${ex.getStackTrace().mkString(" \n "  )}" 
717+       )
718+       Set .empty
704719
705720    /**  Filter for names that should appear when looking for completions. */  
706721    private  object  completionsFilter  extends  NameFilter : 
0 commit comments