Skip to content

Commit 9a581bc

Browse files
committed
Improve member lookup
1 parent 72720f0 commit 9a581bc

File tree

5 files changed

+80
-60
lines changed

5 files changed

+80
-60
lines changed

doc-tool/resources/_layouts/api-page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ <h1 class="section">Members</h1>
3838
<span class="member-kind">
3939
{{ member.kind }}
4040
</span>
41-
<span class="member-name">
41+
<span class="member-name {% if member.isImplicitlyAddedFrom != null %}implicitly-added{% endif %}">
4242
{{ member.name }}
4343
</span>
4444

doc-tool/resources/css/api-page.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ div#entity-members > div.member > div.member-title > span.member-name {
5555
font-weight: 600;
5656
}
5757

58+
div#entity-members > div.member > div.member-title > span.member-name.implicitly-added {
59+
color: #019875;
60+
}
61+
5862
div#entity-members > div.member > div.member-title span.keyword {
5963
font-weight: 600;
6064
margin-right: 11px;

doc-tool/src/dotty/tools/dottydoc/model/factories.scala

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -46,77 +46,82 @@ object factories {
4646
}
4747

4848
def expandTpe(t: Type, params: List[Reference] = Nil): Reference = t match {
49-
case tl: PolyType =>
50-
//FIXME: should be handled correctly
51-
// example, in `Option`:
52-
//
53-
// {{{
54-
// def companion: GenericCompanion[collection.Iterable]
55-
// }}}
56-
//
57-
// Becomes: def companion: [+X0] -> collection.Iterable[X0]
58-
typeRef(tl.show + " (not handled)")
59-
case AppliedType(tycon, args) =>
49+
case AppliedType(tycon, args) => {
6050
val cls = tycon.typeSymbol
61-
if (tycon.isRepeatedParam)
62-
expandTpe(args.head)
63-
else if (defn.isFunctionClass(cls))
51+
52+
if (defn.isFunctionClass(cls))
6453
FunctionReference(args.init.map(expandTpe(_, Nil)), expandTpe(args.last))
6554
else if (defn.isTupleClass(cls))
6655
TupleReference(args.map(expandTpe(_, Nil)))
6756
else {
68-
val query = tycon.show
69-
val name = query.split("\\.").last
57+
val query = cls.showFullName
58+
val name = cls.name.show
7059
typeRef(name, query, params = args.map(expandTpe(_, Nil)))
7160
}
61+
}
7262

73-
case ref @ RefinedType(parent, rn, info) =>
74-
expandTpe(parent) //FIXME: will be a refined HK, aka class Foo[X] { def bar: List[X] } or similar
75-
case ref @ HKApply(tycon, args) =>
76-
expandTpe(tycon, args.map(expandTpe(_, params)))
77-
case TypeRef(_, n) =>
78-
val name = n.decode.toString.split("\\$").last
79-
typeRef(name, params = params)
80-
case ta: TypeAlias =>
81-
expandTpe(ta.alias.widenDealias)
82-
case OrType(left, right) =>
83-
OrTypeReference(expandTpe(left), expandTpe(right))
84-
case AndType(left, right) =>
85-
AndTypeReference(expandTpe(left), expandTpe(right))
86-
case tb @ TypeBounds(lo, hi) =>
63+
case t: TypeRef => {
64+
val cls = t.typeSymbol
65+
typeRef(cls.name.show.split("\\$\\$").last, query = cls.showFullName, params = params)
66+
}
67+
68+
case TypeBounds(lo, hi) =>
8769
BoundsReference(expandTpe(lo), expandTpe(hi))
88-
case AnnotatedType(tpe, _) =>
89-
expandTpe(tpe)
70+
71+
case t: PolyParam =>
72+
typeRef(t.paramName.show, params = params)
73+
9074
case ExprType(tpe) =>
9175
expandTpe(tpe)
92-
case c: ConstantType =>
93-
ConstantReference(c.show)
94-
case tt: ThisType =>
95-
expandTpe(tt.underlying)
96-
case ci: ClassInfo =>
97-
val query = path(ci.typeSymbol).mkString(".")
98-
typeRef(ci.cls.name.show, query = query)
99-
case mt: MethodType =>
100-
expandTpe(mt.resultType)
101-
case pp: PolyParam =>
102-
val paramName = pp.paramName.show
103-
val name =
104-
if (paramName.contains('$'))
105-
paramName.split("\\$\\$").last
106-
else paramName
107-
108-
typeRef(name)
109-
case tr: TermRef =>
76+
77+
case t: ThisType =>
78+
expandTpe(t.underlying)
79+
80+
case AnnotatedType(t, _) =>
81+
expandTpe(t)
82+
83+
case t: MethodType =>
84+
expandTpe(t.finalResultType)
85+
86+
case t: TermRef => {
11087
/** A `TermRef` appears in the return type in e.g:
11188
* ```
11289
* def id[T](t: T): t.type = t
11390
* ```
11491
*/
115-
val name = tr.show
92+
val name = t.show
11693
if (!name.endsWith(".type"))
117-
ctx.warning(s"unhandled return type found: $tr")
94+
ctx.warning(s"unhandled return type found: $t")
95+
96+
typeRef(name, query = t.typeSymbol.showFullName, params = params)
97+
}
98+
99+
case ci: ClassInfo =>
100+
typeRef(ci.cls.name.show, query = ci.typeSymbol.showFullName)
101+
102+
case tl: PolyType => {
103+
// FIXME: should be handled correctly
104+
// example, in `Option`:
105+
//
106+
// ```scala
107+
// def companion: GenericCompanion[collection.Iterable]
108+
// ```
109+
//
110+
// Becomes: def companion: [+X0] -> collection.Iterable[X0]
111+
typeRef(tl.show + " (not handled)")
112+
}
118113

119-
typeRef(name, params = params)
114+
case OrType(left, right) =>
115+
OrTypeReference(expandTpe(left), expandTpe(right))
116+
117+
case AndType(left, right) =>
118+
AndTypeReference(expandTpe(left), expandTpe(right))
119+
120+
case c: ConstantType =>
121+
ConstantReference(c.show)
122+
123+
case ref @ RefinedType(parent, rn, info) =>
124+
expandTpe(parent) //FIXME: will be a refined HK, aka class Foo[X] { def bar: List[X] } or similar
120125
}
121126

122127
expandTpe(t)

doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ case class Site(val root: JFile, val documentation: Map[String, Package]) extend
135135
/** Generate HTML for the API documentation */
136136
def generateApiDocs(outDir: JFile = new JFile(root.getAbsolutePath + "/_site"))(implicit ctx: Context): this.type =
137137
createOutput(outDir) {
138-
def genDoc(e: model.Entity) = {
138+
def genDoc(e: model.Entity): Unit = {
139139
// Suffix is index.html for packages and therefore the additional depth
140140
// is increased by 1
141141
val (suffix, offset) =
@@ -150,11 +150,14 @@ case class Site(val root: JFile, val documentation: Map[String, Package]) extend
150150
val source = new ByteArrayInputStream(rendered.getBytes(StandardCharsets.UTF_8))
151151

152152
Files.copy(source, target, REPLACE_EXISTING)
153+
154+
// Generate docs for nested objects/classes:
155+
e.children.foreach(genDoc)
153156
}
154157

155158
documentation.values.foreach { pkg =>
156159
genDoc(pkg)
157-
pkg.members.filterNot(_.kind == "package").map(genDoc)
160+
pkg.members.filterNot(_.kind == "package").foreach(genDoc)
158161
}
159162
}
160163

doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import dotc.core.Contexts.Context
77
import dotc.core.Flags
88
import dotc.core.Names._
99
import dotc.core.Symbols._
10-
import dotc.core.Types._
1110
import dotc.core.Names._
1211
import dotc.util.Positions._
1312
import model.internal._
@@ -31,7 +30,13 @@ trait MemberLookup {
3130
.collect { case x if x.name == searchStr => x }
3231
.sortBy(_.path.last)
3332
.headOption
34-
.fold(notFound)(e => LinkToEntity(e))
33+
.fold(notFound) {
34+
case e: TypeAlias =>
35+
// TODO: will explode once type aliases are fixed
36+
if (e.alias.isDefined) ???
37+
else notFound
38+
case e => LinkToEntity(e)
39+
}
3540

3641
/** Looks for an entity down in the structure, if the search list is Nil,
3742
* the search stops
@@ -44,7 +49,10 @@ trait MemberLookup {
4449
case x :: xs =>
4550
ent
4651
.members
47-
.collect { case e: Entity with Members if e.name == x => e }
52+
.collect {
53+
case e: Entity with Members if e.name == x => e
54+
case e: Entity with Members if e.name == x.init && x.last == '$' => e
55+
}
4856
.headOption
4957
.fold(notFound)(e => downwardLookup(e, xs))
5058
}
@@ -54,7 +62,7 @@ trait MemberLookup {
5462
*/
5563
def globalLookup: LinkTo = {
5664
def longestMatch(list: List[String]): List[String] =
57-
if (list == Nil) Nil
65+
if (list eq Nil) Nil
5866
else
5967
packages
6068
.get(list.mkString("."))

0 commit comments

Comments
 (0)