Improved Doxygen documentation and search
Whether you are browsing Magnum docs or use Doxygen for your own C++ documentation, there’s always a way to improve your workflow. This article presents the most recent additions to the m.css Doxygen theme.
A year ago I switched Magnum docs to a theme written entirely from scratch, adding a never-before-seen search functionality a while later. As the saying goes, eating one’s own dog food is always a good way to find ways to improve it, so during the whole year I collected various enhancement ideas and noted rough corners that need more polishing, not to mention I received great feedback from all the happy developers that started using the theme for their own projects or were merely the users of it through Magnum documentation.
Showing include information for all the things
A long-awaited — and I would say also the most important — addition is
information about what to #include
to get given symbol. But wait, that’s
not all! While stock Doxygen shows include paths only for classes — which
made sense for classic OOP-heavy codebases — it certainly doesn’t help much
in Magnum, which has a lot of functionality directly inside namespaces. While
I’m trying hard to have the symbol ↔ file mapping as intuitive as
possible, it’s not always clear and can be a lot of struggle especially for
newcomers.
So I went one step further and the documentation now shows #include
information not only for classes, but also for namespaces (in case they are
fully contained in a single header, such as Animation::Easing), for free
functions, typedefs, variables and enums. That makes a big difference
especially in large namespaces such as Math or GL.
Parsing additional function attributes
The theme was already handling extra attributes like delete
d and
default
ed functions and noexcept
— which Doxygen is not
recognizing at all, if I remember correctly. To complete this, now also
override
, final
and conditional noexcept
are parsed and
shown. Besides that, final
is recognized also for classes, if you’d ever
need that, and a few bugs related to parsing of those attributes were fixed.
You can see these in action for example in Containers::Optional.
Support for documenting private virtual functions
The classic article about Virtuality by Herb Sutter
suggests that a class has never any public virtual
functions, but rather
a non-virtual public interface and all virtual interfaces private. That makes
the interface design much more flexible and you don’t run into weird issues
with covariant return types.
Magnum follows this rule since the very beginning in its application classes
(such as Platform::Sdl2Application) and all plugin interfaces like
Trade::AbstractImporter, but until now Doxygen was not really able to
show documented private functions. To work around that, the private virtual
functions used to be shown as protected
, which was misleading. Well, not
anymore!
Improved ordering for search results
The initial search implementation as explained in this article
was picking up the results in whatever order the search data had them in.
This was already million times better and faster than the classic Doxygen
search implementation, but later I realized it could be easily improved to
order the results in a more useful way — in particular preferring classes and
namespaces over functions and tucking away deprecated and
delete
d functionality, since you’re far less likely to need
documentation for these:
Fortunately, due to the way the search is implemented, this was only a matter of sorting the results while building the search data, it required no complex algorithm changes on the client side.
Autocompletion in the search field
Besides the above, with frequent use it also became apparent that having to type long parts of symbol names to narrow down the results is … annoying. Again, a solution was rather simple to implement, making use of a property of the Trie search structure — it collects characters until the first child node that has results and then it offers them for autocompletion.
OpenSearch browser integration
I’m a heavy user of browser’s search bar and search key shortcuts (for example,
if I write cpp vector::emplace
, my browser will search for std::vector::emplace()
directly on cppreference.com). If you’re like me
and want to have in-browser search available also for Doxygen docs, it’s now
discoverable through OpenSearch on browsers that
support it. So, for example on Firefox, visiting doc.magnum.graphics
will offer you this:
Chrome supports OpenSearch as well, but the discovery is well-hidden deep in the settings — if you are on the documentation site and open the search engine settings, it will suggest adding a new search engine. Another way that works in many browsers (also in Vivaldi, for example) is right-clicking the search field and selecting Add search engine.
The underlying capability that enables all this is recognition of
?q={query}#search
in GET parameters. Appending it to the documentation URL
will directly open a search popup with results for {query}
.
Copying Markdown links into a clipboard
This was implemented mainly as a cheat for myself to be more efficient — since I spend a lot of time doing tech support on the Magnum Gitter channel (drop by and say hi!) and various other places, I often need to share a link to the documentation. Now I can, pressing ⌘ M (the usual Meta key on your PC or Mac) will put a Markdown link to the result directly into the clipboard.
More goodies
Among other things there’s now a support for C++14 variable templates and various other improvements, mainly related to UX of the search popup. See the m.css commit history if you want to know more.
The theme is always improving, for a hint on what could come next, see for example mosra/m.css#79. If you want to get involved, there are various issues marked help wanted. I’m always very happy to accept contributions, bugreports and suggestions for improvement — in particular, it’s very possible that the new features are broken for corner cases that I didn’t think about or that some things are not working consistently across all browsers. Comments on that very welcome.
Try it out
If you are a Magnum user, there’s a chance you already spotted some of these improvements on doc.magnum.graphics as I was gradually pushing them out. If you are using Doxygen for your C++ docs, give the m.css Doxygen theme a go — I’m sure you’ll like the result both as a library developer and as an user of the documentation 😊