@@ -21,7 +21,7 @@ type FormattingOptions struct {
2121}
2222
2323const (
24- foregroundColorEscapeGrey = "\u001b [90m"
24+ ForegroundColorEscapeGrey = "\u001b [90m"
2525 foregroundColorEscapeRed = "\u001b [91m"
2626 foregroundColorEscapeYellow = "\u001b [93m"
2727 foregroundColorEscapeBlue = "\u001b [94m"
@@ -39,43 +39,45 @@ func FormatDiagnosticsWithColorAndContext(output io.Writer, diags []*ast.Diagnos
3939 if len (diags ) == 0 {
4040 return
4141 }
42-
4342 for i , diagnostic := range diags {
4443 if i > 0 {
4544 fmt .Fprint (output , formatOpts .NewLine )
4645 }
46+ FormatDiagnosticWithColorAndContext (output , diagnostic , formatOpts )
47+ }
48+ }
4749
48- if diagnostic .File () != nil {
49- file := diagnostic .File ()
50- pos := diagnostic .Loc ().Pos ()
51- WriteLocation (output , file , pos , formatOpts , writeWithStyleAndReset )
52- fmt .Fprint (output , " - " )
53- }
50+ func FormatDiagnosticWithColorAndContext (output io.Writer , diagnostic * ast.Diagnostic , formatOpts * FormattingOptions ) {
51+ if diagnostic .File () != nil {
52+ file := diagnostic .File ()
53+ pos := diagnostic .Loc ().Pos ()
54+ WriteLocation (output , file , pos , formatOpts , writeWithStyleAndReset )
55+ fmt .Fprint (output , " - " )
56+ }
5457
55- writeWithStyleAndReset (output , diagnostic .Category ().Name (), getCategoryFormat (diagnostic .Category ()))
56- fmt .Fprintf (output , "%s TS%d: %s" , foregroundColorEscapeGrey , diagnostic .Code (), resetEscapeSequence )
57- WriteFlattenedDiagnosticMessage (output , diagnostic , formatOpts .NewLine )
58+ writeWithStyleAndReset (output , diagnostic .Category ().Name (), getCategoryFormat (diagnostic .Category ()))
59+ fmt .Fprintf (output , "%s TS%d: %s" , ForegroundColorEscapeGrey , diagnostic .Code (), resetEscapeSequence )
60+ WriteFlattenedDiagnosticMessage (output , diagnostic , formatOpts .NewLine )
5861
59- if diagnostic .File () != nil && diagnostic .Code () != diagnostics .File_appears_to_be_binary .Code () {
60- fmt .Fprint (output , formatOpts .NewLine )
61- writeCodeSnippet (output , diagnostic .File (), diagnostic .Pos (), diagnostic .Len (), getCategoryFormat (diagnostic .Category ()), "" , formatOpts )
62- fmt .Fprint (output , formatOpts .NewLine )
63- }
62+ if diagnostic .File () != nil && diagnostic .Code () != diagnostics .File_appears_to_be_binary .Code () {
63+ fmt .Fprint (output , formatOpts .NewLine )
64+ writeCodeSnippet (output , diagnostic .File (), diagnostic .Pos (), diagnostic .Len (), getCategoryFormat (diagnostic .Category ()), "" , formatOpts )
65+ fmt .Fprint (output , formatOpts .NewLine )
66+ }
6467
65- if (diagnostic .RelatedInformation () != nil ) && (len (diagnostic .RelatedInformation ()) > 0 ) {
66- for _ , relatedInformation := range diagnostic .RelatedInformation () {
67- file := relatedInformation .File ()
68- if file != nil {
69- fmt .Fprint (output , formatOpts .NewLine )
70- fmt .Fprint (output , " " )
71- pos := relatedInformation .Pos ()
72- WriteLocation (output , file , pos , formatOpts , writeWithStyleAndReset )
73- fmt .Fprint (output , " - " )
74- WriteFlattenedDiagnosticMessage (output , relatedInformation , formatOpts .NewLine )
75- writeCodeSnippet (output , file , pos , relatedInformation .Len (), foregroundColorEscapeCyan , " " , formatOpts )
76- }
68+ if (diagnostic .RelatedInformation () != nil ) && (len (diagnostic .RelatedInformation ()) > 0 ) {
69+ for _ , relatedInformation := range diagnostic .RelatedInformation () {
70+ file := relatedInformation .File ()
71+ if file != nil {
7772 fmt .Fprint (output , formatOpts .NewLine )
73+ fmt .Fprint (output , " " )
74+ pos := relatedInformation .Pos ()
75+ WriteLocation (output , file , pos , formatOpts , writeWithStyleAndReset )
76+ fmt .Fprint (output , " - " )
77+ WriteFlattenedDiagnosticMessage (output , relatedInformation , formatOpts .NewLine )
78+ writeCodeSnippet (output , file , pos , relatedInformation .Len (), foregroundColorEscapeCyan , " " , formatOpts )
7879 }
80+ fmt .Fprint (output , formatOpts .NewLine )
7981 }
8082 }
8183}
@@ -196,7 +198,7 @@ func getCategoryFormat(category diagnostics.Category) string {
196198 case diagnostics .CategoryWarning :
197199 return foregroundColorEscapeYellow
198200 case diagnostics .CategorySuggestion :
199- return foregroundColorEscapeGrey
201+ return ForegroundColorEscapeGrey
200202 case diagnostics .CategoryMessage :
201203 return foregroundColorEscapeBlue
202204 }
@@ -359,7 +361,7 @@ func prettyPathForFileError(file *ast.SourceFile, fileErrors []*ast.Diagnostic,
359361 }
360362 return fmt .Sprintf ("%s%s:%d%s" ,
361363 fileName ,
362- foregroundColorEscapeGrey ,
364+ ForegroundColorEscapeGrey ,
363365 line + 1 ,
364366 resetEscapeSequence ,
365367 )
@@ -383,3 +385,15 @@ func WriteFormatDiagnostic(output io.Writer, diagnostic *ast.Diagnostic, formatO
383385 WriteFlattenedDiagnosticMessage (output , diagnostic , formatOpts .NewLine )
384386 fmt .Fprint (output , formatOpts .NewLine )
385387}
388+
389+ func FormatDiagnosticsStatusWithColorAndTime (output io.Writer , time string , diag * ast.Diagnostic , formatOpts * FormattingOptions ) {
390+ fmt .Fprint (output , "[" )
391+ writeWithStyleAndReset (output , time , ForegroundColorEscapeGrey )
392+ fmt .Fprint (output , "] " )
393+ WriteFlattenedDiagnosticMessage (output , diag , formatOpts .NewLine )
394+ }
395+
396+ func FormatDiagnosticsStatusAndTime (output io.Writer , time string , diag * ast.Diagnostic , formatOpts * FormattingOptions ) {
397+ fmt .Fprint (output , time , " - " )
398+ WriteFlattenedDiagnosticMessage (output , diag , formatOpts .NewLine )
399+ }
0 commit comments