Skip to content

Commit

Permalink
use instead getConfigVar, ie: --msgs.hintSuccessX:customMsg
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Mar 11, 2020
1 parent 0969d48 commit cb7ffaa
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
2 changes: 0 additions & 2 deletions compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,6 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
splitSwitch(conf, arg, key, val, pass, info)
if cmpIgnoreStyle(key, "nimQuirky") == 0:
conf.exc = excQuirky
elif cmpIgnoreStyle(key, "nimHintSuccessX") == 0:
msgKindToStr[hintSuccessX] = val
defineSymbol(conf.symbols, key, val)
else:
if cmpIgnoreStyle(arg, "nimQuirky") == 0:
Expand Down
10 changes: 3 additions & 7 deletions compiler/lineinfos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ type
hintUser, hintUserRaw,
hintExtendedContext

var
msgKindToStr*: array[TMsgKind, string] = [
const
MsgKindToStr*: array[TMsgKind, string] = [
errUnknown: "unknown error",
errInternal: "internal error: $1",
errIllFormedAstX: "illformed AST: $1",
Expand Down Expand Up @@ -97,11 +97,7 @@ var
warnCycleCreated: "$1",
warnUser: "$1",
hintSuccess: "operation successful: $#",
# keep in sync with `testament.isSuccess`
# can be overriden with -d:nimHintSuccessX:"custom msg; recompiled: $projectRecompiled"
# for the set of valid keys and details on formatting, see code near:
# `rawMessage(conf, hintSuccessX`
hintSuccessX: "$loc LOC; $sec sec; $mem; $build build; proj: $project; out: $output",
hintSuccessX: "$1", # keep in sync with `testament.isSuccess`
hintCC: "CC: $1",
hintLineTooLong: "line too long",
hintXDeclaredButNotUsed: "'$1' is declared but not used",
Expand Down
6 changes: 5 additions & 1 deletion compiler/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ proc mainCommand*(graph: ModuleGraph) =
let project = if optListFullPaths in conf.globalOptions: $conf.projectFull else: $conf.projectName
var output = $conf.absOutFile
if optListFullPaths notin conf.globalOptions: output = output.AbsoluteFile.extractFilename
rawMessage(conf, hintSuccessX, [

let fmtDefault = "$loc LOC; $sec sec; $mem; $build build; proj: $project; out: $output"
# can be overriden to format differently/show additional fields
let msg = getConfigVar(conf, "msgs.hintSuccessX", fmtDefault)
rawMessage(conf, hintSuccessX, msg % [
"loc", loc,
"sec", sec,
"mem", mem,
Expand Down
2 changes: 1 addition & 1 deletion compiler/msgs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ proc coordToStr(coord: int): string =

proc msgKindToString*(kind: TMsgKind): string =
# later versions may provide translated error messages
result = msgKindToStr[kind]
result = MsgKindToStr[kind]

proc getMessageStr(msg: TMsgKind, arg: string): string =
result = msgKindToString(msg) % [arg]
Expand Down

0 comments on commit cb7ffaa

Please sign in to comment.