rst: add missing line/column info for some warnings (#18383)

* rst: add missing line/column info for some warnings

* add workaround

* use TLineInfo/FileIndex for storing file names

* fix blank lines in include file (rm harmful strip)

* don't use ref TLineInfo

* return `hasToc` as output parameter for uniformity

* Update compiler/docgen.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Update compiler/docgen.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Update lib/packages/docutils/rst.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* address review - stylistic things

* Update compiler/docgen.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* unify RST warnings/errors names

* doAssert + minor name change

* fix a bug caught by doAssert

* apply strbasics.strip to final HTML/Latex

* rm redundant filename

* fix test after rebase

* delete `order` from rnFootnoteRef,

also display errors/warnings properly when footnote references are from
different files

* Update compiler/lineinfos.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Update lib/packages/docutils/rstast.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Update lib/packages/docutils/rstast.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Update lib/packages/docutils/rstast.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* revert because of error:

Error: cannot prove that it's safe to initialize 'info' with the runtime value for the discriminator 'kind'

* Update lib/packages/docutils/rstgen.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* apply suggestion

* Update lib/packages/docutils/rst.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* add Table for string->file name mapping

* do not import compiler/lineinfos

* fix ambiguous calls

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
Co-authored-by: narimiran <narimiran@disroot.org>
This commit is contained in:
Andrey Makarov 2021-07-20 09:32:22 +03:00 • committed by GitHub
commit 8c7ee96457
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 342 additions and 193 deletions

View file

@ -74,6 +74,11 @@ type
rnLeaf # a leaf; the node's text field contains the
# leaf val
FileIndex* = distinct int32
TLineInfo* = object
line*: uint16
col*: int16
fileIndex*: FileIndex
PRstNode* = ref RstNode ## an RST node
RstNodeSeq* = seq[PRstNode]
@ -92,21 +97,32 @@ type
level*: int ## level of headings starting from 1 (main
## chapter) to larger ones (minor sub-sections)
## level=0 means it's document title or subtitle
of rnFootnote, rnCitation, rnFootnoteRef, rnOptionListItem:
of rnFootnote, rnCitation, rnOptionListItem:
order*: int ## footnote order (for auto-symbol footnotes and
## auto-numbered ones without a label)
of rnRef, rnSubstitutionReferences,
rnInterpretedText, rnField, rnInlineCode, rnCodeBlock, rnFootnoteRef:
info*: TLineInfo ## To have line/column info for warnings at
## nodes that are post-processed after parsing
else:
discard
anchor*: string ## anchor, internal link target
## (aka HTML id tag, aka Latex label/hypertarget)
sons*: RstNodeSeq ## the node's sons
proc `==`*(a, b: FileIndex): bool {.borrow.}
proc len*(n: PRstNode): int =
result = len(n.sons)
proc newRstNode*(kind: RstNodeKind, sons: seq[PRstNode] = @[],
anchor = ""): PRstNode =
result = PRstNode(kind: kind, sons: sons, anchor: anchor)
proc newRstNode*(kind: RstNodeKind, info: TLineInfo,
sons: seq[PRstNode] = @[]): PRstNode =
result = PRstNode(kind: kind, sons: sons)
result.info = info
proc newRstNode*(kind: RstNodeKind, s: string): PRstNode {.deprecated.} =
assert kind in {rnLeaf, rnSmiley}
@ -388,7 +404,7 @@ proc renderRstToStr*(node: PRstNode, indent=0): string =
result.add " adType=" & node.adType
of rnHeadline, rnOverline, rnMarkdownHeadline:
result.add " level=" & $node.level
of rnFootnote, rnCitation, rnFootnoteRef, rnOptionListItem:
of rnFootnote, rnCitation, rnOptionListItem:
result.add (if node.order == 0: "" else: " order=" & $node.order)
else:
discard