Open timotheecour opened 3 years ago
We need to decide how JSON can encode the "click on type definition" links and RST markup. I'd still prefer a semi-structured lossless XML format instead of JSON, simply because JSON is inadequate but I've said it before and nobody listens.
We need to decide how JSON can encode the "click on type definition" links and RST markup
not a complete answer but this is a start:
PSym
visited by nim doc
into a compact json representationfn
) are done exclusively via a unique id (eg fn@1
), never by name (eg fn
)Foo
reappears in multiple contexts)# in main.nim
import mymod
proc fn(a: Foo): Bar
proc fn(a: Foo, b: int) # overload
{
"symbols": {
"main@1": {
"name": "main",
"kind": "module",
"imports": ["mymod@1"],
"exports": null,
"symbols": ["fn@1", "fn@2"],
},
"Foo@1": {
"name": "Foo@1",
"kind": "type",
"module": "mymod@1",
"loc": {"file": "/pathto/myincludefile.nim", "line": 10, "col": 11},
},
"fn@1": {
"name": "fn",
"kind": "proc",
"args": [{"name": "a", "type": "Foo@1"}],
"returnType": "Bar",
},
"fn@2": {
"kind": "proc",
"name": "fn",
"args": [{"name": "a", "type": "Foo@1"}, {"name": "b", "type": "int@1"}],
"returnType": null,
}
}
}
I'd still prefer a semi-structured lossless XML format instead of JSON
you'd need to explain how json is inadequate in this context. json allows unique ids as references (aka pointers) so you can encode arbitrary cyclic data structure such as compiler's known PSym
symbols.
Foo@1
, but each symbol would have those fieldsSo ... instead of importing the Nim compiler and access the AST after sem'check, you serialize the AST into a JSON format. And with IC we have the same but as a good binary format, either way you need a library to de-serialize, I'm not sure I like the overlap.
What we should really do is to make nim doc
delegate to a new tool called nimdoc
and this tool imports the compiler API much like nimsuggest does it. Otherwise it's an invitation to inferior documentation tools ("Yes, it doesn't link types to their definitions and still ignores parts of the exposed JSON but it uses MegaMarkdown which is superior (and only works on Unix)") and we get annoying ecosystem splits with markdown dialects.
nimdoc
can have more dependencies like Karax etc. Best of both worlds.
Split the Documentation itself from the main repo into a tiny doc-only repo
More simple and faster CI, can delegate more to the community, no code changes, etc. :)
More simple and faster CI, can delegate more to the community, no code changes, etc.
I don't think splitting into a different repo is a good idea, it causes complications when a PR needs to update both the nim repo and the doc repo (ditto when it gets reverted); not to mention versioning: would it stay in sync or not.
I also don't think faster CI is a valid argument, CI for that repo would need to run anyways (and nim docs CI already runs in a separate github action, which is fast/not a bottleneck compared to main CI in azure pipelines)
I don't think splitting docgen into a different repo is a good idea, is already hard to have all stuff documented already.
If we had a big excess of documentation it would be different but I dont think thats the case...
proposal
nim jsondoc -o:foo.json [options] main
runs runnableExamples and produces foo.jsonnimdoc --mode:html|pdf|latex|tex --outdir:htmldocs foo.json
produces actual docsnim doc [options] main
callsnim jsondoc
and thennimdoc
with appropriate options by shelling out, to reproduce pre-existing behavior=> no code breaks, it'd be a transparent change for users => compiler logic is cleansed from RST parsing etc => no code duplication either
benefits
links
earlier versions of this proposal in comments: