Make rstgen work with gcsafe (#20534)
* Make rstgen work with gcsafe Co-authored-by: Danil Yarantsev <tiberiumk12@gmail.com> * add tests and fixes * if nimHasWarningAsError Co-authored-by: Danil Yarantsev <tiberiumk12@gmail.com>
This commit is contained in:
parent
1f2075042b
commit
e290b028ab
6 changed files with 18 additions and 9 deletions
|
|
@ -333,7 +333,7 @@ proc newDocumentor*(filename: AbsoluteFile; cache: IdentCache; conf: ConfigRef,
|
||||||
result.jEntriesFinal = newJArray()
|
result.jEntriesFinal = newJArray()
|
||||||
initStrTable result.types
|
initStrTable result.types
|
||||||
result.onTestSnippet =
|
result.onTestSnippet =
|
||||||
proc (gen: var RstGenerator; filename, cmd: string; status: int; content: string) =
|
proc (gen: var RstGenerator; filename, cmd: string; status: int; content: string) {.gcsafe.} =
|
||||||
if conf.docCmd == docCmdSkip: return
|
if conf.docCmd == docCmdSkip: return
|
||||||
inc(gen.id)
|
inc(gen.id)
|
||||||
var d = (ptr TDocumentor)(addr gen)
|
var d = (ptr TDocumentor)(addr gen)
|
||||||
|
|
@ -1732,7 +1732,7 @@ proc commandJson*(cache: IdentCache, conf: ConfigRef) =
|
||||||
if ast == nil: return
|
if ast == nil: return
|
||||||
var d = newDocumentor(conf.projectFull, cache, conf, hasToc = true)
|
var d = newDocumentor(conf.projectFull, cache, conf, hasToc = true)
|
||||||
d.onTestSnippet = proc (d: var RstGenerator; filename, cmd: string;
|
d.onTestSnippet = proc (d: var RstGenerator; filename, cmd: string;
|
||||||
status: int; content: string) =
|
status: int; content: string) {.gcsafe.} =
|
||||||
localError(conf, newLineInfo(conf, AbsoluteFile d.filename, -1, -1),
|
localError(conf, newLineInfo(conf, AbsoluteFile d.filename, -1, -1),
|
||||||
warnUser, "the ':test:' attribute is not supported by this backend")
|
warnUser, "the ':test:' attribute is not supported by this backend")
|
||||||
generateJson(d, ast)
|
generateJson(d, ast)
|
||||||
|
|
@ -1755,7 +1755,7 @@ proc commandTags*(cache: IdentCache, conf: ConfigRef) =
|
||||||
if ast == nil: return
|
if ast == nil: return
|
||||||
var d = newDocumentor(conf.projectFull, cache, conf, hasToc = true)
|
var d = newDocumentor(conf.projectFull, cache, conf, hasToc = true)
|
||||||
d.onTestSnippet = proc (d: var RstGenerator; filename, cmd: string;
|
d.onTestSnippet = proc (d: var RstGenerator; filename, cmd: string;
|
||||||
status: int; content: string) =
|
status: int; content: string) {.gcsafe.} =
|
||||||
localError(conf, newLineInfo(conf, AbsoluteFile d.filename, -1, -1),
|
localError(conf, newLineInfo(conf, AbsoluteFile d.filename, -1, -1),
|
||||||
warnUser, "the ':test:' attribute is not supported by this backend")
|
warnUser, "the ':test:' attribute is not supported by this backend")
|
||||||
var
|
var
|
||||||
|
|
|
||||||
|
|
@ -504,7 +504,7 @@ proc formatMsg*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string): s
|
||||||
conf.toFileLineCol(info) & " " & title & getMessageStr(msg, arg)
|
conf.toFileLineCol(info) & " " & title & getMessageStr(msg, arg)
|
||||||
|
|
||||||
proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
|
proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
|
||||||
eh: TErrorHandling, info2: InstantiationInfo, isRaw = false) {.noinline.} =
|
eh: TErrorHandling, info2: InstantiationInfo, isRaw = false) {.gcsafe, noinline.} =
|
||||||
var
|
var
|
||||||
title: string
|
title: string
|
||||||
color: ForegroundColor
|
color: ForegroundColor
|
||||||
|
|
|
||||||
|
|
@ -34,3 +34,7 @@ define:useStdoutAsStdmsg
|
||||||
experimental:strictEffects
|
experimental:strictEffects
|
||||||
warningAsError:Effect:on
|
warningAsError:Effect:on
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@if nimHasWarningAsError:
|
||||||
|
warningAsError:GcUnsafe2:on
|
||||||
|
@end
|
||||||
|
|
|
||||||
|
|
@ -395,7 +395,7 @@ type
|
||||||
suggestVersion*: int
|
suggestVersion*: int
|
||||||
suggestMaxResults*: int
|
suggestMaxResults*: int
|
||||||
lastLineInfo*: TLineInfo
|
lastLineInfo*: TLineInfo
|
||||||
writelnHook*: proc (output: string) {.closure.} # cannot make this gcsafe yet because of Nimble
|
writelnHook*: proc (output: string) {.closure, gcsafe.}
|
||||||
structuredErrorHook*: proc (config: ConfigRef; info: TLineInfo; msg: string;
|
structuredErrorHook*: proc (config: ConfigRef; info: TLineInfo; msg: string;
|
||||||
severity: Severity) {.closure, gcsafe.}
|
severity: Severity) {.closure, gcsafe.}
|
||||||
cppCustomNamespace*: string
|
cppCustomNamespace*: string
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ type
|
||||||
## for hyperlinks. See renderIndexTerm proc for details.
|
## for hyperlinks. See renderIndexTerm proc for details.
|
||||||
id*: int ## A counter useful for generating IDs.
|
id*: int ## A counter useful for generating IDs.
|
||||||
onTestSnippet*: proc (d: var RstGenerator; filename, cmd: string; status: int;
|
onTestSnippet*: proc (d: var RstGenerator; filename, cmd: string; status: int;
|
||||||
content: string)
|
content: string) {.gcsafe.}
|
||||||
escMode*: EscapeMode
|
escMode*: EscapeMode
|
||||||
curQuotationDepth: int
|
curQuotationDepth: int
|
||||||
|
|
||||||
|
|
@ -283,7 +283,7 @@ proc dispA(target: OutputTarget, dest: var string,
|
||||||
proc `or`(x, y: string): string {.inline.} =
|
proc `or`(x, y: string): string {.inline.} =
|
||||||
result = if x.len == 0: y else: x
|
result = if x.len == 0: y else: x
|
||||||
|
|
||||||
proc renderRstToOut*(d: var RstGenerator, n: PRstNode, result: var string)
|
proc renderRstToOut*(d: var RstGenerator, n: PRstNode, result: var string) {.gcsafe.}
|
||||||
## Writes into ``result`` the rst ast ``n`` using the ``d`` configuration.
|
## Writes into ``result`` the rst ast ``n`` using the ``d`` configuration.
|
||||||
##
|
##
|
||||||
## Before using this proc you need to initialise a ``RstGenerator`` with
|
## Before using this proc you need to initialise a ``RstGenerator`` with
|
||||||
|
|
@ -1028,7 +1028,7 @@ proc renderCodeLang*(result: var string, lang: SourceLanguage, code: string,
|
||||||
proc renderNimCode*(result: var string, code: string, target: OutputTarget) =
|
proc renderNimCode*(result: var string, code: string, target: OutputTarget) =
|
||||||
renderCodeLang(result, langNim, code, target)
|
renderCodeLang(result, langNim, code, target)
|
||||||
|
|
||||||
proc renderCode(d: PDoc, n: PRstNode, result: var string) =
|
proc renderCode(d: PDoc, n: PRstNode, result: var string) {.gcsafe.} =
|
||||||
## Renders a code (code block or inline code), appending it to `result`.
|
## Renders a code (code block or inline code), appending it to `result`.
|
||||||
##
|
##
|
||||||
## If the code block uses the ``number-lines`` option, a table will be
|
## If the code block uses the ``number-lines`` option, a table will be
|
||||||
|
|
@ -1592,7 +1592,7 @@ $content
|
||||||
|
|
||||||
proc rstToHtml*(s: string, options: RstParseOptions,
|
proc rstToHtml*(s: string, options: RstParseOptions,
|
||||||
config: StringTableRef,
|
config: StringTableRef,
|
||||||
msgHandler: MsgHandler = rst.defaultMsgHandler): string =
|
msgHandler: MsgHandler = rst.defaultMsgHandler): string {.gcsafe.} =
|
||||||
## Converts an input rst string into embeddable HTML.
|
## Converts an input rst string into embeddable HTML.
|
||||||
##
|
##
|
||||||
## This convenience proc parses any input string using rst markup (it doesn't
|
## This convenience proc parses any input string using rst markup (it doesn't
|
||||||
|
|
|
||||||
|
|
@ -1684,3 +1684,8 @@ suite "local file inclusion":
|
||||||
discard "```nim file = ./readme.md\n```".toHtml(error=error)
|
discard "```nim file = ./readme.md\n```".toHtml(error=error)
|
||||||
check(error[] == "input(1, 23) Error: disabled directive: 'file'")
|
check(error[] == "input(1, 23) Error: disabled directive: 'file'")
|
||||||
|
|
||||||
|
proc documentToHtml*(doc: string, isMarkdown: bool = false): string {.gcsafe.} =
|
||||||
|
var options = {roSupportMarkdown}
|
||||||
|
if isMarkdown:
|
||||||
|
options.incl roPreferMarkdown
|
||||||
|
result = rstToHtml(doc, options, defaultConfig())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue