Skip to content

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

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

Merged
merged 29 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f7fa825
rst: add missing line/column info for some warnings
a-mr Jun 28, 2021
e64c7fb
add workaround
a-mr Jun 28, 2021
af49d7b
use TLineInfo/FileIndex for storing file names
a-mr Jul 2, 2021
1b31d61
fix blank lines in include file (rm harmful strip)
a-mr Jul 2, 2021
80cafde
don't use ref TLineInfo
a-mr Jul 3, 2021
ce5de16
return `hasToc` as output parameter for uniformity
a-mr Jul 6, 2021
ed47dbd
Update compiler/docgen.nim
a-mr Jul 7, 2021
cf27ed9
Update compiler/docgen.nim
a-mr Jul 7, 2021
19fa19e
Update lib/packages/docutils/rst.nim
a-mr Jul 7, 2021
b361cd3
address review - stylistic things
a-mr Jul 7, 2021
4d20a5f
Update compiler/docgen.nim
a-mr Jul 7, 2021
d13c14d
unify RST warnings/errors names
a-mr Jul 7, 2021
98b4d0d
doAssert + minor name change
a-mr Jul 8, 2021
1e633aa
fix a bug caught by doAssert
a-mr Jul 8, 2021
f7bb08c
apply strbasics.strip to final HTML/Latex
a-mr Jul 8, 2021
ae2083b
rm redundant filename
a-mr Jul 10, 2021
e8ede97
fix test after rebase
a-mr Jul 11, 2021
f784222
delete `order` from rnFootnoteRef,
a-mr Jul 15, 2021
b56d6c0
Update compiler/lineinfos.nim
a-mr Jul 15, 2021
22c254d
Update lib/packages/docutils/rstast.nim
a-mr Jul 15, 2021
a0a9ae1
Update lib/packages/docutils/rstast.nim
a-mr Jul 15, 2021
d52ce1f
Update lib/packages/docutils/rstast.nim
a-mr Jul 15, 2021
12dde3d
revert because of error:
a-mr Jul 15, 2021
769d367
Update lib/packages/docutils/rstgen.nim
a-mr Jul 15, 2021
4c5dc1c
apply suggestion
a-mr Jul 15, 2021
209c72e
Update lib/packages/docutils/rst.nim
a-mr Jul 15, 2021
3d5f903
add Table for string->file name mapping
a-mr Jul 17, 2021
cc0df0b
do not import compiler/lineinfos
narimiran Jul 19, 2021
9c709be
fix ambiguous calls
narimiran Jul 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions compiler/docgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

import
ast, strutils, strtabs, options, msgs, os, idents,
wordrecg, syntaxes, renderer, lexer, packages/docutils/rstast,
wordrecg, syntaxes, renderer, lexer,
packages/docutils/rst, packages/docutils/rstgen,
json, xmltree, trees, types,
typesrenderer, astalgo, lineinfos, intsets,
pathutils, tables, nimpaths, renderverbatim, osproc
import packages/docutils/rstast except FileIndex, TLineInfo

from uri import encodeUrl
from std/private/globs import nativeToUnixPath
Expand Down Expand Up @@ -159,17 +160,18 @@ template declareClosures =
case msgKind
of meCannotOpenFile: k = errCannotOpenFile
of meExpected: k = errXExpected
of meGridTableNotImplemented: k = errGridTableNotImplemented
of meMarkdownIllformedTable: k = errMarkdownIllformedTable
of meNewSectionExpected: k = errNewSectionExpected
of meGeneralParseError: k = errGeneralParseError
of meInvalidDirective: k = errInvalidDirectiveX
of meInvalidRstField: k = errInvalidRstField
of meFootnoteMismatch: k = errFootnoteMismatch
of mwRedefinitionOfLabel: k = warnRedefinitionOfLabel
of mwUnknownSubstitution: k = warnUnknownSubstitutionX
of mwUnsupportedLanguage: k = warnLanguageXNotSupported
of mwUnsupportedField: k = warnFieldXNotSupported
of meGridTableNotImplemented: k = errRstGridTableNotImplemented
of meMarkdownIllformedTable: k = errRstMarkdownIllformedTable
of meNewSectionExpected: k = errRstNewSectionExpected
of meGeneralParseError: k = errRstGeneralParseError
of meInvalidDirective: k = errRstInvalidDirectiveX
of meInvalidField: k = errRstInvalidField
of meFootnoteMismatch: k = errRstFootnoteMismatch
of mwRedefinitionOfLabel: k = warnRstRedefinitionOfLabel
of mwUnknownSubstitution: k = warnRstUnknownSubstitutionX
of mwBrokenLink: k = warnRstBrokenLink
of mwUnsupportedLanguage: k = warnRstLanguageXNotSupported
of mwUnsupportedField: k = warnRstFieldXNotSupported
of mwRstStyle: k = warnRstStyle
{.gcsafe.}:
globalError(conf, newLineInfo(conf, AbsoluteFile filename, line, col), k, arg)
Expand All @@ -182,11 +184,9 @@ template declareClosures =

