Skip to content

Commit

Permalink
use canonicalImport for filename_magicSauce
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Apr 16, 2021
1 parent 201ac2b commit 541c699
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
15 changes: 0 additions & 15 deletions compiler/docgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,6 @@ proc prettyString(a: object): string =
for k, v in fieldPairs(a):
result.add k & ": " & $v & "\n"

proc canonicalImport*(conf: ConfigRef, file: AbsoluteFile): string =
##[
Shows the canonical module import, e.g.:
system, std/tables, fusion/pointers, system/assertions, std/private/asciitables
]##
var ret = getRelativePathFromConfigPath(conf, file, isTitle = true)
let dir = getNimbleFile(conf, $file).parentDir.AbsoluteDir
if not dir.isEmpty:
let relPath = relativeTo(file, dir)
if not relPath.isEmpty and (ret.isEmpty or relPath.string.len < ret.string.len):
ret = relPath
if ret.isEmpty:
ret = relativeTo(file, conf.projectPath)
result = ret.string.nativeToUnixPath.changeFileExt("")

proc presentationPath*(conf: ConfigRef, file: AbsoluteFile): RelativeFile =
## returns a relative file that will be appended to outDir
let file2 = $file
Expand Down
18 changes: 9 additions & 9 deletions compiler/msgs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ proc toFilenameOption*(conf: ConfigRef, fileIdx: FileIndex, opt: FilenameOption)
of foAbs: result = toFullPath(conf, fileIdx)
of foRelProject: result = toProjPath(conf, fileIdx)
of foMagicSauce:
let
absPath = toFullPath(conf, fileIdx)
relPath = toProjPath(conf, fileIdx)
result = if (optListFullPaths in conf.globalOptions) or
(relPath.len > absPath.len) or
(relPath.count("..") > 2):
absPath
else:
relPath
let absPath = toFullPath(conf, fileIdx)
result = canonicalImport(conf, absPath.AbsoluteFile)
# relPath = toProjPath(conf, fileIdx)
# result = if (optListFullPaths in conf.globalOptions) or
# (relPath.len > absPath.len) or
# (relPath.count("..") > 2):
# absPath
# else:
# relPath
of foName: result = toProjPath(conf, fileIdx).lastPathPart
of foStacktrace:
if optExcessiveStackTrace in conf.globalOptions:
Expand Down
17 changes: 16 additions & 1 deletion compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import

from terminal import isatty
from times import utc, fromUnix, local, getTime, format, DateTime

from std/private/globs import nativeToUnixPath
const
hasTinyCBackend* = defined(tinyc)
useEffectSystem* = true
Expand Down Expand Up @@ -876,6 +876,21 @@ proc findProjectNimFile*(conf: ConfigRef; pkg: string): string =
if dir == "": break
return ""

proc canonicalImport*(conf: ConfigRef, file: AbsoluteFile): string =
##[
Shows the canonical module import, e.g.:
system, std/tables, fusion/pointers, system/assertions, std/private/asciitables
]##
var ret = getRelativePathFromConfigPath(conf, file, isTitle = true)
let dir = getNimbleFile(conf, $file).parentDir.AbsoluteDir
if not dir.isEmpty:
let relPath = relativeTo(file, dir)
if not relPath.isEmpty and (ret.isEmpty or relPath.string.len < ret.string.len):
ret = relPath
if ret.isEmpty:
ret = relativeTo(file, conf.projectPath)
result = ret.string.nativeToUnixPath.changeFileExt("")

proc canonDynlibName(s: string): string =
let start = if s.startsWith("lib"): 3 else: 0
let ende = strutils.find(s, {'(', ')', '.'})
Expand Down

0 comments on commit 541c699

Please sign in to comment.