msgs: Append/color warning/hint kind in msgWriteln
Rather than embedding it into the message format text itself. This also makes possible to color warning/hint kind.
This commit is contained in:
parent
2ba3642544
commit
b4d3a27753
1 changed files with 66 additions and 50 deletions
|
|
@ -367,54 +367,54 @@ const
|
||||||
"of the generic paramers can be inferred from the expected signature.",
|
"of the generic paramers can be inferred from the expected signature.",
|
||||||
errCompilerDoesntSupportTarget: "The current compiler \'$1\' doesn't support the requested compilation target",
|
errCompilerDoesntSupportTarget: "The current compiler \'$1\' doesn't support the requested compilation target",
|
||||||
errUser: "$1",
|
errUser: "$1",
|
||||||
warnCannotOpenFile: "cannot open \'$1\' [CannotOpenFile]",
|
warnCannotOpenFile: "cannot open \'$1\'",
|
||||||
warnOctalEscape: "octal escape sequences do not exist; leading zero is ignored [OctalEscape]",
|
warnOctalEscape: "octal escape sequences do not exist; leading zero is ignored",
|
||||||
warnXIsNeverRead: "\'$1\' is never read [XIsNeverRead]",
|
warnXIsNeverRead: "\'$1\' is never read",
|
||||||
warnXmightNotBeenInit: "\'$1\' might not have been initialized [XmightNotBeenInit]",
|
warnXmightNotBeenInit: "\'$1\' might not have been initialized",
|
||||||
warnDeprecated: "$1 is deprecated [Deprecated]",
|
warnDeprecated: "$1 is deprecated",
|
||||||
warnConfigDeprecated: "config file '$1' is deprecated [ConfigDeprecated]",
|
warnConfigDeprecated: "config file '$1' is deprecated",
|
||||||
warnSmallLshouldNotBeUsed: "\'l\' should not be used as an identifier; may look like \'1\' (one) [SmallLshouldNotBeUsed]",
|
warnSmallLshouldNotBeUsed: "\'l\' should not be used as an identifier; may look like \'1\' (one)",
|
||||||
warnUnknownMagic: "unknown magic \'$1\' might crash the compiler [UnknownMagic]",
|
warnUnknownMagic: "unknown magic \'$1\' might crash the compiler",
|
||||||
warnRedefinitionOfLabel: "redefinition of label \'$1\' [RedefinitionOfLabel]",
|
warnRedefinitionOfLabel: "redefinition of label \'$1\'",
|
||||||
warnUnknownSubstitutionX: "unknown substitution \'$1\' [UnknownSubstitutionX]",
|
warnUnknownSubstitutionX: "unknown substitution \'$1\'",
|
||||||
warnLanguageXNotSupported: "language \'$1\' not supported [LanguageXNotSupported]",
|
warnLanguageXNotSupported: "language \'$1\' not supported",
|
||||||
warnFieldXNotSupported: "field \'$1\' not supported [FieldXNotSupported]",
|
warnFieldXNotSupported: "field \'$1\' not supported",
|
||||||
warnCommentXIgnored: "comment \'$1\' ignored [CommentXIgnored]",
|
warnCommentXIgnored: "comment \'$1\' ignored",
|
||||||
warnNilStatement: "'nil' statement is deprecated; use an empty 'discard' statement instead [NilStmt]",
|
warnNilStatement: "'nil' statement is deprecated; use an empty 'discard' statement instead",
|
||||||
warnTypelessParam: "'$1' has no type. Typeless parameters are deprecated; only allowed for 'template' [TypelessParam]",
|
warnTypelessParam: "'$1' has no type. Typeless parameters are deprecated; only allowed for 'template'",
|
||||||
warnDifferentHeaps: "possible inconsistency of thread local heaps [DifferentHeaps]",
|
warnDifferentHeaps: "possible inconsistency of thread local heaps",
|
||||||
warnWriteToForeignHeap: "write to foreign heap [WriteToForeignHeap]",
|
warnWriteToForeignHeap: "write to foreign heap",
|
||||||
warnUnsafeCode: "unsafe code: '$1' [UnsafeCode]",
|
warnUnsafeCode: "unsafe code: '$1'",
|
||||||
warnEachIdentIsTuple: "each identifier is a tuple [EachIdentIsTuple]",
|
warnEachIdentIsTuple: "each identifier is a tuple",
|
||||||
warnShadowIdent: "shadowed identifier: '$1' [ShadowIdent]",
|
warnShadowIdent: "shadowed identifier: '$1'",
|
||||||
warnProveInit: "Cannot prove that '$1' is initialized. This will become a compile time error in the future. [ProveInit]",
|
warnProveInit: "Cannot prove that '$1' is initialized. This will become a compile time error in the future.",
|
||||||
warnProveField: "cannot prove that field '$1' is accessible [ProveField]",
|
warnProveField: "cannot prove that field '$1' is accessible",
|
||||||
warnProveIndex: "cannot prove index '$1' is valid [ProveIndex]",
|
warnProveIndex: "cannot prove index '$1' is valid",
|
||||||
warnGcUnsafe: "not GC-safe: '$1' [GcUnsafe]",
|
warnGcUnsafe: "not GC-safe: '$1'",
|
||||||
warnGcUnsafe2: "$1",
|
warnGcUnsafe2: "$1",
|
||||||
warnUninit: "'$1' might not have been initialized [Uninit]",
|
warnUninit: "'$1' might not have been initialized",
|
||||||
warnGcMem: "'$1' uses GC'ed memory [GcMem]",
|
warnGcMem: "'$1' uses GC'ed memory",
|
||||||
warnDestructor: "usage of a type with a destructor in a non destructible context. This will become a compile time error in the future. [Destructor]",
|
warnDestructor: "usage of a type with a destructor in a non destructible context. This will become a compile time error in the future.",
|
||||||
warnLockLevel: "$1 [LockLevel]",
|
warnLockLevel: "$1",
|
||||||
warnResultShadowed: "Special variable 'result' is shadowed. [ResultShadowed]",
|
warnResultShadowed: "Special variable 'result' is shadowed.",
|
||||||
warnUser: "$1 [User]",
|
warnUser: "$1",
|
||||||
hintSuccess: "operation successful [Success]",
|
hintSuccess: "operation successful",
|
||||||
hintSuccessX: "operation successful ($# lines compiled; $# sec total; $#; $#) [SuccessX]",
|
hintSuccessX: "operation successful ($# lines compiled; $# sec total; $#; $#)",
|
||||||
hintLineTooLong: "line too long [LineTooLong]",
|
hintLineTooLong: "line too long",
|
||||||
hintXDeclaredButNotUsed: "\'$1\' is declared but not used [XDeclaredButNotUsed]",
|
hintXDeclaredButNotUsed: "\'$1\' is declared but not used",
|
||||||
hintConvToBaseNotNeeded: "conversion to base object is not needed [ConvToBaseNotNeeded]",
|
hintConvToBaseNotNeeded: "conversion to base object is not needed",
|
||||||
hintConvFromXtoItselfNotNeeded: "conversion from $1 to itself is pointless [ConvFromXtoItselfNotNeeded]",
|
hintConvFromXtoItselfNotNeeded: "conversion from $1 to itself is pointless",
|
||||||
hintExprAlwaysX: "expression evaluates always to \'$1\' [ExprAlwaysX]",
|
hintExprAlwaysX: "expression evaluates always to \'$1\'",
|
||||||
hintQuitCalled: "quit() called [QuitCalled]",
|
hintQuitCalled: "quit() called",
|
||||||
hintProcessing: "$1 [Processing]",
|
hintProcessing: "$1",
|
||||||
hintCodeBegin: "generated code listing: [CodeBegin]",
|
hintCodeBegin: "generated code listing:",
|
||||||
hintCodeEnd: "end of listing [CodeEnd]",
|
hintCodeEnd: "end of listing",
|
||||||
hintConf: "used config file \'$1\' [Conf]",
|
hintConf: "used config file \'$1\'",
|
||||||
hintPath: "added path: '$1' [Path]",
|
hintPath: "added path: '$1'",
|
||||||
hintConditionAlwaysTrue: "condition is always true: '$1' [CondTrue]",
|
hintConditionAlwaysTrue: "condition is always true: '$1'",
|
||||||
hintName: "name should be: '$1' [Name]",
|
hintName: "name should be: '$1'",
|
||||||
hintPattern: "$1 [Pattern]",
|
hintPattern: "$1",
|
||||||
hintUser: "$1 [User]"]
|
hintUser: "$1"]
|
||||||
|
|
||||||
const
|
const
|
||||||
WarningsToStr*: array[0..30, string] = ["CannotOpenFile", "OctalEscape",
|
WarningsToStr*: array[0..30, string] = ["CannotOpenFile", "OctalEscape",
|
||||||
|
|
@ -606,6 +606,8 @@ proc suggestQuit*() =
|
||||||
# Borland and Freepascal use
|
# Borland and Freepascal use
|
||||||
const
|
const
|
||||||
PosFormat = "$1($2, $3) "
|
PosFormat = "$1($2, $3) "
|
||||||
|
KindFormat = " [$1]"
|
||||||
|
KindColor = fgCyan
|
||||||
ErrorTitle = "Error: "
|
ErrorTitle = "Error: "
|
||||||
ErrorColor = fgRed
|
ErrorColor = fgRed
|
||||||
WarningTitle = "Warning: "
|
WarningTitle = "Warning: "
|
||||||
|
|
@ -798,6 +800,7 @@ proc rawMessage*(msg: TMsgKind, args: openArray[string]) =
|
||||||
var
|
var
|
||||||
title: string
|
title: string
|
||||||
color: ForegroundColor
|
color: ForegroundColor
|
||||||
|
kind: string
|
||||||
case msg
|
case msg
|
||||||
of errMin..errMax:
|
of errMin..errMax:
|
||||||
writeContext(unknownLineInfo())
|
writeContext(unknownLineInfo())
|
||||||
|
|
@ -809,16 +812,22 @@ proc rawMessage*(msg: TMsgKind, args: openArray[string]) =
|
||||||
writeContext(unknownLineInfo())
|
writeContext(unknownLineInfo())
|
||||||
title = WarningTitle
|
title = WarningTitle
|
||||||
color = WarningColor
|
color = WarningColor
|
||||||
|
kind = WarningsToStr[ord(msg) - ord(warnMin)]
|
||||||
inc(gWarnCounter)
|
inc(gWarnCounter)
|
||||||
of hintMin..hintMax:
|
of hintMin..hintMax:
|
||||||
if optHints notin gOptions: return
|
if optHints notin gOptions: return
|
||||||
if msg notin gNotes: return
|
if msg notin gNotes: return
|
||||||
title = HintTitle
|
title = HintTitle
|
||||||
color = HintColor
|
color = HintColor
|
||||||
|
kind = HintsToStr[ord(msg) - ord(hintMin)]
|
||||||
inc(gHintCounter)
|
inc(gHintCounter)
|
||||||
let s = `%`(msgKindToString(msg), args)
|
let s = `%`(msgKindToString(msg), args)
|
||||||
if not ignoreMsgBecauseOfIdeTools(msg):
|
if not ignoreMsgBecauseOfIdeTools(msg):
|
||||||
styledMsgWriteln(color, title, resetStyle, s)
|
if kind != nil:
|
||||||
|
styledMsgWriteln(color, title, resetStyle, s,
|
||||||
|
KindColor, `%`(KindFormat, kind))
|
||||||
|
else:
|
||||||
|
styledMsgWriteln(color, title, resetStyle, s)
|
||||||
handleError(msg, doAbort, s)
|
handleError(msg, doAbort, s)
|
||||||
|
|
||||||
proc rawMessage*(msg: TMsgKind, arg: string) =
|
proc rawMessage*(msg: TMsgKind, arg: string) =
|
||||||
|
|
@ -843,8 +852,9 @@ proc liMessage(info: TLineInfo, msg: TMsgKind, arg: string,
|
||||||
eh: TErrorHandling) =
|
eh: TErrorHandling) =
|
||||||
var
|
var
|
||||||
title: string
|
title: string
|
||||||
ignoreMsg = false
|
|
||||||
color: ForegroundColor
|
color: ForegroundColor
|
||||||
|
kind: string
|
||||||
|
ignoreMsg = false
|
||||||
case msg
|
case msg
|
||||||
of errMin..errMax:
|
of errMin..errMax:
|
||||||
writeContext(info)
|
writeContext(info)
|
||||||
|
|
@ -859,11 +869,13 @@ proc liMessage(info: TLineInfo, msg: TMsgKind, arg: string,
|
||||||
if not ignoreMsg: writeContext(info)
|
if not ignoreMsg: writeContext(info)
|
||||||
title = WarningTitle
|
title = WarningTitle
|
||||||
color = WarningColor
|
color = WarningColor
|
||||||
|
kind = WarningsToStr[ord(msg) - ord(warnMin)]
|
||||||
inc(gWarnCounter)
|
inc(gWarnCounter)
|
||||||
of hintMin..hintMax:
|
of hintMin..hintMax:
|
||||||
ignoreMsg = optHints notin gOptions or msg notin gNotes
|
ignoreMsg = optHints notin gOptions or msg notin gNotes
|
||||||
title = HintTitle
|
title = HintTitle
|
||||||
color = HintColor
|
color = HintColor
|
||||||
|
kind = HintsToStr[ord(msg) - ord(hintMin)]
|
||||||
inc(gHintCounter)
|
inc(gHintCounter)
|
||||||
# NOTE: currently line info line numbers start with 1,
|
# NOTE: currently line info line numbers start with 1,
|
||||||
# but column numbers start with 0, however most editors expect
|
# but column numbers start with 0, however most editors expect
|
||||||
|
|
@ -872,7 +884,11 @@ proc liMessage(info: TLineInfo, msg: TMsgKind, arg: string,
|
||||||
coordToStr(info.col+1)]
|
coordToStr(info.col+1)]
|
||||||
let s = getMessageStr(msg, arg)
|
let s = getMessageStr(msg, arg)
|
||||||
if not ignoreMsg and not ignoreMsgBecauseOfIdeTools(msg):
|
if not ignoreMsg and not ignoreMsgBecauseOfIdeTools(msg):
|
||||||
styledMsgWriteln(styleBright, x, resetStyle, color, title, resetStyle, s)
|
if kind != nil:
|
||||||
|
styledMsgWriteln(styleBright, x, resetStyle, color, title, resetStyle, s,
|
||||||
|
KindColor, `%`(KindFormat, kind))
|
||||||
|
else:
|
||||||
|
styledMsgWriteln(styleBright, x, resetStyle, color, title, resetStyle, s)
|
||||||
if optPrintSurroundingSrc and msg in errMin..errMax:
|
if optPrintSurroundingSrc and msg in errMin..errMax:
|
||||||
info.writeSurroundingSrc
|
info.writeSurroundingSrc
|
||||||
handleError(msg, eh, s)
|
handleError(msg, eh, s)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue