make nimsuggest go up in the directory tree in order to determine the main .nim file

This commit is contained in:
Andreas Rumpf 2018-08-10 09:37:17 +02:00
commit 7e2418bd22

View file

@ -600,11 +600,13 @@ proc findModule*(conf: ConfigRef; modulename, currentModule: string): string =
proc findProjectNimFile*(conf: ConfigRef; pkg: string): string = proc findProjectNimFile*(conf: ConfigRef; pkg: string): string =
const extensions = [".nims", ".cfg", ".nimcfg", ".nimble"] const extensions = [".nims", ".cfg", ".nimcfg", ".nimble"]
var candidates: seq[string] = @[] var candidates: seq[string] = @[]
for k, f in os.walkDir(pkg, relative=true): var dir = pkg
while true:
for k, f in os.walkDir(dir, relative=true):
if k == pcFile and f != "config.nims": if k == pcFile and f != "config.nims":
let (_, name, ext) = splitFile(f) let (_, name, ext) = splitFile(f)
if ext in extensions: if ext in extensions:
let x = changeFileExt(pkg / name, ".nim") let x = changeFileExt(dir / name, ".nim")
if fileExists(x): if fileExists(x):
candidates.add x candidates.add x
for c in candidates: for c in candidates:
@ -612,6 +614,8 @@ proc findProjectNimFile*(conf: ConfigRef; pkg: string): string =
if (pkg in c) or (c in pkg): return c if (pkg in c) or (c in pkg): return c
if candidates.len >= 1: if candidates.len >= 1:
return candidates[0] return candidates[0]
dir = parentDir(dir)
if dir == "": break
return "" return ""
proc canonDynlibName(s: string): string = proc canonDynlibName(s: string): string =