Skip to content

Commit 6c68c65

Browse files
committed
Handle .md and .nim paths uniformly in findRefFile
1 parent 32e24c4 commit 6c68c65

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

compiler/docgen.nim

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,22 @@ template declareClosures =
264264
result = getCurrentDir() / s
265265
if not fileExists(result): result = ""
266266

267-
proc docgenFindRefFile(targetRelPath: string, isMarkup: bool):
267+
proc docgenFindRefFile(targetRelPath: string):
268268
tuple[targetPath: string, linkRelPath: string] {.gcsafe.} =
269269
let fromDir = splitFile(destFile).dir # dir where we reference from
270270
let basedir = os.splitFile(currentFilename.string).dir
271-
if isMarkup: # .rst/.md file
272-
result.targetPath = fromDir / targetRelPath
273-
else: # .nim file
274-
let outDirPath: RelativeFile =
275-
presentationPath(conf, AbsoluteFile(basedir / targetRelPath))
276-
# use presentationPath because `..` path can be be mangled to `_._`
277-
result.targetPath = string(conf.outDir / outDirPath)
271+
let outDirPath: RelativeFile =
272+
presentationPath(conf, AbsoluteFile(basedir / targetRelPath))
273+
# use presentationPath because `..` path can be be mangled to `_._`
274+
result.targetPath = string(conf.outDir / outDirPath)
275+
if not fileExists(result.targetPath):
276+
# this can happen if targetRelPath goes to parent directory `OUTDIR/..`.
277+
# Trying it, this may cause ambiguities, but allows us to insert
278+
# "packages" into each other, which is actually used in Nim repo itself.
279+
let destPath = fromDir / targetRelPath
280+
if destPath != result.targetPath and fileExists(destPath):
281+
result.targetPath = destPath
282+
278283
result.linkRelPath = relativePath(result.targetPath.splitFile.dir,
279284
fromDir).replace('\\', '/')
280285

lib/packages/docutils/rst.nim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type
8080
arg: string) {.closure, gcsafe.} ## what to do in case of an error
8181
FindFileHandler* = proc (filename: string): string {.closure, gcsafe.}
8282
FindRefFileHandler* =
83-
proc (targetRelPath: string, isMarkup: bool):
83+
proc (targetRelPath: string):
8484
tuple[targetPath: string, linkRelPath: string] {.closure, gcsafe.}
8585
## returns where .html or .idx file should be found by its relative path.
8686

@@ -473,7 +473,7 @@ proc defaultFindFile*(filename: string): string =
473473
if fileExists(filename): result = filename
474474
else: result = ""
475475

476-
proc defaultFindRefFile*(filename: string, isMarkup: bool): (string, string) =
476+
proc defaultFindRefFile*(filename: string): (string, string) =
477477
(filename, "")
478478

479479
proc defaultRole(options: RstParseOptions): string =
@@ -3499,8 +3499,7 @@ proc loadIdxFile(s: var PRstSharedState, origFilename: string) =
34993499
rstMessage(s.filenames, s.msgHandler, s.idxImports[origFilename].fromInfo,
35003500
meCannotOpenFile, origFilename & ": unknown extension")
35013501
let idxFilename = dir / basename & ".idx"
3502-
let (idxPath, linkRelPath) = s.findRefFile(
3503-
idxFilename, isMarkup = ext in [".md", ".rst"])
3502+
let (idxPath, linkRelPath) = s.findRefFile(idxFilename)
35043503
s.idxImports[origFilename].linkRelPath = linkRelPath
35053504
var
35063505
fileEntries: seq[IndexEntry]
@@ -3772,7 +3771,8 @@ proc resolveSubs*(s: PRstSharedState, n: PRstNode): PRstNode =
37723771
proc completePass2*(s: PRstSharedState) =
37733772
for (filename, importdocInfo) in s.idxImports.pairs:
37743773
if not importdocInfo.used:
3775-
rstMessage(s, mwUnusedImportdoc, filename)
3774+
rstMessage(s.filenames, s.msgHandler, importdocInfo.fromInfo,
3775+
mwUnusedImportdoc, filename)
37763776

37773777
proc rstParse*(text, filename: string,
37783778
line, column: int,

lib/packages/docutils/rstgen.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ proc rstToHtml*(s: string, options: RstParseOptions,
15281528
proc myFindFile(filename: string): string =
15291529
# we don't find any files in online mode:
15301530
result = ""
1531-
proc myFindRefFile(filename: string, isMarkup: bool): (string, string) =
1531+
proc myFindRefFile(filename: string): (string, string) =
15321532
result = ("", "")
15331533

15341534
const filen = "input"

0 commit comments

Comments
 (0)