Add comments explaining comment node procs
This commit is contained in:
parent
4f1464bdfb
commit
c8c2efdc30
1 changed files with 18 additions and 4 deletions
|
|
@ -639,6 +639,8 @@ proc getNameKind*(name: string): tuple[name: string, kind: Kind, recursive: bool
|
||||||
result.name = result.name[0 .. ^2]
|
result.name = result.name[0 .. ^2]
|
||||||
|
|
||||||
proc getCommentsStr*(gState: State, commentNodes: seq[TSNode]): string =
|
proc getCommentsStr*(gState: State, commentNodes: seq[TSNode]): string =
|
||||||
|
## Generate a comment from a set of comment nodes. Comment is guaranteed
|
||||||
|
## to be able to be rendered using nim doc
|
||||||
if commentNodes.len > 0:
|
if commentNodes.len > 0:
|
||||||
result = "::"
|
result = "::"
|
||||||
for commentNode in commentNodes:
|
for commentNode in commentNodes:
|
||||||
|
|
@ -650,25 +652,37 @@ proc getPrevCommentNodes*(node: TSNode, maxSearch=1): seq[TSNode] =
|
||||||
## section
|
## section
|
||||||
var sibling = node.tsNodePrevNamedSibling()
|
var sibling = node.tsNodePrevNamedSibling()
|
||||||
var i = 0
|
var i = 0
|
||||||
|
|
||||||
|
# Search for the starting comment up to maxSearch nodes away
|
||||||
while not sibling.isNil and i < maxSearch:
|
while not sibling.isNil and i < maxSearch:
|
||||||
|
# Once a comment is found, find all of the comments right next to
|
||||||
|
# it so that we can get multiple // style comments
|
||||||
while not sibling.isNil and sibling.getName() == "comment":
|
while not sibling.isNil and sibling.getName() == "comment":
|
||||||
result.add(sibling)
|
result.add(sibling)
|
||||||
sibling = sibling.tsNodePrevNamedSibling()
|
sibling = sibling.tsNodePrevNamedSibling()
|
||||||
|
|
||||||
if sibling.isNil:
|
if sibling.isNil:
|
||||||
result.reverse
|
break
|
||||||
return
|
|
||||||
sibling = sibling.tsNodePrevNamedSibling()
|
sibling = sibling.tsNodePrevNamedSibling()
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
# reverse the comments because we got them in reverse order
|
||||||
result.reverse
|
result.reverse
|
||||||
|
|
||||||
proc getNextCommentNodes*(node: TSNode, maxSearch=1): seq[TSNode] =
|
proc getNextCommentNodes*(node: TSNode, maxSearch=1): seq[TSNode] =
|
||||||
## We only want to search for the next comment node (ie: inline)
|
## Searches the next nodes up to maxSearch nodes away for a comment
|
||||||
|
|
||||||
|
# We only want to search for the next comment node (ie: inline)
|
||||||
|
# but we want to keep the same interface as getPrevCommentNodes,
|
||||||
|
# so we keep a returned seq but only store one element
|
||||||
var sibling = node.tsNodeNextNamedSibling()
|
var sibling = node.tsNodeNextNamedSibling()
|
||||||
var i = 0
|
var i = 0
|
||||||
|
# Search for the comment up to maxSearch nodes away
|
||||||
while not sibling.isNil and i < maxSearch:
|
while not sibling.isNil and i < maxSearch:
|
||||||
if sibling.getName() == "comment":
|
if sibling.getName() == "comment":
|
||||||
return @[sibling]
|
result.add sibling
|
||||||
|
break
|
||||||
sibling = sibling.tsNodeNextNamedSibling()
|
sibling = sibling.tsNodeNextNamedSibling()
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue