-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Is your feature request related to a problem? Please describe.
I am always having to look up function documentation in the nixpkgs repository with either ripgrep or the tool I wrote because of this problem, nix-doc, but neither is perfect: ripgrep finds a lot of overridden copies of the function, and you still often have to jump between several files to decipher what's required to call a function.
By comparison, nix-doc uses a heuristic of looking in the AST for function definitions with comments above them to eliminate overrides, but this heuristic misses functions that are defined in their own file such as fetchFromGitHub, which is a problem I don't think I can practically solve in a tool that doesn't intend to understand the Nix language.
The Nix repl currently has the information to provide a better documentation experience as it knows where the actual function is defined through builtins.unsafeGetAttrPos, but it is not immediately obvious how it can nicely be extended to call some external tool to parse the nix file and find the comments above the function and output them.
Describe the solution you'd like
I want to have the following session in nix repl (also imagine it has colour):
nix-repl> nixpkgs = import <nixpkgs> {}
nix-repl> :doc nixpkgs.lib.composeExtensions
Compose two extending functions of the type expected by 'extends'
into one where changes made in the first are available in the
'super' of the second
composeExtensions = # /nix/store/...-nixpkgs/nixpkgs/lib/fixed-points.nix:74
f: g: self: super: ...
Describe alternatives you've considered
It is /maybe/ possible to do this in nixpkgs, but you'd need a nix parser in nixpkgs OR make nix expose the comments in some attribute (discussed on IRC; plausible). Ergonomically it is probably superior to have this built into nix repl or to make nix repl support some kind of profile mechanism or other trick to add more :commands.
Additional context
cc @infinisil we discussed this on IRC in #nix-lang a couple of weeks ago