add Source+Edit links on top of every docgend file (#15642)

This commit is contained in:
Timothee Cour 2020-10-22 01:44:28 -07:00 • committed by GitHub
commit 0979524137
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 23 deletions

View file

@ -12,6 +12,7 @@
## Compiler changes ## Compiler changes
add `--declaredlocs` to show symbol declaration location in messages add `--declaredlocs` to show symbol declaration location in messages
* Source+Edit links now appear on top of every docgen'd page when `nim doc --git.url:url ...` is given
## Tool changes ## Tool changes

View file

@ -396,6 +396,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
var var
key, val: string key, val: string
case switch.normalize case switch.normalize
of "input", "i": # PRTEMP
expectArg(conf, switch, arg, pass, info)
of "path", "p": of "path", "p":
expectArg(conf, switch, arg, pass, info) expectArg(conf, switch, arg, pass, info)
for path in nimbleSubs(conf, arg): for path in nimbleSubs(conf, arg):

View file

@ -777,6 +777,26 @@ type DocFlags = enum
kDefault kDefault
kForceExport kForceExport
proc genSeeSrcRope(d: PDoc, path: string, line: int): Rope =
let docItemSeeSrc = getConfigVar(d.conf, "doc.item.seesrc")
if docItemSeeSrc.len > 0:
let path = relativeTo(AbsoluteFile path, AbsoluteDir getCurrentDir(), '/')
when false:
let cwd = canonicalizePath(d.conf, getCurrentDir())
var path = path
if path.startsWith(cwd):
path = path[cwd.len+1..^1].replace('\\', '/')
let gitUrl = getConfigVar(d.conf, "git.url")
if gitUrl.len > 0:
let defaultBranch =
if NimPatch mod 2 == 1: "devel"
else: "version-$1-$2" % [$NimMajor, $NimMinor]
let commit = getConfigVar(d.conf, "git.commit", defaultBranch)
let develBranch = getConfigVar(d.conf, "git.devel", "devel")
dispA(d.conf, result, "$1", "", [ropeFormatNamedVars(d.conf, docItemSeeSrc,
["path", "line", "url", "commit", "devel"], [rope path.string,
rope($line), rope gitUrl, rope commit, rope develBranch])])
proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags) = proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags) =
if (docFlags != kForceExport) and not isVisible(d, nameNode): return if (docFlags != kForceExport) and not isVisible(d, nameNode): return
let let
@ -822,26 +842,7 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags) =
nodeToHighlightedHtml(d, n, result, {renderNoBody, renderNoComments, nodeToHighlightedHtml(d, n, result, {renderNoBody, renderNoComments,
renderDocComments, renderSyms}, symbolOrIdEncRope) renderDocComments, renderSyms}, symbolOrIdEncRope)
var seeSrcRope: Rope = nil let seeSrcRope = genSeeSrcRope(d, toFullPath(d.conf, n.info), n.info.line.int)
let docItemSeeSrc = getConfigVar(d.conf, "doc.item.seesrc")
if docItemSeeSrc.len > 0:
let path = relativeTo(AbsoluteFile toFullPath(d.conf, n.info), AbsoluteDir getCurrentDir(), '/')
when false:
let cwd = canonicalizePath(d.conf, getCurrentDir())
var path = toFullPath(d.conf, n.info)
if path.startsWith(cwd):
path = path[cwd.len+1..^1].replace('\\', '/')
let gitUrl = getConfigVar(d.conf, "git.url")
if gitUrl.len > 0:
let defaultBranch =
if NimPatch mod 2 == 1: "devel"
else: "version-$1-$2" % [$NimMajor, $NimMinor]
let commit = getConfigVar(d.conf, "git.commit", defaultBranch)
let develBranch = getConfigVar(d.conf, "git.devel", "devel")
dispA(d.conf, seeSrcRope, "$1", "", [ropeFormatNamedVars(d.conf, docItemSeeSrc,
["path", "line", "url", "commit", "devel"], [rope path.string,
rope($n.info.line), rope gitUrl, rope commit, rope develBranch])])
d.section[k].add(ropeFormatNamedVars(d.conf, getConfigVar(d.conf, "doc.item"), d.section[k].add(ropeFormatNamedVars(d.conf, getConfigVar(d.conf, "doc.item"),
["name", "header", "desc", "itemID", "header_plain", "itemSym", ["name", "header", "desc", "itemID", "header_plain", "itemSym",
"itemSymOrID", "itemSymEnc", "itemSymOrIDEnc", "seeSrc", "deprecationMsg"], "itemSymOrID", "itemSymEnc", "itemSymOrIDEnc", "seeSrc", "deprecationMsg"],
@ -1234,10 +1235,11 @@ proc genOutFile(d: PDoc, groupedToc = false): Rope =
"doc.body_toc_group" "doc.body_toc_group"
elif d.hasToc: "doc.body_toc" elif d.hasToc: "doc.body_toc"
else: "doc.body_no_toc" else: "doc.body_no_toc"
let seeSrcRope = genSeeSrcRope(d, d.filename, 1)
content = ropeFormatNamedVars(d.conf, getConfigVar(d.conf, bodyname), ["title", content = ropeFormatNamedVars(d.conf, getConfigVar(d.conf, bodyname), ["title",
"tableofcontents", "moduledesc", "date", "time", "content", "deprecationMsg", "theindexhref", "body_toc_groupsection"], "tableofcontents", "moduledesc", "date", "time", "content", "deprecationMsg", "theindexhref", "body_toc_groupsection", "seeSrc"],
[title.rope, toc, d.modDesc, rope(getDateStr()), [title.rope, toc, d.modDesc, rope(getDateStr()),
rope(getClockStr()), code, d.modDeprecationMsg, relLink(d.conf.outDir, d.destFile.AbsoluteFile, theindexFname.RelativeFile), groupsection.rope]) rope(getClockStr()), code, d.modDeprecationMsg, relLink(d.conf.outDir, d.destFile.AbsoluteFile, theindexFname.RelativeFile), groupsection.rope, seeSrcRope])
if optCompileOnly notin d.conf.globalOptions: if optCompileOnly notin d.conf.globalOptions:
# XXX what is this hack doing here? 'optCompileOnly' means raw output!? # XXX what is this hack doing here? 'optCompileOnly' means raw output!?
code = ropeFormatNamedVars(d.conf, getConfigVar(d.conf, "doc.file"), [ code = ropeFormatNamedVars(d.conf, getConfigVar(d.conf, "doc.file"), [

View file

@ -80,7 +80,7 @@ doc.item.tocTable = """
doc.item.seesrc = """&nbsp;&nbsp;<a doc.item.seesrc = """&nbsp;&nbsp;<a
href="${url}/tree/${commit}/${path}#L${line}" href="${url}/tree/${commit}/${path}#L${line}"
class="link-seesrc" target="_blank">Source</a> class="link-seesrc" target="_blank">Source</a>
<a href="${url}/edit/${devel}/${path}#L${line}" class="link-seesrc" target="_blank" >Edit</a> &nbsp;&nbsp;<a href="${url}/edit/${devel}/${path}#L${line}" class="link-seesrc" target="_blank" >Edit</a>
""" """
doc.deprecationmsg = """ doc.deprecationmsg = """
@ -187,6 +187,7 @@ doc.body_toc_group = """
</div> </div>
$tableofcontents $tableofcontents
</div> </div>
$seeSrc
<div class="nine columns" id="content"> <div class="nine columns" id="content">
<div id="tocRoot"></div> <div id="tocRoot"></div>
$deprecationMsg $deprecationMsg

View file

@ -106,6 +106,7 @@ function main() {
</ul> </ul>
</div> </div>
<div class="nine columns" id="content"> <div class="nine columns" id="content">
<div id="tocRoot"></div> <div id="tocRoot"></div>

View file

@ -132,6 +132,7 @@ function main() {
</ul> </ul>
</div> </div>
<div class="nine columns" id="content"> <div class="nine columns" id="content">
<div id="tocRoot"></div> <div id="tocRoot"></div>

View file

@ -358,6 +358,7 @@ function main() {
</ul> </ul>
</div> </div>
<div class="nine columns" id="content"> <div class="nine columns" id="content">
<div id="tocRoot"></div> <div id="tocRoot"></div>