diff --git a/compiler/options.nim b/compiler/options.nim index 349f9dae16..6372cddac3 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, {'(', ')', '.'}) diff --git a/nimsuggest/nimsuggest.nim b/nimsuggest/nimsuggest.nim index 2cf19925ce..0b66dfb404 100644 --- a/nimsuggest/nimsuggest.nim +++ b/nimsuggest/nimsuggest.nim @@ -556,7 +556,13 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string) = suggestMaxResults = parseInt(p.val) else: processSwitch(pass, p) of cmdArgument: - options.gProjectName = unixToNativePath(p.key) + let a = unixToNativePath(p.key) + if dirExists(a) and not fileExists(a.addFileExt("nim")): + options.gProjectName = findProjectNimFile(a) + # don't make it worse, report the error the old way: + if options.gProjectName.len == 0: options.gProjectName = a + else: + options.gProjectName = a # if processArgument(pass, p, argsCount): break proc handleCmdLine(cache: IdentCache; config: ConfigRef) =