Skip to content

Emit Nix doc comments for functions #14

@PgBiel

Description

@PgBiel

Since Nix 2.2412, one may write :doc some-function on the Nix REPL (invoked by nix repl) to obtain a function's documentation, specified through a docstring in the format specified by Nix RFC 1453, as follows:

let
   /** Function doc */
   func = x: y: x + y;
in ...

Additionally, in Gleam, we may specify documentation comments on functions through the /// syntax, as follows:

/// Function doc
pub fn func(x: Int, y: Int) -> Int {
  x + y
}

When generating the Nix code for this function, it could be nice to translate the Gleam docstring into a Nix docstring so it can be accessed through :doc.

One concern: We'd need to escape */ in the docstring somehow. One way could be to add a whitespace between * and /, but this could be a problem depending on the contents of the docstring.

Footnotes

  1. https://discourse.nixos.org/t/nix-2-24-released/49986

  2. https://www.github.com/NixOS/nix/pull/11072

  3. https://www.github.com/NixOS/rfcs/pull/145

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestnix targetRelated to the nix target's codegen

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions