-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Introduce digging behaviour #98
base: master
Are you sure you want to change the base?
Conversation
This may be needed when the project has not such flat structure, as nixpkgs. When different libraries produces their outputs not at toplevel, but dipper. You may specify common templates to dig into in command arguments. Eg `--dig submodule`, then this will generate documentation for files like: { submodule = {...}: { /* Doc for foo */ foo = 1; /* Doc for bar */ bar = 2; } } You may force documentation to dig into attrset withing its comment to with `DocDig!` directive: { /* DocDig! */ myDeepLib = {...}: { /* Doc for foo */ foo = 1; /* Doc for bar */ bar = 2; } } Change-Id: I1518323d8e09a087a7b7d02451437792f5bee98f
This doesn't seem very sound, because it would just ignore the function argument which could have important semantics. In particular, right now the examples you gave just generate this: # test {#sec-functions-library-test}
## `lib.test.foo` {#function-library-lib.test.foo}
Doc for foo
## `lib.test.bar` {#function-library-lib.test.bar}
Doc for bar With no mention of I think for an example like this: {
/*
Add or subtract two numbers.
*/
addSub = { a, b }: {
/* Doc for add */
add = a + b;
/* Doc for sub */
sub = a - b;
};
} generating something like this would make more sense: # test {#sec-functions-library-test}
## `lib.test.addSub` {#function-library-lib.test.addSub}
**Type**: `Attrs -> Attrs`
Add or subtract two numbers.
**Argument**
structured function argument
: `a`
: Function argument
`b`
: Function argument
**Returns**
`add`
: Doc for add
`sub`
: Doc for sub This doesn't work very well if you have more complicated nested doc comments though, so maybe both Ping @hsjobeki as this is relevant for NixOS/rfcs#145 and #91 |
@infinisil, I agree with you, but only when we are talking about automatic collecting of deeper fields. My PR is about different behaviour. The most close example is flake: {
outputs = { self, nixpkgs }: {
/* Doc for abc */
result1 = "abc";
/* Just nixpkgs */
result2 = nixpkgs;
};
} My main goal is to generate doc like next: # my-flake {#sec-functions-library-flake}
## `lib.my-flake.result1` {#function-library-lib.flake.result1}
Doc for abc
## `lib.my-flake.result2` {#function-library-lib.flake.result2}
Just nixpkgs
For now nixdoc could generate documentation only for I think, it is better to drop the |
Regarding the 'DocDig!' directive, I would say that your implementation is rather limited. It only supports direct attributes and direct let...in expressions. Any expression other than
I think a complete implementation of this would collect all doc-comments recursively until the end of the parent expression. In comparison, I'll explain how https://noogle.dev works with this problem. Imagine the following 2 files:
We can the observe:
From that position, we can statically analyze the init.nix file at the given position to retrieve the documentation. This currently works for attributes and lambdas. Unfortunately, this doesn't work with nixdoc because it is a static (ast) only tool. And the nix language is too complex for complete static analysis. |
You can do this instead: {
outputs = inputs: import ./outputs.nix inputs;
# This doesn't work because of https://github.com/NixOS/nix/issues/4945
# outputs = import ./outputs.nix;
} Then you can run nixdoc on |
Breaking the code architecture to fix documentation tool drawbacks is a very bad idea |
Personally i'd not want to maintain the Maybe we can find a solution that solves your problem in another way. Do you have some code example / repository that you could show to us? |
@hsjobeki I do not actually need for P.S. The |
Rethinking this a bit, I think this could be made to work like this: {
outputs =
{ self, nixpkgs }:
/* nixdoc!outputs */
{
/* Doc for abc */
result1 = "abc";
/* Just nixpkgs */
result2 = nixpkgs;
};
} Here, This fixes the problem brought up by @hsjobeki in #98 (comment). |
I am not sure, do you need this functionality within mainstream. So I made this WIP PR to ask you, should I make it more clear and add tests to be merged?
This may be needed when the project has not such flat structure, as nixpkgs. When different libraries produces their outputs not at toplevel, but dipper.
You may specify common templates to dig into in command arguments. Eg
--dig submodule
, then this will generate documentation for files like:You may force documentation to dig into attrset withing its comment to with
DocDig!
directive: