Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix displaying some signatures in scaladoc #13317

Merged
merged 8 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions scaladoc-testcases/src/tests/hugetype.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package tests.hugetype

import compiletime._
import compiletime.ops.int._
import scala.annotation.experimental

/**
* a particular group of people or things that share similar characteristics and form a smaller division of a larger set:
* - There were so many different types of bread that I didn't know which to buy.
* - What type of clothes does she wear?
* - It was dark so I didn't notice what type of car it was.
* - He's the type of man you could take home to your mother.
* - He's very attractive, if you like the blond, athletic type.
* - They sell dried flowers and baskets and that type of thing.
* - We have a range of moisturizers for all different skin types.
* - She was young and she was wearing student-type clothes, so I assumed she was studying here.
* - He took me to a bar full of actor types trying to get noticed.
*
*/
type Take[T <: Tuple, N <: Int] <: Tuple = N match {
case 0 => EmptyTuple
case S[n1] => T match {
case EmptyTuple => EmptyTuple
case x *: xs => x *: Take[xs, n1]
}
}

trait E:
@experimental
@deprecated
protected implicit def same[A](a: A): A

trait XD extends E:
/**
* Some important information :o
*
* @param a any value of type forall a. a
* @return Nothing, because I haven't implemented it yet ^^
*/
@experimental
@deprecated
protected override final implicit transparent inline abstract infix def same[A](a: A): A = a

trait Parent[X, A[_], B[_, _]]

trait HugeTrait[X] extends Parent[X, HugeTrait, Map]

trait EvenBiggerTrait[X, Y] extends Parent[X, Seq, EvenBiggerTrait]
50 changes: 31 additions & 19 deletions scaladoc/resources/dotty_res/styles/scalastyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ th {
padding-left: calc(1.015 * var(--side-width));
padding-right: calc(0.15 * var(--side-width));
box-sizing: border-box;
text-decoration: none;
}

#sideMenu2 a span:not(.micon) {
Expand Down Expand Up @@ -582,14 +583,20 @@ footer .mode {

.documentableElement .modifiers {
display: table-cell;
padding-right: 0.5em;
min-width: 10em;
max-width: 10em;
width: 10em;
overflow: hidden;
direction: rtl;
text-align: right;
white-space: nowrap;
text-overflow: ellipsis;
text-indent: 0em;
padding-right: 0.5em;
}

.documentableElement.expand .modifiers {
white-space: break-spaces;
text-overflow: unset;
}

.documentableElement .docs {
Expand All @@ -602,16 +609,15 @@ footer .mode {
}

.kind {
margin-left: 0.5em;
font-weight: bold;
}

.other-modifiers a, .other-modifiers a:visited, .other-modifiers span[data-unresolved-link] {
color: var(--link-sig-fg);
}

.documentableElement.expand .modifiers {
display: inline-table;
min-width: 7em;
display: table-cell;
}

.documentableElement .signature {
Expand All @@ -622,14 +628,24 @@ footer .mode {

.signature.monospace {
padding: 8px;
display: flex;
border-radius: 3px;
}

.signature.monospace .modifiers {
white-space: break-spaces;
}

.signature a, .signature a:visited, .signature span[data-unresolved-link] {
color: var(--link-sig-fg);
}

.expand .signature {
display: inline;
display: table-cell;
}

.documentableFilter {
border-radius: 3px;
}

.documentableElement {
Expand All @@ -642,20 +658,15 @@ footer .mode {
background: var(--documentable-bg);
border-left: 0.25em solid transparent;
margin: 0.5em 0;
border-radius: 3px;
}

.documentableElement>div {
display: table;
}

.expand.documentableElement>div {
display: block;
}

.expand.documentableElement>div.header {
display: block;
padding-left: 4.5em;
text-indent: -4.5em;
display: inline-table;
}

.documentableElement>div .cover {
Expand All @@ -666,10 +677,6 @@ footer .mode {
display: block;
}

.expand .doc {
margin-left: 6.5em;
}

.doc code {
padding: 0;
}
Expand All @@ -684,6 +691,7 @@ footer .mode {
}
.documentableElement .annotations {
color: var(--grey600);
margin-left: 10em;
display: none;
}

Expand All @@ -695,13 +703,17 @@ footer .mode {
display: none;
}

.documentableElement:hover .documentableAnchor:before {
display: flex;
}

.documentableAnchor:before {
content: "\e901"; /* arrow down */
font-family: "dotty-icons" !important;
transform: rotate(45deg);
transform: rotate(-45deg);
font-size: 20px;
color: var(--icon-color);
display: flex;
display: none;
flex-direction: row;
align-items: center;
justify-content: center;
Expand Down
2 changes: 2 additions & 0 deletions scaladoc/src/dotty/tools/scaladoc/api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ enum Modifier(val name: String, val prefix: Boolean):
case Erased extends Modifier("erased", true)
case Opaque extends Modifier("opaque", true)
case Open extends Modifier("open", true)
case Transparent extends Modifier("transparent", true)
case Infix extends Modifier("infix", true)

case class ExtensionTarget(name: String, typeParams: Seq[TypeParameter], argsLists: Seq[ParametersList], signature: Signature, dri: DRI, position: Long)
case class ImplicitConversion(from: DRI, to: DRI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext

val rawBuilder = ScalaSignatureProvider.rawSignature(member, InlineSignatureBuilder())
val inlineBuilder = rawBuilder.asInstanceOf[InlineSignatureBuilder]
if inlineBuilder.preName.isEmpty then println(member)
val kind :: modifiersRevered = inlineBuilder.preName
val signature = inlineBuilder.names.reverse
Seq(
span(cls := "modifiers")(
span(cls := "other-modifiers")(modifiersRevered.reverse.map(renderElement)),
),
div(cls := "signature")(
span(cls := "kind")(renderElement(kind)),
renderLink(member.name, member.dri, nameClasses),
span(signature.map(renderElement))
),
renderLink(member.name, member.dri, nameClasses),
span(cls := "signature")(signature.map(renderElement)),
)

def memberIcon(member: Member) = member.kind match {
Expand Down
28 changes: 14 additions & 14 deletions scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -603,20 +603,20 @@ trait ClassLikeSupport:
graph: HierarchyGraph = HierarchyGraph.empty,
deprecated: Option[Annotation] = None,
) = Member(
name = symbol.normalizedName,
dri = symbol.dri,
kind = kind,
visibility = symbol.getVisibility(),
modifiers = modifiers,
annotations = symbol.getAnnotations(),
signature = signature,
sources = symbol.source,
origin = origin,
inheritedFrom = inheritedFrom,
graph = graph,
docs = symbol.documentation,
deprecated = deprecated
)
name = symbol.normalizedName,
dri = symbol.dri,
kind = kind,
visibility = symbol.getVisibility(),
modifiers = modifiers,
annotations = symbol.getAnnotations(),
signature = signature,
sources = symbol.source,
origin = origin,
inheritedFrom = inheritedFrom,
graph = graph,
docs = symbol.documentation,
deprecated = deprecated
)

object EvidenceOnlyParameterList
type RegularParameterList = Map[String, TypeRepr]
Expand Down
3 changes: 3 additions & 0 deletions scaladoc/src/dotty/tools/scaladoc/tasty/SymOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ object SymOps:
case (None, None, (false, true, true)) => Visibility.Protected(ThisScope)
case (None, None, (false, true, false)) => Visibility.Protected(implicitScope(sym.owner))
case (None, None, (false, false, false)) => Visibility.Unrestricted
case (None, None, (true, true, false)) => Visibility.Protected(ThisScope)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add a comment to this so people won't be confused

case _ => throw new Exception(s"Visibility for symbol $sym cannot be determined")


Expand All @@ -83,6 +84,8 @@ object SymOps:
Flags.Abstract -> Modifier.Abstract,
Flags.Deferred -> Modifier.Deferred,
Flags.Implicit -> Modifier.Implicit,
Flags.Infix -> Modifier.Infix,
Flags.Transparent -> Modifier.Transparent,
Flags.Inline -> Modifier.Inline,
Flags.Lazy -> Modifier.Lazy,
Flags.Open -> Modifier.Open,
Expand Down
13 changes: 9 additions & 4 deletions scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ trait TypesSupport:
case _ => false

// TODO #23 add support for all types signatures that makes sense
private def inner(using Quotes)(tp: reflect.TypeRepr): DocSignature =
private def inner(using Quotes)(tp: reflect.TypeRepr)(using indent: Int = 0): DocSignature =
import reflect._
def noSupported(name: String): DocSignature =
println(s"WARN: Unsupported type: $name: ${tp.show}")
Expand All @@ -99,6 +99,9 @@ trait TypesSupport:
inner(tpe) :+ text("*")
case AnnotatedType(tpe, _) =>
inner(tpe)
case tl @ TypeLambda(params, paramBounds, resType@AppliedType(tpe, args))
if paramBounds.map(inner).forall(_.isEmpty) && params.zip(args.map(inner)).forall(List(_) == _) =>
inner(tpe)
case tl @ TypeLambda(params, paramBounds, resType) =>
texts("[") ++ commas(params.zip(paramBounds).map { (name, typ) =>
val normalizedName = if name.matches("_\\$\\d*") then "_" else name
Expand Down Expand Up @@ -251,13 +254,15 @@ trait TypesSupport:
case NoPrefix() => Nil

case MatchType(bond, sc, cases) =>
val caseSpaces = " " * (indent + 2)
val spaces = " " * (indent)
val casesTexts = cases.flatMap {
case MatchCase(from, to) =>
texts(" case ") ++ inner(from) ++ texts(" => ") ++ inner(to) ++ texts("\n")
texts(caseSpaces + "case ") ++ inner(from) ++ texts(" => ") ++ inner(to)(using indent = indent + 2) ++ texts("\n")
case TypeLambda(_, _, MatchCase(from, to)) =>
texts(" case ") ++ inner(from) ++ texts(" => ") ++ inner(to) ++ texts("\n")
texts(caseSpaces + "case ") ++ inner(from) ++ texts(" => ") ++ inner(to)(using indent = indent + 2) ++ texts("\n")
}
inner(sc) ++ texts(" match {\n") ++ casesTexts ++ texts("}")
inner(sc) ++ texts(" match {\n") ++ casesTexts ++ texts(spaces + "}")

case ParamRef(TypeLambda(names, _, _), i) => texts(names.apply(i))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ abstract class SignatureTest(
val sigPrefix = elem.select(".header .signature").textNodes match
case list if list.size > 0 && list.get(0).getWholeText().startsWith(" ") => " "
case _ => ""
val all = s"$annotations$other $kind $name$sigPrefix$signature".trim()
val all = s"$annotations$other $sigPrefix$signature".trim()
signatures += all
}

Expand Down