proc parseRst(text, filename: string,
line, column: int,
rstOptions: RstParseOptions;
conf: ConfigRef, sharedState: PRstSharedState): PRstNode =
declareClosures()
result = rstParsePass1(text, filename, line, column, rstOptions,
sharedState)
result = rstParsePass1(text, line, column, sharedState)

proc getOutFile2(conf: ConfigRef; filename: RelativeFile,
ext: string, guessTarget: bool): AbsoluteFile =
Expand All @@ -202,20 +202,22 @@ proc getOutFile2(conf: ConfigRef; filename: RelativeFile,
proc isLatexCmd(conf: ConfigRef): bool = conf.cmd in {cmdRst2tex, cmdDoc2tex}

proc newDocumentor*(filename: AbsoluteFile; cache: IdentCache; conf: ConfigRef,
outExt: string = HtmlExt, module: PSym = nil): PDoc =
outExt: string = HtmlExt, module: PSym = nil,
isPureRst = false): PDoc =
declareClosures()
new(result)
result.module = module
result.conf = conf
result.cache = cache
result.outDir = conf.outDir.string
const options = {roSupportRawDirective, roSupportMarkdown,
roPreferMarkdown, roNimFile}
result.isPureRst = isPureRst
var options= {roSupportRawDirective, roSupportMarkdown, roPreferMarkdown}
if not isPureRst: options.incl roNimFile
result.sharedState = newRstSharedState(
options, filename.string,
docgenFindFile, compilerMsgHandler)
initRstGenerator(result[], (if conf.isLatexCmd: outLatex else: outHtml),
conf.configVars, filename.string, options,
conf.configVars, filename.string,
docgenFindFile, compilerMsgHandler)

if conf.configVars.hasKey("doc.googleAnalytics"):
Expand Down Expand Up @@ -299,8 +301,7 @@ proc genComment(d: PDoc, n: PNode): PRstNode =
result = parseRst(n.comment, toFullPath(d.conf, n.info),
toLinenumber(n.info),
toColumn(n.info) + DocColOffset,
d.options, d.conf,
d.sharedState)
d.conf, d.sharedState)

proc genRecCommentAux(d: PDoc, n: PNode): PRstNode =
if n == nil: return nil
Expand Down Expand Up @@ -1132,6 +1133,9 @@ proc generateDoc*(d: PDoc, n, orig: PNode, docFlags: DocFlags = kDefault) =

proc finishGenerateDoc*(d: var PDoc) =
## Perform 2nd RST pass for resolution of links/footnotes/headings...
# copy file map `filenames` to ``rstgen.nim`` for its warnings
d.filenames = d.sharedState.filenames

# Main title/subtitle are allowed only in the first RST fragment of document
var firstRst = PRstNode(nil)
for fragment in d.modDescPre:
Expand Down Expand Up @@ -1426,14 +1430,10 @@ proc commandDoc*(cache: IdentCache, conf: ConfigRef) =
proc commandRstAux(cache: IdentCache, conf: ConfigRef;
filename: AbsoluteFile, outExt: string) =
var filen = addFileExt(filename, "txt")
var d = newDocumentor(filen, cache, conf, outExt)

d.isPureRst = true
var d = newDocumentor(filen, cache, conf, outExt, isPureRst = true)
let rst = parseRst(readFile(filen.string), filen.string,
line=LineRstInit, column=ColRstInit,
{roSupportRawDirective, roSupportMarkdown,
roPreferMarkdown}, conf,
d.sharedState)
conf, d.sharedState)
d.modDescPre = @[ItemFragment(isRst: true, rst: rst)]
finishGenerateDoc(d)
writeOutput(d)
Expand Down
49 changes: 27 additions & 22 deletions compiler/lineinfos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ type
# non-fatal errors
errIllFormedAstX, errCannotOpenFile,
errXExpected,
errGridTableNotImplemented,
errMarkdownIllformedTable,
errGeneralParseError,
errNewSectionExpected,
errInvalidDirectiveX,
errInvalidRstField,
errFootnoteMismatch,
errRstGridTableNotImplemented,
errRstMarkdownIllformedTable,
errRstNewSectionExpected,
errRstGeneralParseError,
errRstInvalidDirectiveX,
errRstInvalidField,
errRstFootnoteMismatch,
errProveInit, # deadcode
errGenerated,
errUser,
Expand All @@ -47,10 +47,13 @@ type
warnXIsNeverRead = "XIsNeverRead", warnXmightNotBeenInit = "XmightNotBeenInit",
warnDeprecated = "Deprecated", warnConfigDeprecated = "ConfigDeprecated",
warnSmallLshouldNotBeUsed = "SmallLshouldNotBeUsed", warnUnknownMagic = "UnknownMagic",
warnRedefinitionOfLabel = "RedefinitionOfLabel", warnUnknownSubstitutionX = "UnknownSubstitutionX",
warnLanguageXNotSupported = "LanguageXNotSupported",
warnFieldXNotSupported = "FieldXNotSupported",
warnRstStyle = "warnRstStyle", warnCommentXIgnored = "CommentXIgnored",
warnRstRedefinitionOfLabel = "RedefinitionOfLabel",
warnRstUnknownSubstitutionX = "UnknownSubstitutionX",
warnRstBrokenLink = "BrokenLink",
warnRstLanguageXNotSupported = "LanguageXNotSupported",
warnRstFieldXNotSupported = "FieldXNotSupported",
warnRstStyle = "warnRstStyle",
warnCommentXIgnored = "CommentXIgnored",
warnTypelessParam = "TypelessParam",
warnUseBase = "UseBase", warnWriteToForeignHeap = "WriteToForeignHeap",
warnUnsafeCode = "UnsafeCode", warnUnusedImportX = "UnusedImport",
Expand Down Expand Up @@ -93,13 +96,13 @@ const
errIllFormedAstX: "illformed AST: $1",
errCannotOpenFile: "cannot open '$1'",
errXExpected: "'$1' expected",
errGridTableNotImplemented: "grid table is not implemented",
errMarkdownIllformedTable: "illformed delimiter row of a markdown table",
errGeneralParseError: "general parse error",
errNewSectionExpected: "new section expected $1",
errInvalidDirectiveX: "invalid directive: '$1'",
errInvalidRstField: "invalid field: $1",
errFootnoteMismatch: "number of footnotes and their references don't match: $1",
errRstGridTableNotImplemented: "grid table is not implemented",
errRstMarkdownIllformedTable: "illformed delimiter row of a markdown table",
errRstNewSectionExpected: "new section expected $1",
errRstGeneralParseError: "general parse error",
errRstInvalidDirectiveX: "invalid directive: '$1'",
errRstInvalidField: "invalid field: $1",
errRstFootnoteMismatch: "number of footnotes and their references don't match: $1",
errProveInit: "Cannot prove that '$1' is initialized.", # deadcode
errGenerated: "$1",
errUser: "$1",
Expand All @@ -111,10 +114,11 @@ const
warnConfigDeprecated: "config file '$1' is deprecated",
warnSmallLshouldNotBeUsed: "'l' should not be used as an identifier; may look like '1' (one)",
warnUnknownMagic: "unknown magic '$1' might crash the compiler",
warnRedefinitionOfLabel: "redefinition of label '$1'",
warnUnknownSubstitutionX: "unknown substitution '$1'",
warnLanguageXNotSupported: "language '$1' not supported",
warnFieldXNotSupported: "field '$1' not supported",
warnRstRedefinitionOfLabel: "redefinition of label '$1'",
warnRstUnknownSubstitutionX: "unknown substitution '$1'",
warnRstBrokenLink: "broken link '$1'",
warnRstLanguageXNotSupported: "language '$1' not supported",
warnRstFieldXNotSupported: "field '$1' not supported",
warnRstStyle: "RST style: $1",
warnCommentXIgnored: "comment '$1' ignored",
warnTypelessParam: "", # deadcode
Expand Down Expand Up @@ -196,6 +200,7 @@ const
warnMax* = pred(hintSuccess)
hintMin* = hintSuccess
hintMax* = high(TMsgKind)
rstWarnings* = {warnRstRedefinitionOfLabel..warnRstStyle}

type
TNoteKind* = range[warnMin..hintMax] # "notes" are warnings or hints
Expand Down
11 changes: 4 additions & 7 deletions compiler/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ proc mainCommand*(graph: ModuleGraph) =
of cmdDoc:
docLikeCmd():
conf.setNoteDefaults(warnLockLevel, false) # issue #13218
conf.setNoteDefaults(warnRedefinitionOfLabel, false) # issue #13218
conf.setNoteDefaults(warnRstRedefinitionOfLabel, false) # issue #13218
# because currently generates lots of false positives due to conflation
# of labels links in doc comments, e.g. for random.rand:
# ## * `rand proc<#rand,Rand,Natural>`_ that returns an integer
Expand All @@ -295,19 +295,16 @@ proc mainCommand*(graph: ModuleGraph) =
commandBuildIndex(conf, $conf.outDir)
of cmdRst2html:
# XXX: why are warnings disabled by default for rst2html and rst2tex?
for warn in [warnUnknownSubstitutionX, warnLanguageXNotSupported,
warnFieldXNotSupported, warnRstStyle]:
for warn in rstWarnings:
conf.setNoteDefaults(warn, true)
conf.setNoteDefaults(warnRedefinitionOfLabel, false) # similar to issue #13218
conf.setNoteDefaults(warnRstRedefinitionOfLabel, false) # similar to issue #13218
when defined(leanCompiler):
conf.quitOrRaise "compiler wasn't built with documentation generator"
else:
loadConfigs(DocConfig, cache, conf, graph.idgen)
commandRst2Html(cache, conf)
of cmdRst2tex, cmdDoc2tex:
for warn in [warnRedefinitionOfLabel, warnUnknownSubstitutionX,
warnLanguageXNotSupported,
warnFieldXNotSupported, warnRstStyle]:
for warn in rstWarnings:
conf.setNoteDefaults(warn, true)
when defined(leanCompiler):
conf.quitOrRaise "compiler wasn't built with documentation generator"
Expand Down
Loading