-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add dottydoc #1453
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
Merged
Merged
Add dottydoc #1453
Changes from all commits
Commits
Show all changes
100 commits
Select commit
Hold shift + click to select a range
8d8d87b
Add project and impl for initial barebones dottydoc
felixmulder 1b20568
Port cooking of strings from NSC
felixmulder 9d4df20
Add module member lookup
felixmulder 6bd4969
Fix compilation for multiple sources
felixmulder 36e63e8
Add summary comment, cleanup
felixmulder fb6c152
Add command alias for dottydoc
felixmulder 980a662
Minify css
felixmulder 02a12f9
Improve layout with search and replace confusing Packages title
felixmulder 2de658d
Add the scaladoc CLI args that make sense for dottydoc
felixmulder 887759e
Add recursive CLI args, move other doc args
felixmulder 46ac1bf
Fix package list links
felixmulder 32b4a9c
Add initial return values to members - to be updated
felixmulder b480bd1
Fix packages not ending up in `packages` map in Phases.scala
felixmulder cbc05e0
Move dynamically generated content to JVM side
felixmulder 80a9077
Move member rendering back to client (for event listeners)
felixmulder db659dc
Split implementation to internal mutable and external interface
felixmulder 0fb1058
Filter out companion objects from package-view
felixmulder 86f816d
Add companions to package view w ability to choose between them
felixmulder 53fc2c0
Adjust font configuration for finalized package view
felixmulder cb42a04
Filter out ProductX when X > 3 in package view
felixmulder 80b027f
Break out commentCache to CommentParser
felixmulder 60b5dc3
Better prints while documenting packages
felixmulder 5c5d54a
Parse comments only from root packages (which contain all entities su…
felixmulder b4622aa
Fix root-package finding in comment-parser
felixmulder 29cf43b
Add JUnit test structure for testing the DocPhase
felixmulder 0020302
Add test for checking if Array has documentation after compiling std lib
felixmulder bc594c8
Add test for simple comment
felixmulder 8e39b71
Fix repeated traversal of packages when generating docs (5x speedup)
felixmulder 07e4ae2
Replace "$plus" with "+" in webview
felixmulder 3ecc86c
Fix linking (do not remove parent linking!)
felixmulder 73bfb73
Cosmetic updates
felixmulder cb4d93c
Filter out `AnyValCompanion` trait
felixmulder 2010a93
Move name filtering to AST build in Phase.scala
felixmulder f084357
Add implicit method `flat` to `Entity`
felixmulder 0bfdc91
Fix #7, "immutable" package mistaken for "Immutable" trait
felixmulder bcc7585
Add setting for output dir
felixmulder 926a81c
Add option `-Ydoc-output` for specifying output dir
felixmulder 59055f2
Add basic member-lookup for result types
felixmulder 23465a3
Improve return value filtering
felixmulder 4b99e29
Change package serialization to go straight to JSON
felixmulder 79133f9
Add interface for interacting with serialized case classes on frontend
felixmulder dccfb5b
Remove parent from fields since it is not serialized
felixmulder 756861e
Add first steps to implementing search
felixmulder a099344
Add basic implementation of toplevel entity search
felixmulder 0912727
Add type parameters to rendered entity
felixmulder 34590e7
Add parameter-lists (text-only)
felixmulder ffcf17a
Change function definition to be span based for better granularity
felixmulder 8294dd0
Add type parameters to classes
felixmulder 76bbb8d
Add supertypes to class, cc, obj and trait
felixmulder 82752b2
Fix value classes not being documented
felixmulder fdb82c9
Remove `filteredName` method in favor for `decode`
felixmulder c6a7446
Implement structure allowing lookup of higher-kinded types
felixmulder cedbb78
Complete proper structure for return types
felixmulder a727637
Fix proper structure for paramlist links (clientside)
felixmulder d451f90
Add implicitly added methods to entity documentation
felixmulder f1c88d7
Add implicitly added values as well
felixmulder 76413f0
Cleanup return types and type parameters from dollar signs
felixmulder 81a86be
Materialize parameter list references
felixmulder c80af6a
Introduce DocMiniPhase concept, fused phases
felixmulder 7fbda93
Rename AddImplicitsPhase to DocImplicitsPhase
felixmulder 8615072
Rename `XTypeLinkers` to `LinkXTypes` - because the amount of linker …
felixmulder 8e5159f
Rename `cclassTransformation` to `caseClassTransformation`
felixmulder d5b0014
Remove dependency on pickling library, make frontend use façade
felixmulder 9bd6101
Remove spray-json dependency
felixmulder 5e88fe3
Move frontend code to JS project - only kicker left in JVM project
felixmulder 7d8dade
Implement by name in parameter lists
felixmulder 61169c0
Add warning message on UnsetLink in doc-ui
felixmulder 00ea4fc
Rebase dottydoc over new HK scheme
felixmulder a284cad
Change TypeReference#paramLinks' type from `MaterializableLink` to `R…
felixmulder fe1ff8f
Fix #28: render functions passed as arguments
felixmulder 7d8458f
Add support for repeated parameters in producer
felixmulder 354a67c
Render repeated parameters correctly in client
felixmulder 3efdb93
Add support for rendering tuples idiomatically
felixmulder 58b83ce
Render idiomatic tuples in client
felixmulder c1b57e9
Correctly parse tuples, functions and applied types like `Map[K,V]` f…
felixmulder 5d6c15f
Handle all types of references when linking
felixmulder c05d628
Change from absolute name to type name in link names
felixmulder c53c115
Add indication that paramList takes implicit arguments
felixmulder a1c73e9
Define special handling of infix types like "<:<" and "=:="
felixmulder c4ec1b6
Sort members when serializing to JSON
felixmulder 87ecca2
Add a SortMembers phase to sort the members instead of doing it when …
felixmulder 553f9b2
Remove shared directory - nothing shared anymore
felixmulder 98b61dd
Fix #25: move doc related structures to `DocBase`
felixmulder 94dd0bc
Get docstring from overriden symbol if not present on the overriding …
felixmulder 922788a
Add info on where implicitly added members originate from
felixmulder 5fdc353
Fix phase fusion for subpackages, fix links in implicitly added methods
felixmulder 20fda57
Fix type params of classes, traits defs, which broke after new HK scheme
felixmulder 079e3db
Implement annotation parsing like CommentFactoryBase from nsc
felixmulder 5cd1d51
Remove client from dottydoc - no more Scala.JS deps!
felixmulder 0d89be8
Add `currentEntity` to templating API
felixmulder b1defa0
Add scaladoc interface stub
felixmulder a252074
Implement bridge that generates json on `doc` command
felixmulder bd77519
Implement working docs requiring manually specifying resources and te…
felixmulder d6b5c3e
Implement dotty bridge for doc
felixmulder abf1632
Add documentation to dottydoc API
felixmulder 0a9003d
Move client test to client repo
felixmulder 9879b90
Add snapshots resolver
felixmulder 59c6c0d
Properly materialize supertype links
felixmulder d8c02ec
Add `ImplicitlyAddedEntity` as a common trait for implicitly added me…
felixmulder 0b69be6
Add phase to deal with constructors
felixmulder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* sbt -- Simple Build Tool | ||
* Copyright 2008, 2009 Mark Harrah | ||
*/ | ||
package xsbt | ||
|
||
import xsbti.Logger | ||
import dotty.tools.dottydoc.api.scala.Dottydoc | ||
import java.net.URL | ||
|
||
class ScaladocInterface { | ||
def run(args: Array[String], log: Logger, delegate: xsbti.Reporter) = | ||
(new DottydocRunner(args, log, delegate)).run() | ||
} | ||
|
||
class DottydocRunner(args: Array[String], log: Logger, delegate: xsbti.Reporter) extends Dottydoc { | ||
def run(): Unit = getOutputFolder(args).map { outputFolder => | ||
val index = createIndex(args) | ||
val resources = getResources(args) | ||
val template = getTemplate(resources) | ||
|
||
template.fold(writeJson(index, outputFolder)) { tpl => | ||
buildDocs(outputFolder, tpl, resources, index) | ||
} | ||
} getOrElse { | ||
delegate.log( | ||
NoPosition, | ||
"No output folder set for API documentation (\"-d\" parameter should be passed to the documentation tool)", | ||
xsbti.Severity.Error | ||
) | ||
} | ||
|
||
private[this] val NoPosition = new xsbti.Position { | ||
val line = xsbti.Maybe.nothing[Integer] | ||
val lineContent = "" | ||
val offset = xsbti.Maybe.nothing[Integer] | ||
val sourcePath = xsbti.Maybe.nothing[String] | ||
val sourceFile = xsbti.Maybe.nothing[java.io.File] | ||
val pointer = xsbti.Maybe.nothing[Integer] | ||
val pointerSpace = xsbti.Maybe.nothing[String] | ||
} | ||
|
||
private def getStringSetting(name: String): Option[String] = | ||
args find (_.startsWith(name)) map (_.drop(name.length)) | ||
|
||
private def getOutputFolder(args: Array[String]): Option[String] = | ||
args sliding(2) find { case Array(x, _) => x == "-d" } map (_.tail.head.trim) | ||
|
||
private def getTemplate(resources: List[URL]): Option[URL] = | ||
resources.find(_.getFile.endsWith("template.html")) | ||
|
||
private def getResources(args: Array[String]): List[URL] = { | ||
val cp = args sliding (2) find { case Array(x, _) => x == "-classpath" } map (_.tail.head.trim) getOrElse "" | ||
|
||
cp.split(":").find(_.endsWith("dottydoc-client.jar")).map { resourceJar => | ||
import java.util.jar.JarFile | ||
val jarEntries = (new JarFile(resourceJar)).entries | ||
var entries: List[URL] = Nil | ||
|
||
while (jarEntries.hasMoreElements) { | ||
val entry = jarEntries.nextElement() | ||
|
||
if (!entry.isDirectory()) { | ||
val path = s"jar:file:$resourceJar!/${entry.getName}" | ||
val url = new URL(path) | ||
entries = url :: entries | ||
} | ||
} | ||
|
||
entries | ||
} getOrElse (Nil) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package dotty.tools | ||
package dottydoc | ||
|
||
import core._ | ||
import core.transform._ | ||
import dotc.config.CompilerCommand | ||
import dotc.config.Printers.dottydoc | ||
import dotc.core.Contexts._ | ||
import dotc.core.Phases.Phase | ||
import dotc.typer.FrontEnd | ||
import dotc.{ CompilationUnit, Compiler, Driver, Run } | ||
import io.PlainFile | ||
import model.Package | ||
import model.json._ | ||
|
||
import _root_.java.util.{ Map => JMap } | ||
|
||
/** Custom Compiler with phases for the documentation tool | ||
* | ||
* The idea here is to structure `dottydoc` around the new infrastructure. As | ||
* such, dottydoc will itself be a compiler. It will, however, produce a format | ||
* that can be used by other tools or web-browsers. | ||
* | ||
* Example: | ||
* 1. Use the existing FrontEnd to typecheck the code being fed to dottydoc | ||
* 2. Create an AST that is serializable | ||
* 3. Serialize to JS object | ||
*/ | ||
class DocCompiler extends Compiler { | ||
override def phases: List[List[Phase]] = List( | ||
List(new DocFrontEnd), | ||
List(new DocImplicitsPhase), | ||
List(new DocASTPhase), | ||
List(DocMiniTransformations(new LinkReturnTypes, | ||
new LinkParamListTypes, | ||
new LinkImplicitlyAddedTypes, | ||
new LinkSuperTypes, | ||
new AlternateConstructors, | ||
new SortMembers)) | ||
) | ||
} | ||
|
||
class DocFrontEnd extends FrontEnd { | ||
override protected def discardAfterTyper(unit: CompilationUnit)(implicit ctx: Context) = | ||
unit.isJava | ||
} | ||
|
||
abstract class DocDriver extends Driver { | ||
import scala.collection.JavaConverters._ | ||
|
||
override def setup(args: Array[String], rootCtx: Context): (List[String], Context) = { | ||
val ctx = rootCtx.fresh | ||
val summary = CompilerCommand.distill(args)(ctx) | ||
|
||
ctx.setSettings(summary.sstate) | ||
ctx.setSetting(ctx.settings.YkeepComments, true) | ||
|
||
val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ctx) | ||
(fileNames, ctx) | ||
} | ||
|
||
override def newCompiler(implicit ctx: Context): Compiler = new DocCompiler | ||
|
||
def compiledDocs(args: Array[String]): collection.Map[String, Package] = { | ||
val (fileNames, ctx) = setup(args, initCtx.fresh) | ||
doCompile(newCompiler(ctx), fileNames)(ctx) | ||
|
||
ctx.docbase.packages[Package] | ||
} | ||
|
||
def compiledDocsJava(args: Array[String]): JMap[String, Package] = | ||
compiledDocs(args).asJava | ||
|
||
def indexToJson(index: collection.Map[String, Package]): String = | ||
index.json | ||
|
||
def indexToJsonJava(index: JMap[String, Package]): String = | ||
indexToJson(index.asScala) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package dotty.tools.dottydoc.api.java; | ||
|
||
import dotty.tools.dottydoc.DocDriver; | ||
import dotty.tools.dottydoc.model.Package; | ||
import dotty.tools.dottydoc.util.OutputWriter; | ||
import java.util.Map; | ||
import java.util.List; | ||
import java.net.URL; | ||
|
||
/** | ||
* The Dottydoc API is fairly simple. The tool creates an index by calling: | ||
* "createIndex" with the same argument list as you would the compiler - e.g: | ||
* | ||
* {{{ | ||
* String[] array = { | ||
* "-language:Scala2" | ||
* }; | ||
* | ||
* Map<String, Package> index = createIndex(array); | ||
* }}} | ||
* | ||
* Once the index has been generated, the tool can also build a documentation | ||
* API given a Mustache template and a flat resources structure (i.e. absolute | ||
* paths to each resource, which will be put in the same directory). | ||
* | ||
* {{{ | ||
* buildDocs("path/to/output/dir", templateURL, resources, index); | ||
* }}} | ||
* | ||
* The tool can also generate JSON from the created index using "toJson(index)" | ||
* or directly using "createJsonIndex" | ||
*/ | ||
public class Dottydoc extends DocDriver { | ||
|
||
/** Creates index from compiler arguments */ | ||
public Map<String, Package> createIndex(String[] args) { | ||
return compiledDocsJava(args); | ||
} | ||
|
||
/** Creates JSON from compiler arguments */ | ||
public String createJsonIndex(String[] args) { | ||
return indexToJsonJava(createIndex(args)); | ||
} | ||
|
||
public String toJson(Map<String, Package> index) { | ||
return indexToJsonJava(index); | ||
} | ||
|
||
/** Creates a documentation from the given parameters */ | ||
public void buildDocs( | ||
String outputDir, | ||
URL template, | ||
List<URL> resources, | ||
Map<String, Package> index | ||
) { | ||
new OutputWriter().writeJava(index, outputDir, template, resources); | ||
} | ||
|
||
/** Writes JSON to an output directory as "index.json" */ | ||
public void writeJson(Map<String, Package> index, String outputDir) { | ||
new OutputWriter().writeJsonJava(index, outputDir); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
dottydoc/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package dotty.tools.dottydoc.api.scala | ||
|
||
import dotty.tools.dottydoc.DocDriver | ||
import dotty.tools.dottydoc.model.Package | ||
import dotty.tools.dottydoc.util.OutputWriter | ||
|
||
import scala.collection.Map | ||
import java.net.URL | ||
|
||
/** | ||
* The Dottydoc API is fairly simple. The tool creates an index by calling: | ||
* "createIndex" with the same argument list as you would the compiler - e.g: | ||
* | ||
* {{{ | ||
* val array: Array[String] = Array( | ||
* "-language:Scala2" | ||
* ) | ||
* | ||
* val index: Map[String, Package] = createIndex(array) | ||
* }}} | ||
* | ||
* Once the index has been generated, the tool can also build a documentation | ||
* API given a Mustache template and a flat resources structure (i.e. absolute | ||
* paths to each resource, which will be put in the same directory). | ||
* | ||
* {{{ | ||
* buildDocs("path/to/output/dir", templateURL, resources, index) | ||
* }}} | ||
* | ||
* The tool can also generate JSON from the created index using "indexToJson" | ||
* or directly using "createJsonIndex" | ||
*/ | ||
trait Dottydoc extends DocDriver { | ||
/** Creates index from compiler arguments */ | ||
def createIndex(args: Array[String]): Map[String, Package] = | ||
compiledDocs(args) | ||
|
||
/** Creates JSON from compiler arguments */ | ||
def createJsonIndex(args: Array[String]): String = | ||
indexToJson(compiledDocs(args)) | ||
|
||
/** Creates a documentation from the given parameters */ | ||
def buildDocs(outDir: String, template: URL, resources: List[URL], index: Map[String, Package]) = | ||
new OutputWriter().write(index, outDir, template, resources) | ||
|
||
/** Writes JSON to an output directory as "index.json" */ | ||
def writeJson(index: Map[String, Package], outputDir: String) = | ||
new OutputWriter().writeJson(index, outputDir) | ||
} |
34 changes: 34 additions & 0 deletions
34
dottydoc/src/dotty/tools/dottydoc/core/AlternateConstructorsPhase.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dotty.tools | ||
package dottydoc | ||
package core | ||
|
||
import dotc.core.Contexts.Context | ||
|
||
import transform.DocMiniPhase | ||
import model._ | ||
import model.internal._ | ||
|
||
/** This DocMiniPhase adds the alternate constructors, currently defined as | ||
* methods with the name `<init>`, to the Entity#constructors list | ||
*/ | ||
class AlternateConstructors extends DocMiniPhase { | ||
def partitionMembers(ent: Entity with Constructors with Members): (List[List[ParamList]], List[Entity]) = { | ||
val (constructors, members) = ent.members.partition(x => x.name == "<init>") | ||
|
||
val paramLists: List[List[ParamList]] = constructors.collect { | ||
case df: Def => df.paramLists | ||
} | ||
|
||
(ent.constructors ++ paramLists, members) | ||
} | ||
|
||
override def transformClass(implicit ctx: Context) = { case cls: ClassImpl => | ||
val (constructors, members) = partitionMembers(cls) | ||
cls.copy(members = members, constructors = constructors) | ||
} | ||
|
||
override def transformCaseClass(implicit ctx: Context) = { case cc: CaseClassImpl => | ||
val (constructors, members) = partitionMembers(cc) | ||
cc.copy(members = members, constructors = constructors) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you have both
Dottydoc.java
andDottydoc.scala
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to have a Java interface for when the time comes that releases are compiled with dotty. As such, tools compiled with dotty should be able to use the Scala interface, while incompatible projects (such as sbt on 2.10) will still be able to use the Java interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, should this interface be part of
dotty-interfaces
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with that as long as it's on the same classpath available to the bridge as dotty 😄
Let me know and I'll make it happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, let's keep it as is for now