no more guessing where compiler msgs came from (#14317)
This commit is contained in:
parent
a3719df8b3
commit
3573a4f9c1
3 changed files with 40 additions and 19 deletions
|
|
@ -175,6 +175,9 @@ proc mydiv(a, b): int {.raises: [].} =
|
||||||
(likewise with other hints and warnings), which is consistent with all other bool flags.
|
(likewise with other hints and warnings), which is consistent with all other bool flags.
|
||||||
(since 1.3.3).
|
(since 1.3.3).
|
||||||
- `nim doc -r main` and `nim rst2html -r main` now call openDefaultBrowser
|
- `nim doc -r main` and `nim rst2html -r main` now call openDefaultBrowser
|
||||||
|
- new hint: `--hint:msgOrigin` will show where a compiler msg (hint|warning|error) was generated; this
|
||||||
|
helps in particular when it's non obvious where it came from either because multiple locations generate
|
||||||
|
the same message, or because the message involves runtime formatting.
|
||||||
|
|
||||||
## Tool changes
|
## Tool changes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,8 @@ type
|
||||||
hintSource, hintPerformance, hintStackTrace, hintGCStats,
|
hintSource, hintPerformance, hintStackTrace, hintGCStats,
|
||||||
hintGlobalVar, hintExpandMacro,
|
hintGlobalVar, hintExpandMacro,
|
||||||
hintUser, hintUserRaw,
|
hintUser, hintUserRaw,
|
||||||
hintExtendedContext
|
hintExtendedContext,
|
||||||
|
hintMsgOrigin, # since 1.3.5
|
||||||
|
|
||||||
const
|
const
|
||||||
MsgKindToStr*: array[TMsgKind, string] = [
|
MsgKindToStr*: array[TMsgKind, string] = [
|
||||||
|
|
@ -140,6 +141,7 @@ const
|
||||||
hintUser: "$1",
|
hintUser: "$1",
|
||||||
hintUserRaw: "$1",
|
hintUserRaw: "$1",
|
||||||
hintExtendedContext: "$1",
|
hintExtendedContext: "$1",
|
||||||
|
hintMsgOrigin: "$1",
|
||||||
]
|
]
|
||||||
|
|
||||||
const
|
const
|
||||||
|
|
@ -166,7 +168,7 @@ const
|
||||||
"ExprAlwaysX", "QuitCalled", "Processing", "CodeBegin", "CodeEnd", "Conf",
|
"ExprAlwaysX", "QuitCalled", "Processing", "CodeBegin", "CodeEnd", "Conf",
|
||||||
"Path", "CondTrue", "CondFalse", "Name", "Pattern", "Exec", "Link", "Dependency",
|
"Path", "CondTrue", "CondFalse", "Name", "Pattern", "Exec", "Link", "Dependency",
|
||||||
"Source", "Performance", "StackTrace", "GCStats", "GlobalVar", "ExpandMacro",
|
"Source", "Performance", "StackTrace", "GCStats", "GlobalVar", "ExpandMacro",
|
||||||
"User", "UserRaw", "ExtendedContext",
|
"User", "UserRaw", "ExtendedContext", "MsgOrigin",
|
||||||
]
|
]
|
||||||
|
|
||||||
const
|
const
|
||||||
|
|
@ -192,7 +194,7 @@ proc computeNotesVerbosity(): array[0..3, TNoteKinds] =
|
||||||
result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext}
|
result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext}
|
||||||
result[1] = result[2] - {warnProveField, warnProveIndex,
|
result[1] = result[2] - {warnProveField, warnProveIndex,
|
||||||
warnGcUnsafe, hintPath, hintDependency, hintCodeBegin, hintCodeEnd,
|
warnGcUnsafe, hintPath, hintDependency, hintCodeBegin, hintCodeEnd,
|
||||||
hintSource, hintGlobalVar, hintGCStats}
|
hintSource, hintGlobalVar, hintGCStats, hintMsgOrigin}
|
||||||
result[0] = result[1] - {hintSuccessX, hintSuccess, hintConf,
|
result[0] = result[1] - {hintSuccessX, hintSuccess, hintConf,
|
||||||
hintProcessing, hintPattern, hintExecuting, hintLinking, hintCC}
|
hintProcessing, hintPattern, hintExecuting, hintLinking, hintCC}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ import
|
||||||
lineinfos, pathutils
|
lineinfos, pathutils
|
||||||
import std/private/miscdollars
|
import std/private/miscdollars
|
||||||
|
|
||||||
|
type InstantiationInfo = typeof(instantiationInfo())
|
||||||
|
|
||||||
proc toCChar*(c: char; result: var string) =
|
proc toCChar*(c: char; result: var string) =
|
||||||
case c
|
case c
|
||||||
of '\0'..'\x1F', '\x7F'..'\xFF':
|
of '\0'..'\x1F', '\x7F'..'\xFF':
|
||||||
|
|
@ -255,6 +257,9 @@ proc toLinenumber*(info: TLineInfo): int {.inline.} =
|
||||||
proc toColumn*(info: TLineInfo): int {.inline.} =
|
proc toColumn*(info: TLineInfo): int {.inline.} =
|
||||||
result = info.col
|
result = info.col
|
||||||
|
|
||||||
|
proc toFileLineCol(info: InstantiationInfo): string {.inline.} =
|
||||||
|
result.toLocation(info.filename, info.line, info.column + ColOffset)
|
||||||
|
|
||||||
proc toFileLineCol*(conf: ConfigRef; info: TLineInfo): string {.inline.} =
|
proc toFileLineCol*(conf: ConfigRef; info: TLineInfo): string {.inline.} =
|
||||||
result.toLocation(toMsgFilename(conf, info), info.line.int, info.col.int + ColOffset)
|
result.toLocation(toMsgFilename(conf, info), info.line.int, info.col.int + ColOffset)
|
||||||
|
|
||||||
|
|
@ -487,7 +492,7 @@ proc formatMsg*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string): s
|
||||||
conf.toFileLineCol(info) & " " & title & getMessageStr(msg, arg)
|
conf.toFileLineCol(info) & " " & title & getMessageStr(msg, arg)
|
||||||
|
|
||||||
proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
|
proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
|
||||||
eh: TErrorHandling) =
|
eh: TErrorHandling, info2: InstantiationInfo) {.noinline.} =
|
||||||
var
|
var
|
||||||
title: string
|
title: string
|
||||||
color: ForegroundColor
|
color: ForegroundColor
|
||||||
|
|
@ -533,36 +538,47 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
|
||||||
styledMsgWriteln(styleBright, x, resetStyle, color, title, resetStyle, s)
|
styledMsgWriteln(styleBright, x, resetStyle, color, title, resetStyle, s)
|
||||||
if conf.hasHint(hintSource):
|
if conf.hasHint(hintSource):
|
||||||
conf.writeSurroundingSrc(info)
|
conf.writeSurroundingSrc(info)
|
||||||
|
if conf.hasHint(hintMsgOrigin):
|
||||||
|
styledMsgWriteln(styleBright, toFileLineCol(info2), resetStyle, " compiler msg initiated here", KindColor, KindFormat % HintsToStr[ord(hintMsgOrigin) - ord(hintMin)], resetStyle)
|
||||||
|
|
||||||
handleError(conf, msg, eh, s)
|
handleError(conf, msg, eh, s)
|
||||||
|
|
||||||
proc fatal*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
template fatal*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||||
# this fixes bug #7080 so that it is at least obvious 'fatal'
|
# this fixes bug #7080 so that it is at least obvious 'fatal'
|
||||||
# was executed.
|
# was executed.
|
||||||
conf.m.errorOutputs = {eStdOut, eStdErr}
|
conf.m.errorOutputs = {eStdOut, eStdErr}
|
||||||
liMessage(conf, info, msg, arg, doAbort)
|
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||||
|
liMessage(conf, info, msg, arg, doAbort, info2)
|
||||||
|
|
||||||
proc globalError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
template globalError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||||
liMessage(conf, info, msg, arg, doRaise)
|
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||||
|
liMessage(conf, info, msg, arg, doRaise, info2)
|
||||||
|
|
||||||
proc globalError*(conf: ConfigRef; info: TLineInfo, arg: string) =
|
template globalError*(conf: ConfigRef; info: TLineInfo, arg: string) =
|
||||||
liMessage(conf, info, errGenerated, arg, doRaise)
|
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||||
|
liMessage(conf, info, errGenerated, arg, doRaise, info2)
|
||||||
|
|
||||||
proc localError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
template localError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||||
liMessage(conf, info, msg, arg, doNothing)
|
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||||
|
liMessage(conf, info, msg, arg, doNothing, info2)
|
||||||
|
|
||||||
proc localError*(conf: ConfigRef; info: TLineInfo, arg: string) =
|
template localError*(conf: ConfigRef; info: TLineInfo, arg: string) =
|
||||||
liMessage(conf, info, errGenerated, arg, doNothing)
|
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||||
|
liMessage(conf, info, errGenerated, arg, doNothing, info2)
|
||||||
|
|
||||||
proc localError*(conf: ConfigRef; info: TLineInfo, format: string, params: openArray[string]) =
|
template localError*(conf: ConfigRef; info: TLineInfo, format: string, params: openArray[string]) =
|
||||||
localError(conf, info, format % params)
|
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||||
|
liMessage(conf, info, errGenerated, format % params, doNothing, info2)
|
||||||
|
|
||||||
proc message*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
template message*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||||
liMessage(conf, info, msg, arg, doNothing)
|
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||||
|
liMessage(conf, info, msg, arg, doNothing, info2)
|
||||||
|
|
||||||
proc internalError*(conf: ConfigRef; info: TLineInfo, errMsg: string) =
|
proc internalError*(conf: ConfigRef; info: TLineInfo, errMsg: string) =
|
||||||
if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return
|
if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return
|
||||||
|
const info2 = instantiationInfo(-1, fullPaths = true)
|
||||||
writeContext(conf, info)
|
writeContext(conf, info)
|
||||||
liMessage(conf, info, errInternal, errMsg, doAbort)
|
liMessage(conf, info, errInternal, errMsg, doAbort, info2)
|
||||||
|
|
||||||
proc internalError*(conf: ConfigRef; errMsg: string) =
|
proc internalError*(conf: ConfigRef; errMsg: string) =
|
||||||
if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return
|
if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue