-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rst: add missing line/column info for some warnings #18383
Conversation
lib/packages/docutils/rstast.nim
Outdated
@@ -77,6 +77,11 @@ type | |||
|
|||
PRstNode* = ref RstNode ## an RST node | |||
RstNodeSeq* = seq[PRstNode] | |||
PRstLocation* = ref object ## location inside a file | |||
filename*: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would try to reuse the TLineInfo
mechanism.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see also NimLineInfo
refs nim-lang/RFCs#387
lib/packages/docutils/rst.nim
Outdated
if fid.int < files.len: | ||
result = files[fid.int] | ||
else: | ||
result = "input" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is input
used for? is that same as compiler/msgs.nim:177:3: commandLineDesc* = "command line"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a fallback value, it should not happen. Alternatively a ValueError can be raised here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it shouldn't happen than maybe use doAssert? (ie indicates program logic bug, not user error)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, switched to doAssert
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and doAssert caught a bug :-)
rnRef | ||
rnLeaf 'brokenLink' | ||
""") | ||
removeFile("other.rst") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- not DRY
- bad style to write in the source tree and with a generic name (eg what if you ^C testament and are left with un-clean git status, or worse, it overwrites another test file)
- instead use either:
import stdtest/specialpaths
const tmpFile = buildDir / "D20210706T170748.rst"
or createTempFile
from std/tempfiles
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copy pasted it from this very file. Let us postpone it for trst.nim
refactoring PR.
Co-authored-by: Timothee Cour <[email protected]>
Co-authored-by: Timothee Cour <[email protected]>
Co-authored-by: Timothee Cour <[email protected]>
Co-authored-by: Timothee Cour <[email protected]>
fe74530
to
e8ede97
Compare
also display errors/warnings properly when footnote references are from different files
doAssert "<h2 id=\"another2\">Another2</h2>" in output10 | ||
doAssert "<h3 id=\"more3\"><center>More3</center></h3>" in output10 | ||
|
||
doAssert "<h1 id=\"level1\"><center>Level1</center></h1>" in output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about using triple quoted strings instead so that it's easier to copy paste without quoting, eg:
doAssert "<h1 id=\"level1\"><center>Level1</center></h1>" in output
=>
doAssert """<h1 id="level1"><center>Level1</center></h1>""" in output
can be done in separate PR though
it could even be written as:
for line in """
<h1 id="level1"><center>Level1</center></h1>
<h2 id="level2">Level2</h2>
...
""":
doAssert line in output
if you want to maintain ordering there's also testutils.greedyOrderedSubsetLines
rstGenera.renderRstToOut(rst, output) | ||
doAssert rstGenera.meta[metaTitle] == "Title0" | ||
doAssert rstGenera.meta[metaSubTitle] == "" | ||
doAssert output == |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use multiline literal instead (can be done in separate PR)
@@ -628,7 +630,7 @@ let x = 1 | |||
let p2 = """<p>Par2 <tt class="docutils literal"><span class="pre">value2</span></tt>.</p>""" | |||
let p3 = """<p>Par3 <tt class="docutils literal"><span class="pre">""" & id"value3" & "</span></tt>.</p>" | |||
let p4 = """<p>Par4 <tt class="docutils literal"><span class="pre">value4</span></tt>.</p>""" | |||
let expected = p1 & p2 & "\n" & p3 & "\n" & p4 & "\n" | |||
let expected = p1 & p2 & "\n" & p3 & "\n" & p4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, multiline literal is much clearer than concatenating like this
"extra arguments were given to number-lines: ' let a = 1'") | ||
check "" == output | ||
|
||
test "code-block warning": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a blocker because the situation after this PR improves in all cases, but the line numbers and columns are off by ~1 for nested doc comments, eg:
before PR: all lines/cols are 1 (useless)
after PR: main3 is correct, main1 and main2 are off by ~1
proc main1*()=
##[
.. code:: Nim
:unsupportedField: anything
.. code:: unsupportedLang
anything
```anotherLang
someCode
```
]##
discard
proc main2*()=
##[
.. code:: Nim
:unsupportedField: anything
.. code:: unsupportedLang
anything
```anotherLang
someCode
```
]##
discard
proc main3*()=
## .. code:: Nim
## :unsupportedField: anything
## .. code:: unsupportedLang
## anything
## ```anotherLang
## someCode
## ```
discard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, line info is saved only for first #
of ##
, not for real comment inside.
We talked about this problem in timotheecour#658
lib/packages/docutils/rst.nim
Outdated
footnotes: seq[FootnoteSubst] # correspondence b/w footnote label, | ||
# number, order of occurrence | ||
msgHandler: MsgHandler # How to handle errors. | ||
findFile: FindFileHandler # How to find files. | ||
filename: string | ||
filenames*: seq[string] # map FileIndex -> file name (for storing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it's a map, shouldn't this be a Table? this would also simplify setCurrFilename , getFilename etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with both ways, readability is the same.
seq[string]
should be faster for typical cases when there is only 1 fileTable
will be faster when there is >~ 10 files included
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think performance is any concern here (not a bottleneck), but it seemed to me Table would simplify code, but again, can be deferred to future work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, remaining comments are not critical and can be addressed in a followup PR so that this PR doesn't bitrot
Co-authored-by: Timothee Cour <[email protected]>
Co-authored-by: Timothee Cour <[email protected]>
Co-authored-by: Timothee Cour <[email protected]>
Co-authored-by: Timothee Cour <[email protected]>
Error: cannot prove that it's safe to initialize 'info' with the runtime value for the discriminator 'kind'
Co-authored-by: Timothee Cour <[email protected]>
Co-authored-by: Timothee Cour <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still LGTM (remaing comments can be addressed in followup PR)
* 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 <[email protected]> * Update compiler/docgen.nim Co-authored-by: Timothee Cour <[email protected]> * Update lib/packages/docutils/rst.nim Co-authored-by: Timothee Cour <[email protected]> * address review - stylistic things * Update compiler/docgen.nim Co-authored-by: Timothee Cour <[email protected]> * 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 <[email protected]> * Update lib/packages/docutils/rstast.nim Co-authored-by: Timothee Cour <[email protected]> * Update lib/packages/docutils/rstast.nim Co-authored-by: Timothee Cour <[email protected]> * Update lib/packages/docutils/rstast.nim Co-authored-by: Timothee Cour <[email protected]> * 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 <[email protected]> * apply suggestion * Update lib/packages/docutils/rst.nim Co-authored-by: Timothee Cour <[email protected]> * add Table for string->file name mapping * do not import compiler/lineinfos * fix ambiguous calls Co-authored-by: Timothee Cour <[email protected]> Co-authored-by: narimiran <[email protected]>
Some rst node types are post-processed after parsing, that is in either
resolveSubs
or inrstgen.nim
, while lines/columns are stored only in tokens during parsing stage. There was no way to print proper line/column for the corresponding warnings or errors. Now for all those 7 node kinds the line/column info is saved in a dedicated fieldPRstNode.loc
.Fixes bug 8 from #17340 .