nimsuggest: bugfix: also output documentation comments
This commit is contained in:
parent
26fb6cb073
commit
76a28d8b83
4 changed files with 37 additions and 23 deletions
|
|
@ -209,26 +209,26 @@ proc getPlainDocstring(n: PNode): string =
|
||||||
result = getPlainDocstring(n.sons[i])
|
result = getPlainDocstring(n.sons[i])
|
||||||
if result.len > 0: return
|
if result.len > 0: return
|
||||||
|
|
||||||
|
when false:
|
||||||
|
proc findDocComment(n: PNode): PNode =
|
||||||
|
if n == nil: return nil
|
||||||
|
if not isNil(n.comment) and startsWith(n.comment, "##"): return n
|
||||||
|
for i in countup(0, safeLen(n)-1):
|
||||||
|
result = findDocComment(n.sons[i])
|
||||||
|
if result != nil: return
|
||||||
|
|
||||||
proc findDocComment(n: PNode): PNode =
|
proc extractDocComment*(s: PSym, d: PDoc = nil): string =
|
||||||
if n == nil: return nil
|
let n = findDocComment(s.ast)
|
||||||
if not isNil(n.comment) and startsWith(n.comment, "##"): return n
|
result = ""
|
||||||
for i in countup(0, safeLen(n)-1):
|
if not n.isNil:
|
||||||
result = findDocComment(n.sons[i])
|
if not d.isNil:
|
||||||
if result != nil: return
|
var dummyHasToc: bool
|
||||||
|
renderRstToOut(d[], parseRst(n.comment, toFilename(n.info),
|
||||||
proc extractDocComment*(s: PSym, d: PDoc = nil): string =
|
toLinenumber(n.info), toColumn(n.info),
|
||||||
let n = findDocComment(s.ast)
|
dummyHasToc, d.options + {roSkipPounds}),
|
||||||
result = ""
|
result)
|
||||||
if not n.isNil:
|
else:
|
||||||
if not d.isNil:
|
result = n.comment.substr(2).replace("\n##", "\n").strip
|
||||||
var dummyHasToc: bool
|
|
||||||
renderRstToOut(d[], parseRst(n.comment, toFilename(n.info),
|
|
||||||
toLinenumber(n.info), toColumn(n.info),
|
|
||||||
dummyHasToc, d.options + {roSkipPounds}),
|
|
||||||
result)
|
|
||||||
else:
|
|
||||||
result = n.comment.substr(2).replace("\n##", "\n").strip
|
|
||||||
|
|
||||||
proc isVisible(n: PNode): bool =
|
proc isVisible(n: PNode): bool =
|
||||||
result = false
|
result = false
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,20 @@ var
|
||||||
|
|
||||||
template origModuleName(m: PSym): string = m.name.s
|
template origModuleName(m: PSym): string = m.name.s
|
||||||
|
|
||||||
|
proc findDocComment(n: PNode): PNode =
|
||||||
|
if n == nil: return nil
|
||||||
|
if not isNil(n.comment): return n
|
||||||
|
for i in countup(0, safeLen(n)-1):
|
||||||
|
result = findDocComment(n.sons[i])
|
||||||
|
if result != nil: return
|
||||||
|
|
||||||
|
proc extractDocComment(s: PSym): string =
|
||||||
|
let n = findDocComment(s.ast)
|
||||||
|
if not n.isNil:
|
||||||
|
result = n.comment.replace("\n##", "\n").strip
|
||||||
|
else:
|
||||||
|
result = ""
|
||||||
|
|
||||||
proc symToSuggest(s: PSym, isLocal: bool, section: string, li: TLineInfo;
|
proc symToSuggest(s: PSym, isLocal: bool, section: string, li: TLineInfo;
|
||||||
quality: range[0..100]): Suggest =
|
quality: range[0..100]): Suggest =
|
||||||
result.section = parseIdeCmd(section)
|
result.section = parseIdeCmd(section)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
discard """
|
discard """
|
||||||
$nimsuggest --tester $file
|
$nimsuggest --tester $file
|
||||||
>def $1
|
>def $1
|
||||||
def;;skProc;;tdef1.hello;;proc ();;$file;;9;;5;;"";;100
|
def;;skProc;;tdef1.hello;;proc (): string{.noSideEffect, gcsafe, locks: 0.};;$file;;9;;5;;"Return hello";;100
|
||||||
>def $1
|
>def $1
|
||||||
def;;skProc;;tdef1.hello;;proc ();;$file;;9;;5;;"";;100
|
def;;skProc;;tdef1.hello;;proc (): string{.noSideEffect, gcsafe, locks: 0.};;$file;;9;;5;;"Return hello";;100
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc hello() string =
|
proc hello(): string =
|
||||||
## Return hello
|
## Return hello
|
||||||
"Hello"
|
"Hello"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
discard """
|
discard """
|
||||||
$nimsuggest --tester lib/pure/strutils.nim
|
$nimsuggest --tester lib/pure/strutils.nim
|
||||||
>def lib/pure/strutils.nim:2300:6
|
>def lib/pure/strutils.nim:2300:6
|
||||||
def;;skTemplate;;system.doAssert;;proc (cond: bool, msg: string): typed;;*/lib/system.nim;;*;;9;;"";;100
|
def;;skTemplate;;system.doAssert;;proc (cond: bool, msg: string): typed;;*/lib/system.nim;;*;;9;;"same as `assert` but is always turned on and not affected by the\x0A``--assertions`` command line switch.";;100
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Line 2300 in strutils.nim is doAssert and this is unlikely to change
|
# Line 2300 in strutils.nim is doAssert and this is unlikely to change
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue