timotheecour / Nim

Nim is a compiled, garbage-collected systems programming language with a design that focuses on efficiency, expressiveness, and elegance (in that order of priority).
http://nim-lang.org/
Other
2 stars 0 forks source link

DocGen Regression inline proc doc #784

Closed juancarlospaco closed 2 years ago

juancarlospaco commented 2 years ago
$ cat example.nim
func example*(): int = 42  ## DOCUMENTATION HERE!.

$ choosenim 1.2.0
$ nim doc example.nim

temp0

$ choosenim devel
$ nim doc example.nim

temp1

DocGen completely removes documentation, single-line proc is useful for FFI purposes (importjs, importc, etc).

/cc @a-mr

timotheecour commented 2 years ago

I see; this is intimately tied to https://github.com/nim-lang/RFCs/issues/231; the problem is that the spec for placement of doc comments/runnableExamples is not well specified.

unclear what the right approach is here, if you consider other examples:

proc fn* =
  ## foo
  echo 1
  ## bar <= should this be part of doc comment? if not, what's the correct algorithm to decide?
juancarlospaco commented 2 years ago

Python takes 1 string on the first line of the body of the function, string can be multi-line, if it is placed elsewere it is always ignored.

I am Ok with whatever is choosed as standard, but better to choose a standard way of doing it. 🙂

a-mr commented 2 years ago

what's the correct algorithm to decide?

Suggestion: if the line of equal sign = is N then any doc comment starting on N or N+1 is good. So this is also correct:

func example*(): int = 42
  ## DOCUMENTATION HERE!.

This is not correct:

func example*(): int =
  42
  ## BAD
timotheecour commented 2 years ago

Suggestion: if the line of equal sign = is N then any doc comment starting on N or N+1 is good. So this is also correct:

sounds reasonable; can you write a PR?

juancarlospaco commented 2 years ago

So single line proc doc will not work anymore?.

a-mr commented 2 years ago

@juancarlospaco , it will work if the suggestion gets applied because equal sign is on the same line as doc comment.

a-mr commented 2 years ago

@timotheecour ,

There may be another problem here: I don't see a doc comment saved in AST tree in the case of same-line doc comment (example 1 below):

dumpTree:
  func example1*(): int = 42  ## DOCUMENTATION HERE!.
  func example2*(): int =
    ## DOCUMENTATION HERE!.
    43
  func example3*(): int =
    44
    ## DOCUMENTATION HERE!.
StmtList
  FuncDef
    Postfix
      Ident "*"
      Ident "example1"
    Empty
    Empty
    FormalParams
      Ident "int"
    Empty
    Empty
    StmtList
      IntLit 42
  FuncDef
    Postfix
      Ident "*"
      Ident "example2"
    Empty
    Empty
    FormalParams
      Ident "int"
    Empty
    Empty
    StmtList
      CommentStmt "DOCUMENTATION HERE!."
      IntLit 43
  FuncDef
    Postfix
      Ident "*"
      Ident "example3"
    Empty
    Empty
    FormalParams
      Ident "int"
    Empty
    Empty
    StmtList
      IntLit 44
      CommentStmt "DOCUMENTATION HERE!."

Also I doubt that position of equal sign is saved...

timotheecour commented 2 years ago

some more info:

func example6*(a: int): int = a runnableExamples: let x = 1

juancarlospaco commented 2 years ago

If you think is not a bug, because they never worked reliably, feel free to close no problem.

timotheecour commented 2 years ago

If you think is not a bug, because they never worked reliably, feel free to close no problem.

I never said that :) things should improve regardless of whether they worked reliably in past or not

timotheecour commented 2 years ago

=> PR https://github.com/nim-lang/Nim/pull/18595