1111
1212import
1313 llstream, commands, os, strutils, msgs, lexer,
14- options, idents, wordrecg, strtabs, lineinfos, pathutils
14+ options, idents, wordrecg, strtabs, lineinfos, pathutils, scriptconfig
1515
1616# ---------------- configuration file parser -----------------------------
1717# we use Nim's scanner here to save space and work
@@ -248,17 +248,31 @@ proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) =
248248 if readConfigFile (configPath, cache, conf):
249249 configFiles.add (configPath)
250250
251+ template runNimScriptIfExists (path: AbsoluteFile ) =
252+ let p = path # eval once
253+ if fileExists (p):
254+ runNimScript (cache, p, freshDefines = false , conf)
255+
251256 if optSkipSystemConfigFile notin conf.globalOptions:
252257 readConfigFile (getSystemConfigPath (conf, cfg))
253258
259+ if cfg == DefaultConfig :
260+ runNimScriptIfExists (getSystemConfigPath (conf, DefaultConfigNims ))
261+
254262 if optSkipUserConfigFile notin conf.globalOptions:
255263 readConfigFile (getUserConfigPath (cfg))
256264
265+ if cfg == DefaultConfig :
266+ runNimScriptIfExists (getUserConfigPath (DefaultConfigNims ))
267+
257268 let pd = if not conf.projectPath.isEmpty: conf.projectPath else : AbsoluteDir (getCurrentDir ())
258269 if optSkipParentConfigFiles notin conf.globalOptions:
259270 for dir in parentDirs (pd.string , fromRoot= true , inclusive= false ):
260271 readConfigFile (AbsoluteDir (dir) / cfg)
261272
273+ if cfg == DefaultConfig :
274+ runNimScriptIfExists (AbsoluteDir (dir) / DefaultConfigNims )
275+
262276 if optSkipProjConfigFile notin conf.globalOptions:
263277 readConfigFile (pd / cfg)
264278
@@ -269,6 +283,20 @@ proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) =
269283 projectConfig = changeFileExt (conf.projectFull, " nim.cfg" )
270284 readConfigFile (projectConfig)
271285
286+ if cfg == DefaultConfig :
287+ runNimScriptIfExists (pd / DefaultConfigNims )
288+
272289 for filename in configFiles:
273290 # delayed to here so that `hintConf` is honored
274291 rawMessage (conf, hintConf, filename.string )
292+
293+ block :
294+ let scriptFile = conf.projectFull.changeFileExt (" nims" )
295+ if conf.command != " nimsuggest" :
296+ runNimScriptIfExists (scriptFile)
297+ else :
298+ if scriptFile != conf.projectFull:
299+ runNimScriptIfExists (scriptFile)
300+ else :
301+ # 'nimsuggest foo.nims' means to just auto-complete the NimScript file
302+ discard
0 commit comments