Skip to content

Commit 609a576

Browse files
authored
Merge pull request #13317 from KacperFKorban/scaladoc/fix-css
Fix displaying some signatures in scaladoc
2 parents 868906d + da43aa7 commit 609a576

File tree

8 files changed

+112
-41
lines changed

8 files changed

+112
-41
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package tests.hugetype
2+
3+
import compiletime._
4+
import compiletime.ops.int._
5+
import scala.annotation.experimental
6+
7+
/**
8+
* a particular group of people or things that share similar characteristics and form a smaller division of a larger set:
9+
* - There were so many different types of bread that I didn't know which to buy.
10+
* - What type of clothes does she wear?
11+
* - It was dark so I didn't notice what type of car it was.
12+
* - He's the type of man you could take home to your mother.
13+
* - He's very attractive, if you like the blond, athletic type.
14+
* - They sell dried flowers and baskets and that type of thing.
15+
* - We have a range of moisturizers for all different skin types.
16+
* - She was young and she was wearing student-type clothes, so I assumed she was studying here.
17+
* - He took me to a bar full of actor types trying to get noticed.
18+
*
19+
*/
20+
type Take[T <: Tuple, N <: Int] <: Tuple = N match {
21+
case 0 => EmptyTuple
22+
case S[n1] => T match {
23+
case EmptyTuple => EmptyTuple
24+
case x *: xs => x *: Take[xs, n1]
25+
}
26+
}
27+
28+
trait E:
29+
@experimental
30+
@deprecated
31+
protected implicit def same[A](a: A): A
32+
33+
trait XD extends E:
34+
/**
35+
* Some important information :o
36+
*
37+
* @param a any value of type forall a. a
38+
* @return Nothing, because I haven't implemented it yet ^^
39+
*/
40+
@experimental
41+
@deprecated
42+
protected override final implicit transparent inline abstract infix def same[A](a: A): A = a
43+
44+
trait Parent[X, A[_], B[_, _]]
45+
46+
trait HugeTrait[X] extends Parent[X, HugeTrait, Map]
47+
48+
trait EvenBiggerTrait[X, Y] extends Parent[X, Seq, EvenBiggerTrait]

scaladoc/resources/dotty_res/styles/scalastyle.css

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ th {
262262
padding-left: calc(1.015 * var(--side-width));
263263
padding-right: calc(0.15 * var(--side-width));
264264
box-sizing: border-box;
265+
text-decoration: none;
265266
}
266267

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

583584
.documentableElement .modifiers {
584585
display: table-cell;
585-
padding-right: 0.5em;
586586
min-width: 10em;
587587
max-width: 10em;
588588
width: 10em;
589589
overflow: hidden;
590-
direction: rtl;
590+
text-align: right;
591591
white-space: nowrap;
592+
text-overflow: ellipsis;
592593
text-indent: 0em;
594+
padding-right: 0.5em;
595+
}
596+
597+
.documentableElement.expand .modifiers {
598+
white-space: break-spaces;
599+
text-overflow: unset;
593600
}
594601

