Add lion: documentation extraction tool for Go code#316
Conversation
|
@copilot now add some comments to the lion project itself and use it to document itself. the resulting markdown files will be in lion/docs/. also write a script that will regenerate the docs. |
Done in commit 6166bf0. Added lion comments throughout the source code covering overview, architecture, cli, and implementation topics. Generated documentation is in
Created |
|
@copilot > //lion:architecture I don't like that I have to write the same thing here on every line. Is there anything we can do about it? Is it possible to somehow mark the whole comment as a Lion comment? |
Added block comment support in commit 141a858. You can now use /*lion:architecture
The main function starts the HTTP server.
It registers handlers and starts listening.
No need to repeat lion:architecture on each line.
*/
func main() { ... }Both formats work and can be mixed. Single-line ( |
|
@copilot ok but uhhhhhhhhh i wonder if there is any way to do it without /* */ comments? like for example what if we just say that a single lion directive at the bottom of the // comment pulls the entire comment into the docs? or idk maybe you can suggest something. how do other tools handle this "mark a block of comments as [something]" usecase? |
Implemented marker-at-end format in commit c7d2645. Put // The main function starts the HTTP server.
// It registers handlers and starts listening.
// It handles setup and configuration.
//lion:architecture
func main() { ... }This is now the recommended format - cleanest syntax, no repetition, no All three formats (marker-at-end, single-line, block comment) work and produce identical output. |
|
@copilot Im interested in higher level docs. Like im not looking for a godoc replacement here, but smth that will generate higher level docs like "how to use this tool", "syntax reference", "known issues", etc. right now comments in lion itself are an example of the former but should be an example of the latter |
Changed in commit c2f5126. Replaced low-level API documentation with high-level user documentation examples. Lion now demonstrates:
The self-documentation now shows how to create narrative documentation and user guides, not API reference (which is godoc's job). Generated docs are in |
|
@copilot Oof. Not great. Ok lets do it this way. Remove all lion comments you added. I want to learn the following: a) what syntax is supported? b) how do I run generation? c) in what order do annotated snippets end up in the file? d) can I set the title of the generated file / section? ------ all of these should be answered in the generated docs and all documentation must be written at the point of implementation, not in a random place or in doc.go. |
Done in commit e7d5905. Removed all previous lion comments and doc.go. Added new documentation at the point of implementation that answers your questions: a) What syntax is supported? → Generated docs are now 5 files: |
e51f4ad to
ff059a9
Compare
🧪 CI InsightsHere's what we observed from your CI run for ff059a9. 🟢 All jobs passed!But CI Insights is watching 👀 |
Implements a tool that extracts lion comments from Go source and generates organized markdown documentation files, one per topic. Supports three comment formats: marker-at-end (recommended), single-line, and block comment.
Usage
Marker-at-end format (recommended - cleanest):
Single-line format:
Block comment format:
$ lion generate ./myapp --output ./docs Generated documentation in ./docs $ ls docs/ getting-started.md api-guide.md index.mdImplementation
AST parsing (
internal/extractor): Walks Go AST to extract lion comments from package declarations, functions, types, constants, and variables. Supports three formats: marker-at-end (regular//comments with//lion:topicat the end), single-line (//lion:topic), and block comment (/*lion:topic ... */). Combines consecutive comments on the same entity.Markdown generation (
internal/generator): Creates one file per topic with entity sections. Includes source file references. Generatesindex.mdwith topic links.CLI: Cobra-based with
generate,topics, andversioncommands.Comment Formats
lion supports three formats that produce identical output:
//comments followed by//lion:topic-name- Cleanest syntax, no repetition, no/* */needed//lion:topic-name Content- Good for short comments, can be repeated/*lion:topic-name\nMulti-line content\n*/- Alternative for multi-line without repetitionAll formats can be mixed in the same codebase.
Self-Documentation
lion documents itself using its own extraction tool. The
lion/docs/directory contains markdown files that answer key questions about using the tool:supported-syntax.md- What syntax formats are supported (documented atextractFromCommentGroup)how-to-run-generation.md- How to run the generate command (documented atgenerateCmd)snippet-order.md- In what order snippets appear in generated files (documented atGenerate)file-title.md- How file titles are determined from topic names (documented atgenerateTopicFile)index.md- Documentation index with links to all topicsAll documentation is written at the point of implementation - comments are placed at the exact functions/commands where features are implemented, not in random locations or separate doc files.
A
regenerate-docs.shscript is provided to regenerate documentation when code changes:$ ./lion/regenerate-docs.sh Regenerating lion documentation... Generated documentation in ./docsThis serves as both documentation and a working example of lion's approach: documenting features at their implementation points.
Changes
lion/with main.go, internal packages, tests, README, AGENTS.mdlion/docs/with documentation answering specific usage questionslion/regenerate-docs.shscript to regenerate documentationREADME.md,release-mirror.toml,mise.tomlto include lionOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.