nim-lang / RFCs

A repository for your Nim proposals.
136 stars 26 forks source link

split out docgen specific code from compiler #285

Open timotheecour opened 3 years ago

timotheecour commented 3 years ago

proposal

=> 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:

Araq commented 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.

timotheecour commented 3 years ago

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:

# 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.

minor notes

Araq commented 3 years ago

So ... 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.

Araq commented 3 years ago

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.

juancarlospaco commented 3 years ago

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. :)

timotheecour commented 3 years ago

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)

juancarlospaco commented 3 years ago

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...