595602
.documentableElement .docs {
@@ -602,16 +609,15 @@ footer .mode {
602609
}
603610

604611
.kind {
605-
margin-left: 0.5em;
612+
font-weight: bold;
606613
}
607614

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

612619
.documentableElement.expand .modifiers {
613-
display: inline-table;
614-
min-width: 7em;
620+
display: table-cell;
615621
}
616622

617623
.documentableElement .signature {
@@ -622,14 +628,24 @@ footer .mode {
622628

623629
.signature.monospace {
624630
padding: 8px;
631+
display: flex;
632+
border-radius: 3px;
633+
}
634+
635+
.signature.monospace .modifiers {
636+
white-space: break-spaces;
625637
}
626638

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

631643
.expand .signature {
632-
display: inline;
644+
display: table-cell;
645+
}
646+
647+
.documentableFilter {
648+
border-radius: 3px;
633649
}
634650

635651
.documentableElement {
@@ -642,20 +658,15 @@ footer .mode {
642658
background: var(--documentable-bg);
643659
border-left: 0.25em solid transparent;
644660
margin: 0.5em 0;
661+
border-radius: 3px;
645662
}
646663

647664
.documentableElement>div {
648665
display: table;
649666
}
650667

651-
.expand.documentableElement>div {
652-
display: block;
653-
}
654-
655668
.expand.documentableElement>div.header {
656-
display: block;
657-
padding-left: 4.5em;
658-
text-indent: -4.5em;
669+
display: inline-table;
659670
}
660671

661672
.documentableElement>div .cover {
@@ -666,10 +677,6 @@ footer .mode {
666677
display: block;
667678
}
668679

669-
.expand .doc {
670-
margin-left: 6.5em;
671-
}
672-
673680
.doc code {
674681
padding: 0;
675682
}
@@ -684,6 +691,7 @@ footer .mode {
684691
}
685692
.documentableElement .annotations {
686693
color: var(--grey600);
694+
margin-left: 10em;
687695
display: none;
688696
}
689697

@@ -695,13 +703,17 @@ footer .mode {
695703
display: none;
696704
}
697705

706+
.documentableElement:hover .documentableAnchor:before {
707+
display: flex;
708+
}
709+
698710
.documentableAnchor:before {
699711
content: "\e901"; /* arrow down */
700712
font-family: "dotty-icons" !important;
701-
transform: rotate(45deg);
713+
transform: rotate(-45deg);
702714
font-size: 20px;
703715
color: var(--icon-color);
704-
display: flex;
716+
display: none;
705717
flex-direction: row;
706718
align-items: center;
707719
justify-content: center;

scaladoc/src/dotty/tools/scaladoc/api.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ enum Modifier(val name: String, val prefix: Boolean):
4040
case Erased extends Modifier("erased", true)
4141
case Opaque extends Modifier("opaque", true)
4242
case Open extends Modifier("open", true)
43+
case Transparent extends Modifier("transparent", true)
44+
case Infix extends Modifier("infix", true)
4345

4446
case class ExtensionTarget(name: String, typeParams: Seq[TypeParameter], argsLists: Seq[ParametersList], signature: Signature, dri: DRI, position: Long)
4547
case class ImplicitConversion(from: DRI, to: DRI)

scaladoc/src/dotty/tools/scaladoc/renderers/MemberRenderer.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,17 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
134134

135135
val rawBuilder = ScalaSignatureProvider.rawSignature(member, InlineSignatureBuilder())
136136
val inlineBuilder = rawBuilder.asInstanceOf[InlineSignatureBuilder]
137-
if inlineBuilder.preName.isEmpty then println(member)
138137
val kind :: modifiersRevered = inlineBuilder.preName
139138
val signature = inlineBuilder.names.reverse
140139
Seq(
141140
span(cls := "modifiers")(
142141
span(cls := "other-modifiers")(modifiersRevered.reverse.map(renderElement)),
142+
),
143+
div(cls := "signature")(
143144
span(cls := "kind")(renderElement(kind)),
145+
renderLink(member.name, member.dri, nameClasses),
146+
span(signature.map(renderElement))
144147
),
145-
renderLink(member.name, member.dri, nameClasses),
146-
span(cls := "signature")(signature.map(renderElement)),
147148
)
148149

149150
def memberIcon(member: Member) = member.kind match {

scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -603,20 +603,20 @@ trait ClassLikeSupport:
603603
graph: HierarchyGraph = HierarchyGraph.empty,
604604
deprecated: Option[Annotation] = None,
605605
) = Member(
606-
name = symbol.normalizedName,
607-
dri = symbol.dri,
608-
kind = kind,
609-
visibility = symbol.getVisibility(),
610-
modifiers = modifiers,
611-
annotations = symbol.getAnnotations(),
612-
signature = signature,
613-
sources = symbol.source,
614-
origin = origin,
615-
inheritedFrom = inheritedFrom,
616-
graph = graph,
617-
docs = symbol.documentation,
618-
deprecated = deprecated
619-
)
606+
name = symbol.normalizedName,
607+
dri = symbol.dri,
608+
kind = kind,
609+
visibility = symbol.getVisibility(),
610+
modifiers = modifiers,
611+
annotations = symbol.getAnnotations(),
612+
signature = signature,
613+
sources = symbol.source,
614+
origin = origin,
615+
inheritedFrom = inheritedFrom,
616+
graph = graph,
617+
docs = symbol.documentation,
618+
deprecated = deprecated
619+
)
620620

621621
object EvidenceOnlyParameterList
622622
type RegularParameterList = Map[String, TypeRepr]

scaladoc/src/dotty/tools/scaladoc/tasty/SymOps.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ object SymOps:
7070
case (None, None, (false, true, true)) => Visibility.Protected(ThisScope)
7171
case (None, None, (false, true, false)) => Visibility.Protected(implicitScope(sym.owner))
7272
case (None, None, (false, false, false)) => Visibility.Unrestricted
73+
case (None, None, (true, true, false)) => Visibility.Protected(ThisScope)
7374
case _ => throw new Exception(s"Visibility for symbol $sym cannot be determined")
7475

7576

@@ -83,6 +84,8 @@ object SymOps:
8384
Flags.Abstract -> Modifier.Abstract,
8485
Flags.Deferred -> Modifier.Deferred,
8586
Flags.Implicit -> Modifier.Implicit,
87+
Flags.Infix -> Modifier.Infix,
88+
Flags.Transparent -> Modifier.Transparent,
8689
Flags.Inline -> Modifier.Inline,
8790
Flags.Lazy -> Modifier.Lazy,
8891
Flags.Open -> Modifier.Open,

scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ trait TypesSupport:
8080
case _ => false
8181

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

253256
case MatchType(bond, sc, cases) =>
257+
val caseSpaces = " " * (indent + 2)
258+
val spaces = " " * (indent)
254259
val casesTexts = cases.flatMap {
255260
case MatchCase(from, to) =>
256-
texts(" case ") ++ inner(from) ++ texts(" => ") ++ inner(to) ++ texts("\n")
261+
texts(caseSpaces + "case ") ++ inner(from) ++ texts(" => ") ++ inner(to)(using indent = indent + 2) ++ texts("\n")
257262
case TypeLambda(_, _, MatchCase(from, to)) =>
258-
texts(" case ") ++ inner(from) ++ texts(" => ") ++ inner(to) ++ texts("\n")
263+
texts(caseSpaces + "case ") ++ inner(from) ++ texts(" => ") ++ inner(to)(using indent = indent + 2) ++ texts("\n")
259264
}
260-
inner(sc) ++ texts(" match {\n") ++ casesTexts ++ texts("}")
265+
inner(sc) ++ texts(" match {\n") ++ casesTexts ++ texts(spaces + "}")
261266

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

scaladoc/test/dotty/tools/scaladoc/signatures/SignatureTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ abstract class SignatureTest(
119119
val sigPrefix = elem.select(".header .signature").textNodes match
120120
case list if list.size > 0 && list.get(0).getWholeText().startsWith(" ") => " "
121121
case _ => ""
122-
val all = s"$annotations$other $kind $name$sigPrefix$signature".trim()
122+
val all = s"$annotations$other $sigPrefix$signature".trim()
123123
signatures += all
124124
}
125125

0 commit comments

Comments
 (0)