r/Clojure • • May 24 '18

a new Clojure documentation effort

https://cljdoc.xyz/
73 Upvotes

22 comments sorted by

12

u/fbellomi May 24 '18

Nice tool. FYI CrossClj already does almost the same thing, with the difference that it automatically pulls docs from all opensource projects hosted con clojars, and it automatically links to sources, which provide cross-references links for all defined vars, along with a unified search engine on vars for all clojure projects.

For example, here is the CrossClj documentation for bidi, which is the first example listed the cljdoc.xyz

https://crossclj.info/doc/bidi/2.1.3/index.html

7

u/mklappstuhl May 24 '18

The idea is to expand beyond API docs and also include guides, examples and other stuff: see Reitit for a more complex scenario: https://cljdoc.xyz/d/metosin/reitit/0.1.1/doc/introduction/

Eventually, I would also like to package docsets for documentation browsers like Dash (https://kapeli.com/) & Zeal (https://zealdocs.org/).

CrossClj is a very cool project and I probably didn't look at it enough (yet) but there's a reason people publish Codox documentation and don't link to their respective CrossClj pages.

cljdoc's goal is to make it super easy for everyone publishing documentation for their Clojure/Script library (see rationale).

Since you seem to be the CrossClj author: is the code open source somewhere? Would be very curious to take a peek at your data model etc :)

4

u/fbellomi May 25 '18

Thanks for the reference, however the idea behind CrossClj is not "make people link to their CrossClj page".

In fact, CrossClj autonomously discovers published projects and makes use of all available data (mainly, the source code), to automatically publish documentation. The automation part is relevant: at the moment 9700+ clojure projects are indexed, and only a small fractions have published codox documentation; IMO requiring all these authors to explicitly take action is difficult, and hopefully not necessary. If no codox metadata is present in the source code, CrossClj still publish available metadata (eg. var doc strings), and even in the case no documentation is provided, CrossClj published both the outline of the documentation and the fully cross-referenced source code. For example, if you have an undocumented fn in a project, you can still look for all the usages of that fn in all the 9700+ projects, with link to usages in their source, sorted by project popularity. In the end, you can browse all 9700+ projects as a single code base, by jumping from an identifier to its definition (even if it's on another project), and by searching for all uses of each defined var.

FWIW, I personally welcome any effort in this area, such as cljdoc; CrossClj is also a no-profit, pro-bono effort; I am offering these comments on this thread simply because I think it's useful to be aware of the state of the art and discuss trade-offs when proposing alternatives. For this reason, CrossClj provides links to other documentation projects, for example in the pages of the vars of clojure/core, such as:

https://crossclj.info/fun/clojure.core/frequencies.html

Regarding the source code: I have no real reason for not making it available, except that is a very old codebase (actually the first application I wrote in clojure), it's not "aesthetically pleasant" by my current standards, it would need some cleanup (eg. moving credentials data outside from the actual source code...). At the moment I have no bandwidth for this, but I would consider the effort if there is some interest.

1

u/mklappstuhl May 29 '18

I absolutely agree that having library authors take action here won't work. It needs to be fully automated and I will get there eventually.

Linking to usages from a function and similar stuff sounds great and is something I'd explore for cljdoc as well.

I appreciate you making me aware of the state of the art but with CrossClj being closed-source and there not being any clear path towards contributing there is very little I can do with that awareness :-) I strongly believe that a platform like this can only thrive if it is open source and contributions are welcome.

Please consider open-sourcing it or helping to build cljdoc. I would certainly appreciate your experience with storing this data, analyzing sources etc. If that's any less work I'd also be happy to receive a .zip with the code.

2

u/fbellomi May 31 '18

