diff options
Diffstat (limited to 'doc-tool')
-rw-r--r-- | doc-tool/resources/_layouts/api-page.html | 2 | ||||
-rw-r--r-- | doc-tool/resources/css/api-page.css | 4 | ||||
-rw-r--r-- | doc-tool/src/dotty/tools/dottydoc/model/factories.scala | 111 | ||||
-rw-r--r-- | doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala | 7 | ||||
-rw-r--r-- | doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala | 16 |
5 files changed, 80 insertions, 60 deletions
diff --git a/doc-tool/resources/_layouts/api-page.html b/doc-tool/resources/_layouts/api-page.html index ed65c0651..a3d9008e3 100644 --- a/doc-tool/resources/_layouts/api-page.html +++ b/doc-tool/resources/_layouts/api-page.html @@ -38,7 +38,7 @@ extraCSS: <span class="member-kind"> {{ member.kind }} </span> - <span class="member-name"> + <span class="member-name {% if member.isImplicitlyAddedFrom != null %}implicitly-added{% endif %}"> {{ member.name }} </span> diff --git a/doc-tool/resources/css/api-page.css b/doc-tool/resources/css/api-page.css index 743596813..9b18b6f6a 100644 --- a/doc-tool/resources/css/api-page.css +++ b/doc-tool/resources/css/api-page.css @@ -55,6 +55,10 @@ div#entity-members > div.member > div.member-title > span.member-name { font-weight: 600; } +div#entity-members > div.member > div.member-title > span.member-name.implicitly-added { + color: #019875; +} + div#entity-members > div.member > div.member-title span.keyword { font-weight: 600; margin-right: 11px; diff --git a/doc-tool/src/dotty/tools/dottydoc/model/factories.scala b/doc-tool/src/dotty/tools/dottydoc/model/factories.scala index e47c683f3..8f1fad4a7 100644 --- a/doc-tool/src/dotty/tools/dottydoc/model/factories.scala +++ b/doc-tool/src/dotty/tools/dottydoc/model/factories.scala @@ -46,77 +46,82 @@ object factories { } def expandTpe(t: Type, params: List[Reference] = Nil): Reference = t match { - case tl: PolyType => - //FIXME: should be handled correctly - // example, in `Option`: - // - // {{{ - // def companion: GenericCompanion[collection.Iterable] - // }}} - // - // Becomes: def companion: [+X0] -> collection.Iterable[X0] - typeRef(tl.show + " (not handled)") - case AppliedType(tycon, args) => + case AppliedType(tycon, args) => { val cls = tycon.typeSymbol - if (tycon.isRepeatedParam) - expandTpe(args.head) - else if (defn.isFunctionClass(cls)) + + if (defn.isFunctionClass(cls)) FunctionReference(args.init.map(expandTpe(_, Nil)), expandTpe(args.last)) else if (defn.isTupleClass(cls)) TupleReference(args.map(expandTpe(_, Nil))) else { - val query = tycon.show - val name = query.split("\\.").last + val query = cls.showFullName + val name = cls.name.show typeRef(name, query, params = args.map(expandTpe(_, Nil))) } + } - case ref @ RefinedType(parent, rn, info) => - expandTpe(parent) //FIXME: will be a refined HK, aka class Foo[X] { def bar: List[X] } or similar - case ref @ HKApply(tycon, args) => - expandTpe(tycon, args.map(expandTpe(_, params))) - case TypeRef(_, n) => - val name = n.decode.toString.split("\\$").last - typeRef(name, params = params) - case ta: TypeAlias => - expandTpe(ta.alias.widenDealias) - case OrType(left, right) => - OrTypeReference(expandTpe(left), expandTpe(right)) - case AndType(left, right) => - AndTypeReference(expandTpe(left), expandTpe(right)) - case tb @ TypeBounds(lo, hi) => + case t: TypeRef => { + val cls = t.typeSymbol + typeRef(cls.name.show.split("\\$\\$").last, query = cls.showFullName, params = params) + } + + case TypeBounds(lo, hi) => BoundsReference(expandTpe(lo), expandTpe(hi)) - case AnnotatedType(tpe, _) => - expandTpe(tpe) + + case t: PolyParam => + typeRef(t.paramName.show, params = params) + case ExprType(tpe) => expandTpe(tpe) - case c: ConstantType => - ConstantReference(c.show) - case tt: ThisType => - expandTpe(tt.underlying) - case ci: ClassInfo => - val query = path(ci.typeSymbol).mkString(".") - typeRef(ci.cls.name.show, query = query) - case mt: MethodType => - expandTpe(mt.resultType) - case pp: PolyParam => - val paramName = pp.paramName.show - val name = - if (paramName.contains('$')) - paramName.split("\\$\\$").last - else paramName - - typeRef(name) - case tr: TermRef => + + case t: ThisType => + expandTpe(t.underlying) + + case AnnotatedType(t, _) => + expandTpe(t) + + case t: MethodType => + expandTpe(t.finalResultType) + + case t: TermRef => { /** A `TermRef` appears in the return type in e.g: * ``` * def id[T](t: T): t.type = t * ``` */ - val name = tr.show + val name = t.show if (!name.endsWith(".type")) - ctx.warning(s"unhandled return type found: $tr") + ctx.warning(s"unhandled return type found: $t") + + typeRef(name, query = t.typeSymbol.showFullName, params = params) + } + + case ci: ClassInfo => + typeRef(ci.cls.name.show, query = ci.typeSymbol.showFullName) + + case tl: PolyType => { + // FIXME: should be handled correctly + // example, in `Option`: + // + // ```scala + // def companion: GenericCompanion[collection.Iterable] + // ``` + // + // Becomes: def companion: [+X0] -> collection.Iterable[X0] + typeRef(tl.show + " (not handled)") + } - typeRef(name, params = params) + case OrType(left, right) => + OrTypeReference(expandTpe(left), expandTpe(right)) + + case AndType(left, right) => + AndTypeReference(expandTpe(left), expandTpe(right)) + + case c: ConstantType => + ConstantReference(c.show) + + case ref @ RefinedType(parent, rn, info) => + expandTpe(parent) //FIXME: will be a refined HK, aka class Foo[X] { def bar: List[X] } or similar } expandTpe(t) diff --git a/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala b/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala index 72fd8c2a5..92fd95d09 100644 --- a/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala +++ b/doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala @@ -135,7 +135,7 @@ case class Site(val root: JFile, val documentation: Map[String, Package]) extend /** Generate HTML for the API documentation */ def generateApiDocs(outDir: JFile = new JFile(root.getAbsolutePath + "/_site"))(implicit ctx: Context): this.type = createOutput(outDir) { - def genDoc(e: model.Entity) = { + def genDoc(e: model.Entity): Unit = { // Suffix is index.html for packages and therefore the additional depth // is increased by 1 val (suffix, offset) = @@ -150,11 +150,14 @@ case class Site(val root: JFile, val documentation: Map[String, Package]) extend val source = new ByteArrayInputStream(rendered.getBytes(StandardCharsets.UTF_8)) Files.copy(source, target, REPLACE_EXISTING) + + // Generate docs for nested objects/classes: + e.children.foreach(genDoc) } documentation.values.foreach { pkg => genDoc(pkg) - pkg.members.filterNot(_.kind == "package").map(genDoc) + pkg.members.filterNot(_.kind == "package").foreach(genDoc) } } diff --git a/doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala b/doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala index 52b18f70c..ad73ad008 100644 --- a/doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala +++ b/doc-tool/src/dotty/tools/dottydoc/util/MemberLookup.scala @@ -7,7 +7,6 @@ import dotc.core.Contexts.Context import dotc.core.Flags import dotc.core.Names._ import dotc.core.Symbols._ -import dotc.core.Types._ import dotc.core.Names._ import dotc.util.Positions._ import model.internal._ @@ -31,7 +30,13 @@ trait MemberLookup { .collect { case x if x.name == searchStr => x } .sortBy(_.path.last) .headOption - .fold(notFound)(e => LinkToEntity(e)) + .fold(notFound) { + case e: TypeAlias => + // TODO: will explode once type aliases are fixed + if (e.alias.isDefined) ??? + else notFound + case e => LinkToEntity(e) + } /** Looks for an entity down in the structure, if the search list is Nil, * the search stops @@ -44,7 +49,10 @@ trait MemberLookup { case x :: xs => ent .members - .collect { case e: Entity with Members if e.name == x => e } + .collect { + case e: Entity with Members if e.name == x => e + case e: Entity with Members if e.name == x.init && x.last == '$' => e + } .headOption .fold(notFound)(e => downwardLookup(e, xs)) } @@ -54,7 +62,7 @@ trait MemberLookup { */ def globalLookup: LinkTo = { def longestMatch(list: List[String]): List[String] = - if (list == Nil) Nil + if (list eq Nil) Nil else packages .get(list.mkString(".")) |