Skip to content

More about module documentation #220

Closed

Description

@rvirding

It now works but there are a few issues which I think needs discussing up:

  • Now the argument information is stored and returned for every function and macro even if it doesn't have any documentation. Should this only be done when there is documentation?
  • Now the function/macro arguments haven't been macro expanded. Should it be like this? Should we see the arguments as they are written or as they "really" are? The compiler internals as they are today enforce the current way but it would be easy to change this if we wish.
  • Internally should we delay processing the documentation until have checked the code? This would require the change to the compiler internals as in the previous issue.

Activity

  1. yurrriq commented on Apr 17, 2016

    @yurrriq
    Contributor

    Should we store information for undocumented definitions?

    I think so. Often the name, arity and arguments can be informative in and of themselves.

    Should the arguments be macro expanded?

    I think I've changed my mind on this and now want arguments macro expanded.
    That would make the job easier for further tooling (e.g. lodox or {doc,describe,help}/1).

    Should we delay processing until the code is checked?

    Probably. It's inefficient to execute the do_docs step if the compilation will ultimately fail.
    lfe_doc also basically assumes correct code (though there is a bit of error handling).

  2. rvirding commented on Apr 18, 2016

    @rvirding
    MemberAuthor

    OK, my plan is that I will first fix the internals of the compiler so we can move the collecting of the docs until after the code has been checked. This will also mean that the function/macro arguments will be expanded.

    We can then discuss if we want to keep argument info for functions/macros without docs.

  3. yurrriq commented on Apr 18, 2016

    @yurrriq
    Contributor

    Sounds good to me. It might be helpful to look at how Codox, Exdoc, et al. handle undocumented functions.

  4. yurrriq commented on Apr 22, 2016

    @yurrriq
    Contributor

    I've started working on updating lodox to use the LDoc chunk.

    See version 0.13.0 and the terribly satisfying diff:

    $ git diff --stat 0.12.14 0.13.0
     .travis.yml                |   9 ++-
     README.md                  |  94 +++++++++++++++++++---------
     doc                        |   2 +-
     rebar.config               |  41 +++++-------
     rebar.lock                 |  25 ++++----
     src/lodox-html-writer.lfe  |   4 +-
     src/lodox-p.lfe            |  82 ------------------------
     src/lodox-parse.lfe        | 335 ++++++++++++++++----------------------------------------------------------------------------------
     src/lodox-search.lfe       |   4 +-
     src/lodox.app.src          |   4 +-
     test/lodox_parse_tests.erl | 168 -------------------------------------------------
     test/unit-lodox-tests.lfe  |  44 +++++++++++--
     12 files changed, 192 insertions(+), 620 deletions(-)
  5. rvirding commented on Apr 23, 2016

    @rvirding
    MemberAuthor

    I have just pushed a commit which moves the documentation till after the syntax pass. This is more logical and makes the code easier to work with. There are now some changes I will (probably) be making:

    • Only add the docs for exported functions and macros. I don't think module internal stuff should leak out.
    • I still think we should only add and save the argument patterns for functions and macros which have documentation.

    Now we just need some interface functions for accessing and printing the data and we are done.

  6. yurrriq commented on Apr 23, 2016

    @yurrriq
    Contributor

    FWIW Codox handles undocumented, but public, definitions, similar to how we're doing it now. Perhaps there's a way we can ignore definitions generated by the compiler, e.g. L-E-E-M, and those that come from an include-lib or include-file. Is that feasible/agreeable?

  7. rvirding commented on Apr 23, 2016

    @rvirding
    MemberAuthor

    OK, I will leave it as it is for the exported public functions and macros but not include the internal ones. And I will include the argument documentation even if there is no user docs. I make sure all the automatically generated functions and macros are not documented.

    I will add a simple interface in the REPL, I had a an idea that that would also handle elixir documentation as well. Just to poke them a bit that we can use theirs. :-)

  8. yurrriq commented on Apr 23, 2016

    @yurrriq
    Contributor

    I've started messing around here.

  9. rvirding commented on Apr 23, 2016

    @rvirding
    MemberAuthor

    OK, you work on that end of the problem while I do the compiler end and we can merge it into core LFE and call it from the REPL.

  10. yurrriq commented on Apr 23, 2016

    @yurrriq
    Contributor

    Should it be written in Erlang instead of LFE? Maybe it should live in lfe_doc.

  11. yurrriq commented on Apr 23, 2016

    @yurrriq
    Contributor

    Note that the pattern-formatting hack for forms like ``(,x . ,xs)is still needed even after moving thedo_docs` pass.

  12. rvirding commented on Apr 23, 2016

    @rvirding
    MemberAuthor

    I don't think so as they should all be expanded with the macros, the `` , ,@` are actually macros. Lint doesn't see them anyway. This should make it easier to do the pattern checking as well as you know that the patterns are all correct, even in the macros, at least those which have been used.

  13. yurrriq commented on Apr 23, 2016

    @yurrriq
    Contributor

    Maybe I had a stale copy of LFE in my _build. I'll clear out and try again.

    Update: Confirmed.

    From the example output in my comment on #228:

    tricky/255
     ((x) (x y) (x y . z))
     This is a tricky varargs macro.
    
  14. yurrriq commented on Apr 23, 2016

    @yurrriq
    Contributor

    Did we decide on a name? I like doc/{1,3} (as it is currently in my ldoc repo), but there's been talk of help or describe too. My idea is to support ({{name}} m f a) as well as ({{name}}} #(m f a)) and perhaps alternatives without arity as I've written some search functionality. We could do one with just module too. Thoughts?

    cc: @rvirding @oubiwann @arpunk

    See also: #67 #115

  15. oubiwann commented on Apr 24, 2016

    @oubiwann
    Member

    doc is Clojure and describe is CL; we could have both, one as an alias ...

  16. rvirding commented on Apr 24, 2016

    @rvirding
    MemberAuthor

    OK, I am working on just saving the exported functions and macros. I seriously wonder if macros should have number of arguments. Basically they just get a list of arguments which can be matched in any way. Maybe either ignore the arity field for macros in #doc{} or drop it completely and make the name field be {Name,Arity} for functions and just Name for macros.

  17. yurrriq commented on Apr 26, 2016

    @yurrriq
    Contributor

    Update: Now we're only saving exported definitions and macros don't have arity, e.g.

    #doc{type = macro, name = mymacro, ...}.
    
    #doc{type = function, name = {myfunc, 2}, ...}.

    I think we can safely remove the exported field now too, as it will always be true.

  18. rvirding commented on Apr 26, 2016

    @rvirding
    MemberAuthor

    No I think we should leave it. You mentioned a private-docs flag for the compiler which would also generate the documentation for private files. For that we need to keep track of which is which. I am making some small changes to the lfe_doc API which will allow this later if we wish.

  19. yurrriq commented on Apr 26, 2016

    @yurrriq
    Contributor

    Ah, yes. Good point.

  20. yurrriq commented on May 17, 2016

    @yurrriq
    Contributor

    Pasting the snippet for metadata syntax from Slack:

    (define-function ->binary
      ;; implicit 'meta'
      ((spec ((list)   binary)
             ((binary) binary))
       (abritary true)
      ;; position of (doc ...) doesn't matter
       (doc "Given a string or a binary, return a binary.")
       (something else))
      (match-lambda
        ([str] (when (is_list str))
         (unicode:characters_to_binary str 'utf8 'utf8))
        ([bin]
         bin)))
    
    (defun adder (x y)
      "Add x and y."
      (+ x y))
    
    ;; is equivalent to
    
    (define-function adder
      ((doc "Add x and y."))
      (lambda (x y) (+ x y)))

    Users can also specify multiline docstrings as follows:

    (define-function divider
      ((doc "first line"
            "second line"
            ...))
      (lambda (x y) (- x y)))

    which will result in:

    #doc{doc=<<"first line\nsecond line">>}
  21. oubiwann commented on Oct 14, 2020

    @oubiwann
    Member

    Robert has since re-worked the docs code in LFE.

    Closing ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions