summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-08-10 09:37:17 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-08-10 09:37:17 +0200
commit7e2418bd224add065bb1245a0602b8d75dd2ca03 (patch)
tree3d2874b01dd86df8d8a33d8349fe717a2c9f0600 /compiler
parent1d63a8fe4a21d71ab2d8cfb7d1540bdc09d02c29 (diff)
downloadNim-7e2418bd224add065bb1245a0602b8d75dd2ca03.tar.gz
make nimsuggest go up in the directory tree in order to determine the main .nim file
Diffstat (limited to 'compiler')
-rw-r--r--compiler/options.nim28
1 files changed, 16 insertions, 12 deletions
diff --git a/compiler/options.nim b/compiler/options.nim
index be9342085..ff3e70800 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -600,18 +600,22 @@ proc findModule*(conf: ConfigRef; modulename, currentModule: string): string =
 proc findProjectNimFile*(conf: ConfigRef; pkg: string): string =
   const extensions = [".nims", ".cfg", ".nimcfg", ".nimble"]
   var candidates: seq[string] = @[]
-  for k, f in os.walkDir(pkg, relative=true):
-    if k == pcFile and f != "config.nims":
-      let (_, name, ext) = splitFile(f)
-      if ext in extensions:
-        let x = changeFileExt(pkg / name, ".nim")
-        if fileExists(x):
-          candidates.add x
-  for c in candidates:
-    # nim-foo foo  or  foo  nfoo
-    if (pkg in c) or (c in pkg): return c
-  if candidates.len >= 1:
-    return candidates[0]
+  var dir = pkg
+  while true:
+    for k, f in os.walkDir(dir, relative=true):
+      if k == pcFile and f != "config.nims":
+        let (_, name, ext) = splitFile(f)
+        if ext in extensions:
+          let x = changeFileExt(dir / name, ".nim")
+          if fileExists(x):
+            candidates.add x
+    for c in candidates:
+      # nim-foo foo  or  foo  nfoo
+      if (pkg in c) or (c in pkg): return c
+    if candidates.len >= 1:
+      return candidates[0]
+    dir = parentDir(dir)
+    if dir == "": break
   return ""
 
 proc canonDynlibName(s: string): string =