summary refs log tree commit diff stats
path: root/compiler/options.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-03-14 12:28:15 +0100
committerAndreas Rumpf <rumpf_a@web.de>2017-03-14 12:28:15 +0100
commitf7d760cb94ffef99b596d167fc517284e5a6a757 (patch)
treebb6177e4731a54e87774fe6b5ab70f13e843cc30 /compiler/options.nim
parentb414806e66efbf37c8e7edf832cb9a266f433d60 (diff)
downloadNim-f7d760cb94ffef99b596d167fc517284e5a6a757.tar.gz
nimsuggest: when invoked with a directory, detect the main nim file on its own
Diffstat (limited to 'compiler/options.nim')
-rw-r--r--compiler/options.nim17
1 files changed, 17 insertions, 0 deletions
diff --git a/compiler/options.nim b/compiler/options.nim
index 349f9dae1..6372cddac 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -392,6 +392,23 @@ proc findModule*(modulename, currentModule: string): string =
     result = findFile(m)
   patchModule()
 
+proc findProjectNimFile*(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]
+  return ""
+
 proc canonDynlibName(s: string): string =
   let start = if s.startsWith("lib"): 3 else: 0
   let ende = strutils.find(s, {'(', ')', '.'})
;hut@lavabit.com> 2010-02-15 21:57:21 +0100 added guidelines on code modification' href='/akspecs/ranger/commit/HACKING?h=v1.9.0b5&id=f8f6f7f94b3c0a1da2d8abb38cf23ca127dd28a4'>f8f6f7f9 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85