experimental support for outputting code snippets in error messages; implements #301
see #301 for description. currently, the feature is activated by setting the verbosity level to 2 or more
This commit is contained in:
parent
95b28700cc
commit
e7581e7b9b
2 changed files with 21 additions and 0 deletions
|
|
@ -506,6 +506,8 @@ var gCodegenLineInfo* = newLineInfo(int32(1), 1, 1)
|
||||||
proc raiseRecoverableError*(msg: string) {.noinline, noreturn.} =
|
proc raiseRecoverableError*(msg: string) {.noinline, noreturn.} =
|
||||||
raise newException(ERecoverableError, msg)
|
raise newException(ERecoverableError, msg)
|
||||||
|
|
||||||
|
proc sourceLine*(i: TLineInfo): PRope
|
||||||
|
|
||||||
var
|
var
|
||||||
gNotes*: TNoteKinds = {low(TNoteKind)..high(TNoteKind)} - {warnShadowIdent}
|
gNotes*: TNoteKinds = {low(TNoteKind)..high(TNoteKind)} - {warnShadowIdent}
|
||||||
gErrorCounter*: int = 0 # counts the number of errors
|
gErrorCounter*: int = 0 # counts the number of errors
|
||||||
|
|
@ -707,6 +709,11 @@ proc rawMessage*(msg: TMsgKind, arg: string) =
|
||||||
var
|
var
|
||||||
lastError = UnknownLineInfo()
|
lastError = UnknownLineInfo()
|
||||||
|
|
||||||
|
proc writeSurroundingSrc(info: TLineInfo) =
|
||||||
|
const indent = " "
|
||||||
|
MsgWriteln(indent & info.sourceLine.data)
|
||||||
|
MsgWriteln(indent & repeatChar(info.col, ' ') & '^')
|
||||||
|
|
||||||
proc liMessage(info: TLineInfo, msg: TMsgKind, arg: string,
|
proc liMessage(info: TLineInfo, msg: TMsgKind, arg: string,
|
||||||
eh: TErrorHandling) =
|
eh: TErrorHandling) =
|
||||||
var frmt: string
|
var frmt: string
|
||||||
|
|
@ -732,6 +739,8 @@ proc liMessage(info: TLineInfo, msg: TMsgKind, arg: string,
|
||||||
coordToStr(info.col), getMessageStr(msg, arg)]
|
coordToStr(info.col), getMessageStr(msg, arg)]
|
||||||
if not ignoreMsg:
|
if not ignoreMsg:
|
||||||
MsgWriteln(s)
|
MsgWriteln(s)
|
||||||
|
if optPrintSurroundingSrc and msg in errMin..errMax:
|
||||||
|
info.writeSurroundingSrc
|
||||||
handleError(msg, eh, s)
|
handleError(msg, eh, s)
|
||||||
|
|
||||||
proc Fatal*(info: TLineInfo, msg: TMsgKind, arg = "") =
|
proc Fatal*(info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||||
|
|
@ -771,6 +780,12 @@ proc addSourceLine*(fileIdx: int32, line: string) =
|
||||||
|
|
||||||
proc sourceLine*(i: TLineInfo): PRope =
|
proc sourceLine*(i: TLineInfo): PRope =
|
||||||
if i.fileIndex < 0: return nil
|
if i.fileIndex < 0: return nil
|
||||||
|
|
||||||
|
if not optPreserveOrigSource and
|
||||||
|
fileInfos[i.fileIndex].lines.len == 0:
|
||||||
|
for line in lines(i.toFullPath):
|
||||||
|
addSourceLine i.fileIndex, line.string
|
||||||
|
|
||||||
InternalAssert i.fileIndex < fileInfos.len and
|
InternalAssert i.fileIndex < fileInfos.len and
|
||||||
i.line <= fileInfos[i.fileIndex].lines.len
|
i.line <= fileInfos[i.fileIndex].lines.len
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,12 @@ proc usesNativeGC*(): bool {.inline.} = gSelectedGC >= gcRefc
|
||||||
template compilationCachePresent*: expr =
|
template compilationCachePresent*: expr =
|
||||||
{optCaasEnabled, optSymbolFiles} * gGlobalOptions != {}
|
{optCaasEnabled, optSymbolFiles} * gGlobalOptions != {}
|
||||||
|
|
||||||
|
template optPreserveOrigSource*: expr =
|
||||||
|
optEmbedOrigSrc in gGlobalOptions
|
||||||
|
|
||||||
|
template optPrintSurroundingSrc*: expr =
|
||||||
|
gVerbosity >= 2
|
||||||
|
|
||||||
const
|
const
|
||||||
genSubDir* = "nimcache"
|
genSubDir* = "nimcache"
|
||||||
NimExt* = "nim"
|
NimExt* = "nim"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue