diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2018-08-30 04:52:32 -0700 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-08-30 13:52:32 +0200 |
commit | ed0cb7b85d8d48bcebb63a5e90a45a4e29bcb673 (patch) | |
tree | a89177259a1fb42477adbafa09c1790c5fe50535 /nimsuggest/nimsuggest.nim | |
parent | 01211ced1d5c3252c88e61bbbb6bb78dcc5575f0 (diff) | |
download | Nim-ed0cb7b85d8d48bcebb63a5e90a45a4e29bcb673.tar.gz |
make config.nims behave like nim.cfg in terms of where these scripts are searched / run (#8682)
* run project config.nims if exists, then inputfile.nims if exists * ~/.config/nim/config.nims can now be used * also check in getSystemConfigPath for config.nims * refactor handleCmdLine for nim and nimsuggest
Diffstat (limited to 'nimsuggest/nimsuggest.nim')
-rw-r--r-- | nimsuggest/nimsuggest.nim | 73 |
1 files changed, 25 insertions, 48 deletions
diff --git a/nimsuggest/nimsuggest.nim b/nimsuggest/nimsuggest.nim index 4b5ce0a57..b20572b0e 100644 --- a/nimsuggest/nimsuggest.nim +++ b/nimsuggest/nimsuggest.nim @@ -20,7 +20,7 @@ import compiler / [options, commands, modules, sem, passes, passaux, msgs, nimconf, extccomp, condsyms, sigmatch, ast, scriptconfig, - idents, modulegraphs, vm, prefixmatches, lineinfos] + idents, modulegraphs, vm, prefixmatches, lineinfos, cmdlinehelper] when defined(windows): import winlean @@ -582,55 +582,32 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string; conf: ConfigRef) = # if processArgument(pass, p, argsCount): break proc handleCmdLine(cache: IdentCache; conf: ConfigRef) = - condsyms.initDefines(conf.symbols) - defineSymbol conf.symbols, "nimsuggest" + let self = NimProg( + suggestMode: true, + processCmdLine: processCmdLine, + mainCommand: mainCommand + ) + self.initDefinesProg(conf, "nimsuggest") if paramCount() == 0: stdout.writeline(Usage) - else: - processCmdLine(passCmd1, "", conf) - if gMode != mstdin: - conf.writelnHook = proc (msg: string) = discard - if conf.projectName != "": - try: - conf.projectFull = canonicalizePath(conf, conf.projectName) - except OSError: - conf.projectFull = conf.projectName - var p = splitFile(conf.projectFull) - conf.projectPath = canonicalizePath(conf, p.dir) - conf.projectName = p.name - else: - conf.projectPath = canonicalizePath(conf, getCurrentDir()) - - # Find Nim's prefix dir. - let binaryPath = findExe("nim") - if binaryPath == "": - raise newException(IOError, - "Cannot find Nim standard library: Nim compiler not in PATH") - conf.prefixDir = binaryPath.splitPath().head.parentDir() - if not dirExists(conf.prefixDir / "lib"): conf.prefixDir = "" - - #msgs.writelnHook = proc (line: string) = log(line) - myLog("START " & conf.projectFull) - - loadConfigs(DefaultConfig, cache, conf) # load all config files - # now process command line arguments again, because some options in the - # command line can overwite the config file's settings - conf.command = "nimsuggest" - let scriptFile = conf.projectFull.changeFileExt("nims") - if fileExists(scriptFile): - # 'nimsuggest foo.nims' means to just auto-complete the NimScript file: - if scriptFile != conf.projectFull: - runNimScript(cache, scriptFile, freshDefines=false, conf) - elif fileExists(conf.projectPath / "config.nims"): - # directory wide NimScript file - runNimScript(cache, conf.projectPath / "config.nims", freshDefines=false, conf) - - extccomp.initVars(conf) - processCmdLine(passCmd2, "", conf) - - let graph = newModuleGraph(cache, conf) - graph.suggestMode = true - mainCommand(graph) + return + + self.processCmdLineAndProjectPath(conf) + + if gMode != mstdin: + conf.writelnHook = proc (msg: string) = discard + # Find Nim's prefix dir. + let binaryPath = findExe("nim") + if binaryPath == "": + raise newException(IOError, + "Cannot find Nim standard library: Nim compiler not in PATH") + conf.prefixDir = binaryPath.splitPath().head.parentDir() + if not dirExists(conf.prefixDir / "lib"): conf.prefixDir = "" + + #msgs.writelnHook = proc (line: string) = log(line) + myLog("START " & conf.projectFull) + + discard self.loadConfigsAndRunMainCommand(cache, conf) handleCmdline(newIdentCache(), newConfigRef()) |