<commit_before>package dotty.tools.dotc.util

import dotty.tools.dotc.ast.Trees._
import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Constants.Constant
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Denotations.SingleDenotation
import dotty.tools.dotc.core.Flags.Implicit
import dotty.tools.dotc.core.Names.TermName
import dotty.tools.dotc.util.Spans.Span
import dotty.tools.dotc.core.Types.{ErrorType, MethodType, PolyType}
import dotty.tools.dotc.reporting.diagnostic.messages

import scala.collection.JavaConverters._

object Signatures {

  /**
   * Represent a method signature.
   *
   * @param name       The name of the method
   * @param tparams    The type parameters and their bounds
   * @param paramss    The parameter lists of this method
   * @param returnType The return type of this method, if this is not a constructor.
   * @param doc        The documentation for this method.
   */
  case class Signature(name: String, tparams: List[String], paramss: List[List[Param]], returnType: Option[String], doc: Option[String] = None) {
  }

  /**
   * Represent a method's parameter.
   *
   * @param name       The name of the parameter
   * @param tpe        The type of the parameter
   * @param doc        The documentation of this parameter
   * @param isImplicit Is this parameter implicit?
   */
  case class Param(name: String, tpe: String, doc: Option[String] = None, isImplicit: Boolean = false) {
    def show: String =
      s"$name: $tpe"
  }

  /**
   * Extract (current parameter index, function index, functions) out of a method call.
   *
   * @param path The path to the function application
   * @param span The position of the cursor
   * @return A triple containing the index of the parameter being edited, the index of the function
   *         being called, the list of overloads of this function).
   */
  def callInfo(path: List[tpd.Tree], span: Span)(implicit ctx: Context): (Int, Int, List[SingleDenotation]) = {
    path match {
      case Apply(fun, params) :: _ =>
        val alreadyAppliedCount = Signatures.countParams(fun)
        val paramIndex = params.indexWhere(_.span.contains(span)) match {
          case -1 => (params.length - 1 max 0) + alreadyAppliedCount
          case n => n + alreadyAppliedCount
        }

        val (alternativeIndex, alternatives) = fun.tpe match {
          case err: ErrorType =>
            val (alternativeIndex, alternatives) = alternativesFromError(err, params)
            (alternativeIndex, alternatives)

          case _ =>
            val funSymbol = fun.symbol
            val alternatives = funSymbol.owner.info.member(funSymbol.name).alternatives
            val alternativeIndex = alternatives.indexOf(funSymbol.denot) max 0
            (alternativeIndex, alternatives)
        }

        (paramIndex, alternativeIndex, alternatives)

      case _ =>
        (0, 0, Nil)
    }
  }

