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

Add unidoc directive for markdowns #24563

Merged
merged 8 commits into from
Mar 1, 2018

Conversation

richardimaoka
Copy link
Contributor

@richardimaoka richardimaoka commented Feb 18, 2018

Closes #24426

Generated page under my firebase project:
https://doc.akka.io/docs/akka/current/cluster-client.html#cluster-client

I want to:

  1. add @unidoc in akka, and make sure it works for all .md files in akka which would take time
  2. then after 1. move the code for @unidoc to either akka-paradox or paradox

is that ok? or should we just do 2?

Copied UnidocDirective from akka/akka-http#1579, and added UnidocRefDirective to avoid the issue described here

As the first step, modified cluster-client.md to see how @unidoc works.

@akka-ci akka-ci added the validating PR is currently being validated by Jenkins label Feb 18, 2018
another cluster. It only needs to know the location of one (or more) nodes to use as initial
contact points. It will establish a connection to a @scala[@scaladoc[`ClusterReceptionist`](akka.cluster.client.ClusterReceptionist)]@java[@javadoc[`ClusterReceptionist`](akka.cluster.client.ClusterReceptionist)] somewhere in
contact points. It will establish a connection to a @unidocRef[ClusterReceptionist](akka.cluster.client.ClusterReceptionist) somewhere in
Copy link
Contributor Author

@richardimaoka richardimaoka Feb 18, 2018

Choose a reason for hiding this comment

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

Using @unidocRef instead of @unidoc, because @unidoc gave the following error:

Error writing content for page cluster-client.html: 2 matches found for ClusterReceptionist, but not
javadsl/scaladsl: akka.cluster.client.ClusterReceptionist,
akka.cluster.typed.internal.receptionist.ClusterReceptionist

Matched two classes are not javadsl/scaladsl variants.

Although @unidoc by UnidocDirective works nicely with a concise syntax, it doesn't work in cases like above. Hence this syntax, @unidocRef[ClusterReceptionist](akka.cluster.client.ClusterReceptionist).

Copy link
Member

Choose a reason for hiding this comment

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

I agree being able to point to a particular class when unidoc can't figure it out on its own is useful. Could we even do that in one directive, so allowing @unidoc[ClusterReceptionist](akka.cluster.client.ClusterReceptionist) or perhaps even @unidoc[client.ClusterReceptionist]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think handling both @unidoc[ClassName] and @unidoc[ClassName](path.to.ClassName) is difficult, as we need to

  1. extract if (path.to.ClassName) part exists,
  2. and if 1 is not found, fall back to the current logic for @unidoc[ClassName]

The problem with 1 is that we need the same logic as SourceDirective's resolvedSource, which is sealed inside Paradox.

For @unidoc[client.ClusterReceptionist], I can give it a try. Hopefully that does not clutter the code to extract the label and filtering logic here..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@unidoc[client.ClusterReceptionist] was actually almost already handled. So I only made a slight change.

You can see the generated page here

}.value
)

class UnidocDirective(allClasses: IndexedSeq[String]) extends InlineDirective("unidoc") {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is copied from akka/akka-http#1579 removing unnecessary stuff.

Copy link
Member

Choose a reason for hiding this comment

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

What unnecessary stuff could be removed? can we also remove it over there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unnecessary stuff was removed in 4161175 - unused parameters, and case 2 in the pattern match could be handled by case n.

As we are making the new sbt plugin anyway, we don't need to do the same in akka-http? However, if the plugin takes too much time, yes I'll do that in akka-http.

}
}

class UnidocRefDirective(page: Page, variables: Map[String, String]) extends InlineDirective("unidocRef") {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See this comment for the motivation.

@richardimaoka richardimaoka changed the title Unidoc richard Add unidoc directive for markdowns Feb 18, 2018
@akka-ci akka-ci added tested PR that was successfully built and tested by Jenkins and removed validating PR is currently being validated by Jenkins labels Feb 18, 2018
@akka-ci
Copy link

akka-ci commented Feb 18, 2018

Test PASSed.

@johanandren
Copy link
Member

This is very nice!

As the javadsl/scaladsl is our Akka-specific convention I don't think we can move the directive to paradox general (unless we make it more configurable). Maybe start with the akka-paradox module so that we can use it in all Akka-umbrella projects.

Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

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

Very nice! I agree with adding it to akka-paradox.

@2m
Copy link
Member

2m commented Feb 19, 2018

sbt-paradox-akka is only used in akka and akka-http. So it would not benefit projects like alpakka and akka-management.

We should package the directive as a separate sbt plugin. I do not think we have yet seen a paradox directive pacakged separately as an sbt plugin, but it seems to be doable.

@richardimaoka
Copy link
Contributor Author

I can work on the sbt plugin later, but is it ok to firstly add the @unidoc implementation inside the akka repository?

Otherwise, I need to make sure the @unidoc implementation works for all the .md files in akka, to avoid multiple releases of the sbt plugin just to fix issues as I keep updating .md. I prefer incrementally updating .md, at least in a couple of PRs, but if we should get the sbt plugin ready first, and go with a single big PR to convert all .md, i follow that approach.

@raboof
Copy link
Member

raboof commented Feb 20, 2018

Incubating it in the project and extracting it later seems fine to me

@akka-ci akka-ci added validating PR is currently being validated by Jenkins and removed tested PR that was successfully built and tested by Jenkins labels Feb 23, 2018
})
case n =>
throw new java.lang.IllegalStateException(s"$n matches found for $label, but not javadsl/scaladsl: ${matches.mkString(", ")}")
}
}
}

class UnidocRefDirective(page: Page, variables: Map[String, String]) extends InlineDirective("unidocRef") {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turned out @unidocRef is not needed as @unidoc[path.to.ClassName] was already handled.

@richardimaoka
Copy link
Contributor Author

Think it's good for another round of review.

@akka-ci akka-ci added tested PR that was successfully built and tested by Jenkins and removed validating PR is currently being validated by Jenkins labels Feb 23, 2018
@akka-ci
Copy link

akka-ci commented Feb 23, 2018

Test PASSed.

@@ -3,7 +3,7 @@
An actor system that is not part of the cluster can communicate with actors
somewhere in the cluster via this @unidoc[ClusterClient]. The client can of course be part of
another cluster. It only needs to know the location of one (or more) nodes to use as initial
contact points. It will establish a connection to a @unidocRef[ClusterReceptionist](akka.cluster.client.ClusterReceptionist) somewhere in
contact points. It will establish a connection to a @unidoc[client.ClusterReceptionist] somewhere in
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit strange though, it's neither the FQCN nor the simple name but something in-between, I think either @unidoc[ClusterReceptionist] or @unidoc[akka.cluster.client.ClusterReceptionist] is what we'd want

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, added a new commit to only allow FQCN or a simple class name (without any .).

@akka-ci akka-ci added validating PR is currently being validated by Jenkins and removed tested PR that was successfully built and tested by Jenkins labels Feb 24, 2018
printer.print(s"</span>")
} catch {
case e: LinkException =>
throw new LinkException(s"${e.getMessage}. You may want to use the fully qualified class name as `@unidoc[fqcn]`.")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Error message is like:

[error] Caused by: com.lightbend.paradox.markdown.ExternalLinkDirective$LinkException: Failed to resolve [client.ClusterReceptionist] referenced from [cluster-client.html] because property [javadoc.base_url] is not defined. You may want to use the fully qualified class name as @unidoc[fqcn].
[error] at akka.ParadoxSupport$UnidocDirective.renderByFqcn(ParadoxSupport.scala:94)

Copy link
Member

Choose a reason for hiding this comment

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

Nice!

@akka-ci akka-ci added tested PR that was successfully built and tested by Jenkins and removed validating PR is currently being validated by Jenkins labels Feb 24, 2018
@akka-ci
Copy link

akka-ci commented Feb 24, 2018

Test PASSed.

case n =>
throw new java.lang.IllegalStateException(
s"$n matches found for @unidoc[$label], but not javadsl/scaladsl: ${matches.mkString(", ")}. " +
s"You may want to use the fully qualified class name as @unidoc[fqcn] instead of @unidoc[${label}]."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Error message is like:

[error] Caused by: java.lang.IllegalStateException: 2 matches found for @unidoc[ClusterReceptionist], but not javadsl/scaladsl: akka.cluster.client.ClusterReceptionist, akka.cluster.typed.internal.receptionist.ClusterReceptionist. You may want to use the fully qualified class name as @unidoc[fqcn] instead of @unidoc[ClusterReceptionist].
[error] at akka.ParadoxSupport$UnidocDirective.renderByClassName(ParadoxSupport.scala:78)

@akka-ci akka-ci added validating PR is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed tested PR that was successfully built and tested by Jenkins validating PR is currently being validated by Jenkins labels Feb 24, 2018
@akka-ci
Copy link

akka-ci commented Feb 24, 2018

Test PASSed.

@akka-ci
Copy link

akka-ci commented Feb 26, 2018

Test FAILed.

@jrudolph
Copy link
Member

(Ignore the latest failure, I was testing a Jenkins thing)

@akka-ci
Copy link

akka-ci commented Feb 26, 2018

Test FAILed.

@jrudolph
Copy link
Member

PLS BUILD

@akka-ci akka-ci added validating PR is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed tested PR that was successfully built and tested by Jenkins validating PR is currently being validated by Jenkins labels Feb 26, 2018
@akka-ci
Copy link

akka-ci commented Feb 26, 2018

Test PASSed.

}
}

def renderByClassName(label: String, node: DirectiveNode, visitor: Visitor, printer: Printer): Unit = {
Copy link
Member

Choose a reason for hiding this comment

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

It would be neat if this logic would just find the fqcn based on the short text and then re-use renderByFqcn, would that be possible?

Copy link
Member

Choose a reason for hiding this comment

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

I iterated further on this a bit in akka/akka-http#1890, could you have a look whether what I did there make sense and if so apply the same here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, copied UnidocDirective from akka/akka-http#1890

@akka-ci akka-ci added validating PR is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed tested PR that was successfully built and tested by Jenkins validating PR is currently being validated by Jenkins labels Feb 28, 2018
@akka-ci
Copy link

akka-ci commented Feb 28, 2018

Test PASSed.

Copy link
Member

@raboof raboof left a comment

Choose a reason for hiding this comment

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

Super nice!

Copy link
Member

@johanandren johanandren left a comment

Choose a reason for hiding this comment

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

LGTM, thanks a bunch!

@johanandren johanandren merged commit 82f50a8 into akka:master Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tested PR that was successfully built and tested by Jenkins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants