Skip to content

Commit ce36fdc

Browse files
timotheecourAraq
authored andcommitted
correctly honor cmdline --hint:conf:on/off ; correctly show Conf hints in order
1 parent 96bffad commit ce36fdc

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

compiler/cmdlinehelper.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ proc initDefinesProg*(self: NimProg, conf: ConfigRef, name: string) =
2727
defineSymbol conf.symbols, name
2828

2929
proc processCmdLineAndProjectPath*(self: NimProg, conf: ConfigRef) =
30+
conf.isCmdLine = true
3031
self.processCmdLine(passCmd1, "", conf)
32+
conf.isCmdLine = false
3133
if self.supportsStdinFile and conf.projectName == "-":
3234
handleStdinInput(conf)
3335
elif conf.projectName != "":

compiler/commands.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,17 @@ proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass,
204204
incl(conf.notes, n)
205205
incl(conf.mainPackageNotes, n)
206206
incl(conf.enableNotes, n)
207+
if conf.isCmdLine:
208+
incl(conf.cmdLineNotes, n)
209+
excl(conf.cmdLineDisabledNotes, n)
207210
of "off":
208211
excl(conf.notes, n)
209212
excl(conf.mainPackageNotes, n)
210213
incl(conf.disableNotes, n)
211214
excl(conf.foreignPackageNotes, n)
215+
if conf.isCmdLine:
216+
incl(conf.cmdLineDisabledNotes, n)
217+
excl(conf.cmdLineNotes, n)
212218
else: localError(conf, info, errOnOrOffExpectedButXFound % arg)
213219

214220
proc processCompile(conf: ConfigRef; filename: string) =

compiler/msgs.nim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,10 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
418418
inc(conf.warnCounter)
419419
of hintMin..hintMax:
420420
sev = Severity.Hint
421-
if not conf.hasHint(msg): return
421+
if msg in conf.cmdLineDisabledNotes: return # eg: `--hints:conf:off` passed on cmdline
422+
# handle `--hints:off` (regardless of cmdline/cfg file)
423+
# handle `--hints:conf:on` on cmdline
424+
if not conf.hasHint(msg) and not (optHints in conf.options and msg in conf.cmdLineNotes)): return
422425
title = HintTitle
423426
color = HintColor
424427
if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)]

compiler/nimconf.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) =
251251
template runNimScriptIfExists(path: AbsoluteFile) =
252252
let p = path # eval once
253253
if fileExists(p):
254+
configFiles.add(p)
254255
runNimScript(cache, p, freshDefines = false, conf)
255256

256257
if optSkipSystemConfigFile notin conf.globalOptions:

compiler/options.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ type
231231
foreignPackageNotes*: TNoteKinds
232232
notes*: TNoteKinds
233233
mainPackageNotes*: TNoteKinds
234+
cmdLineNotes*: TNoteKinds
235+
cmdLineDisabledNotes*: TNoteKinds
234236
mainPackageId*: int
235237
errorCounter*: int
236238
hintCounter*: int
@@ -286,6 +288,7 @@ type
286288
structuredErrorHook*: proc (config: ConfigRef; info: TLineInfo; msg: string;
287289
severity: Severity) {.closure, gcsafe.}
288290
cppCustomNamespace*: string
291+
isCmdLine*: bool # whether we are currently processing cmdline args, not cfg files
289292

290293
proc hasHint*(conf: ConfigRef, note: TNoteKind): bool =
291294
optHints in conf.options and note in conf.notes
@@ -391,6 +394,7 @@ proc newConfigRef*(): ConfigRef =
391394
arguments: "",
392395
suggestMaxResults: 10_000,
393396
maxLoopIterationsVM: 10_000_000,
397+
isCmdLine: false,
394398
)
395399
setTargetFromSystem(result.target)
396400
# enable colors by default on terminals

compiler/scriptconfig.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ proc setupVM*(module: PSym; cache: IdentCache; scriptName: string;
199199

200200
proc runNimScript*(cache: IdentCache; scriptName: AbsoluteFile;
201201
freshDefines=true; conf: ConfigRef) =
202-
rawMessage(conf, hintConf, scriptName.string)
203202
let oldSymbolFiles = conf.symbolFiles
204203
conf.symbolFiles = disabledSf
205204

@@ -224,7 +223,7 @@ proc runNimScript*(cache: IdentCache; scriptName: AbsoluteFile;
224223
incl(m.flags, sfMainModule)
225224
graph.vm = setupVM(m, cache, scriptName.string, graph)
226225

227-
graph.compileSystemModule() # TODO: see why this unsets hintConf in conf.notes
226+
graph.compileSystemModule()
228227
discard graph.processModule(m, llStreamOpen(scriptName, fmRead))
229228

230229
# watch out, "newruntime" can be set within NimScript itself and then we need

0 commit comments

Comments
 (0)