  def toSignature(denot: SingleDenotation)(implicit ctx: Context): Option[Signature] = {
    val symbol = denot.symbol
    val docComment = ParsedComment.docOf(symbol)
    val classTree = symbol.topLevelClass.asClass.rootTree

    def toParamss(tp: MethodType)(implicit ctx: Context): List[List[Param]] = {
      val rest = tp.resType match {
        case res: MethodType =>
          // Hide parameter lists consisting only of CanBuildFrom or DummyImplicit,
          // we can remove the CanBuildFrom special-case once we switch to the 2.13 standard library.
          if (res.resultType.isParameterless &&
              res.isImplicitMethod &&
              res.paramInfos.forall(info =>
                info.classSymbol.fullName.toString == "scala.collection.generic.CanBuildFrom" ||
                info.classSymbol.derivesFrom(ctx.definitions.DummyImplicitClass)))
            Nil
          else
            toParamss(res)
        case _ =>
          Nil
      }
      val params = tp.paramNames.zip(tp.paramInfos).map { case (name, info) =>
        Signatures.Param(name.show,
          info.widenTermRefExpr.show,
          docComment.flatMap(_.paramDoc(name)),
          isImplicit = tp.isImplicitMethod)
      }

      params :: rest
    }

    denot.info.stripPoly match {
      case tpe: MethodType =>
        val paramss = toParamss(tpe)
        val typeParams = denot.info match {
          case poly: PolyType =>
            poly.paramNames.zip(poly.paramInfos).map { case (x, y) => x.show + y.show }<commit_msg>Remove hiding of CanBuildFrom params from the IDE/REPL<commit_after>package dotty.tools.dotc.util

import dotty.tools.dotc.ast.Trees._
import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Constants.Constant
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Denotations.SingleDenotation
import dotty.tools.dotc.core.Flags.Implicit
import dotty.tools.dotc.core.Names.TermName
import dotty.tools.dotc.util.Spans.Span
import dotty.tools.dotc.core.Types.{ErrorType, MethodType, PolyType}
import dotty.tools.dotc.reporting.diagnostic.messages

import scala.collection.JavaConverters._

object Signatures {

  /**
   * Represent a method signature.
   *
   * @param name       The name of the method
   * @param tparams    The type parameters and their bounds
   * @param paramss    The parameter lists of this method
   * @param returnType The return type of this method, if this is not a constructor.
   * @param doc        The documentation for this method.
   */
  case class Signature(name: String, tparams: List[String], paramss: List[List[Param]], returnType: Option[String], doc: Option[String] = None) {
  }

  /**
   * Represent a method's parameter.
   *
   * @param name       The name of the parameter
   * @param tpe        The type of the parameter
   * @param doc        The documentation of this parameter
   * @param isImplicit Is this parameter implicit?
   */
  case class Param(name: String, tpe: String, doc: Option[String] = None, isImplicit: Boolean = false) {
    def show: String =
      s"$name: $tpe"
  }

  /**
   * Extract (current parameter index, function index, functions) out of a method call.
   *
   * @param path The path to the function application
   * @param span The position of the cursor
   * @return A triple containing the index of the parameter being edited, the index of the function
   *         being called, the list of overloads of this function).
   */
  def callInfo(path: List[tpd.Tree], span: Span)(implicit ctx: Context): (Int, Int, List[SingleDenotation]) = {
    path match {
      case Apply(fun, params) :: _ =>
        val alreadyAppliedCount = Signatures.countParams(fun)
        val paramIndex = params.indexWhere(_.span.contains(span)) match {
          case -1 => (params.length - 1 max 0) + alreadyAppliedCount
          case n => n + alreadyAppliedCount
        }

        val (alternativeIndex, alternatives) = fun.tpe match {
          case err: ErrorType =>
            val (alternativeIndex, alternatives) = alternativesFromError(err, params)
            (alternativeIndex, alternatives)

          case _ =>
            val funSymbol = fun.symbol
            val alternatives = funSymbol.owner.info.member(funSymbol.name).alternatives
            val alternativeIndex = alternatives.indexOf(funSymbol.denot) max 0
            (alternativeIndex, alternatives)
        }

        (paramIndex, alternativeIndex, alternatives)

      case _ =>
        (0, 0, Nil)
    }
  }

  def toSignature(denot: SingleDenotation)(implicit ctx: Context): Option[Signature] = {
    val symbol = denot.symbol
    val docComment = ParsedComment.docOf(symbol)
    val classTree = symbol.topLevelClass.asClass.rootTree

    def toParamss(tp: MethodType)(implicit ctx: Context): List[List[Param]] = {
      val rest = tp.resType match {
        case res: MethodType =>
          // Hide parameter lists consisting only of DummyImplicit,
          if (res.resultType.isParameterless &&
              res.isImplicitMethod &&
              res.paramInfos.forall(info =>
                info.classSymbol.derivesFrom(ctx.definitions.DummyImplicitClass)))
            Nil
          else
            toParamss(res)
        case _ =>
          Nil
      }
      val params = tp.paramNames.zip(tp.paramInfos).map { case (name, info) =>
        Signatures.Param(name.show,
          info.widenTermRefExpr.show,
          docComment.flatMap(_.paramDoc(name)),
          isImplicit = tp.isImplicitMethod)
      }

      params :: rest
    }

    denot.info.stripPoly match {
      case tpe: MethodType =>
        val paramss = toParamss(tpe)
        val typeParams = denot.info match {
          case poly: PolyType =>
            poly.paramNames.zip(poly.paramInfos).map { case (x, y) => x.show + y.show }
{'fraction_non_alphanumeric': 0.09618916437098256, 'fraction_numerical': 0.001721763085399449, 'mean_word_length': 2.6532494758909855, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '366522', 'n_tokens_mistral': 2536, 'n_tokens_neox': 2486, 'n_words': 699}