CrossClj, is actually a somewhat "simple" system:

  1. it takes a list of published clojure projects from clojars https://github.com/clojars/clojars-web/wiki/Data

  2. iterate on them, and for each one

  3. download the full dependencies using the Maven toolchain, and temporarily add them to the runtime; you can use https://github.com/cemerick/pomegranate

  4. parse all the source code with https://github.com/clojure/tools.analyzer

  5. ...which produces a very detailed AST http://clojure.github.io/tools.analyzer/spec/quickref.html where you can find, for each symbol in your source code, both the position in the source code itself, and the fully qualified reference (ie. var, local binding...)

  6. with this information, you can choose a global "coordinate system" for your cross-referenced entities, eg. <group, project, version, namespace, var> and resolve the project-local qualified names into the full coordinates (eg. you look at project.clj to resolve the actually used libraries)

  7. once you've done that you can a) decorate your source code, b) index the data (CrossClj uses Lucene which is very good also for fulltext search), c) use for whatever you want (ie. statistics, static analysis)

I'll try to polish the source code and publish it

2

u/fbellomi Jun 02 '18

I just published CrossClj's source code.

https://github.com/fbellomi/crossclj

1

u/mklappstuhl Jun 01 '18

I would be very interested in seeing the analysis code! Especially source extraction, how you combine clj/cljs etc.

How do you handle isolation? Or do you just load those jars and trust that there's no malicious code in them?

2

u/fbellomi Jun 01 '18

At that time I didn't have a good solution for isolation/trust; nowadays I would take into consideration Boot Pods https://github.com/boot-clj/boot/wiki/Pods

Source extraction is very straightforward: published jars contain the source code, which can directly be parsed using https://github.com/clojure/tools.reader and https://github.com/clojure/tools.analyzer

clj and cljs live in separated spaces, so it's enough to use the correct analyzer (based on the source file extension); I don't know the details about cljc because at the time (2013) it did not exist, but I think tools.reader support it; I think you will have to parse cljc files twice (one for each language)

When I say "parse" I actually mean read+eval (which is what tools.analyzer does). Eval includes macro expansion, which preserves metadata.

My analysis code is very rough, since at that time there were no documentation on the AST format for tools.analyzer! however you simply traverse the AST top-down and collect the metadata on the symbols

8

u/mklappstuhl May 24 '18

Hi, main author (so far) here, happy to answer any questions! :)

4

u/zcam May 24 '18

This is great! I just built a few repos with it, super nice really.

Next step would be to run a script that uses the github api and builds all clojure repos with more than N stars ;)

https://cljdoc.xyz/d/cc.qbits/alia/4.2.1/api/qbits.alia https://cljdoc.xyz/d/cc.qbits/spandex/0.6.2/doc/readme/

1

u/mklappstuhl May 24 '18

A contribution in that direction would be very much welcome! :)

4

u/Severed_Infinity May 24 '18

I don't really see the point? It takes the readme of GitHub projects… I could just go and read the GitHub page for that.

Is it the API part that lists all the vars? Again I can open up the library in my IDE or browse the GitHub page to get the same results.

Unless the goal here is to document how to use the libraries and along with best practices with functional code that I could say copy and paste then I cannot see the value to this site personally.

As someone else already mentioned, something like this already exists - CrossClj, and outside of a different UI, they both do the exact same thing.

The appeal of the UI would definitely make me choose it over CrossClj but again unless it adds extra value over the GitHub pages then I repeat that I do not see the point.

4

u/dustingetz May 24 '18

I think the goal is to make it dead easy to browse the namespace and see the docs in friendly rendered form. This would focus more attention on docs and thus encourage investment. It could also be a starting point to evolve more interesting things, like a community wiki that supplements the docstrings in source (and doesn't require PRs and CLAs to contribute docs!)

-1

u/Severed_Infinity May 24 '18

That’s exactly do in my ide… so it offers nothing of value especially to me.

3

u/RomanTsopin May 24 '18

UI looks awesome! Will give it a try

1

u/Miridius May 24 '18

Nice! Will it work with projects hosted on GitLab.com?

1

u/mklappstuhl May 24 '18

There's nothing fundamentally tying it to GitHub at this point but I think some links may not work (e.g. source links) due to different link structures on those two sites.

1

u/foobarbazquix May 25 '18

Omg this is amazing