1- package compiler
1+ package diagnosticwriter
22
33import (
44 "fmt"
@@ -15,7 +15,7 @@ import (
1515 "github.com/microsoft/typescript-go/internal/tspath"
1616)
1717
18- type DiagnosticsFormattingOptions struct {
18+ type FormattingOptions struct {
1919 tspath.ComparePathsOptions
2020 NewLine string
2121}
@@ -35,7 +35,7 @@ const (
3535 ellipsis = "..."
3636)
3737
38- func FormatDiagnosticsWithColorAndContext (output io.Writer , diags []* ast.Diagnostic , formatOpts * DiagnosticsFormattingOptions ) {
38+ func FormatDiagnosticsWithColorAndContext (output io.Writer , diags []* ast.Diagnostic , formatOpts * FormattingOptions ) {
3939 if len (diags ) == 0 {
4040 return
4141 }
@@ -80,7 +80,7 @@ func FormatDiagnosticsWithColorAndContext(output io.Writer, diags []*ast.Diagnos
8080 }
8181}
8282
83- func writeCodeSnippet (writer io.Writer , sourceFile * ast.SourceFile , start int , length int , squiggleColor string , formatOpts * DiagnosticsFormattingOptions ) {
83+ func writeCodeSnippet (writer io.Writer , sourceFile * ast.SourceFile , start int , length int , squiggleColor string , formatOpts * FormattingOptions ) {
8484 firstLine , firstLineChar := scanner .GetLineAndCharacterOfPosition (sourceFile , start )
8585 lastLine , lastLineChar := scanner .GetLineAndCharacterOfPosition (sourceFile , start + length )
8686
@@ -196,7 +196,7 @@ func writeWithStyleAndReset(output io.Writer, text string, formatStyle string) {
196196 fmt .Fprint (output , resetEscapeSequence )
197197}
198198
199- func WriteLocation (output io.Writer , file * ast.SourceFile , pos int , formatOpts * DiagnosticsFormattingOptions , writeWithStyleAndReset FormattedWriter ) {
199+ func WriteLocation (output io.Writer , file * ast.SourceFile , pos int , formatOpts * FormattingOptions , writeWithStyleAndReset FormattedWriter ) {
200200 firstLine , firstChar := scanner .GetLineAndCharacterOfPosition (file , pos )
201201 var relativeFileName string
202202 if formatOpts != nil {
@@ -221,7 +221,7 @@ type ErrorSummary struct {
221221 SortedFileList []* ast.SourceFile
222222}
223223
224- func WriteErrorSummaryText (output io.Writer , allDiagnostics []* ast.Diagnostic , formatOpts * DiagnosticsFormattingOptions ) {
224+ func WriteErrorSummaryText (output io.Writer , allDiagnostics []* ast.Diagnostic , formatOpts * FormattingOptions ) {
225225 // Roughly corresponds to 'getErrorSummaryText' from watch.ts
226226
227227 errorSummary := getErrorSummary (allDiagnostics )
@@ -299,7 +299,7 @@ func getErrorSummary(diags []*ast.Diagnostic) *ErrorSummary {
299299 }
300300}
301301
302- func writeTabularErrorsDisplay (output io.Writer , errorSummary * ErrorSummary , formatOpts * DiagnosticsFormattingOptions ) {
302+ func writeTabularErrorsDisplay (output io.Writer , errorSummary * ErrorSummary , formatOpts * FormattingOptions ) {
303303 sortedFiles := errorSummary .SortedFileList
304304
305305 maxErrors := 0
@@ -330,7 +330,7 @@ func writeTabularErrorsDisplay(output io.Writer, errorSummary *ErrorSummary, for
330330 }
331331}
332332
333- func prettyPathForFileError (file * ast.SourceFile , fileErrors []* ast.Diagnostic , formatOpts * DiagnosticsFormattingOptions ) string {
333+ func prettyPathForFileError (file * ast.SourceFile , fileErrors []* ast.Diagnostic , formatOpts * FormattingOptions ) string {
334334 line , _ := scanner .GetLineAndCharacterOfPosition (file , fileErrors [0 ].Loc ().Pos ())
335335 fileName := file .FileName ()
336336 if tspath .PathIsAbsolute (fileName ) && tspath .PathIsAbsolute (formatOpts .CurrentDirectory ) {
@@ -344,21 +344,21 @@ func prettyPathForFileError(file *ast.SourceFile, fileErrors []*ast.Diagnostic,
344344 )
345345}
346346
347- func WriteFormatDiagnostics (output io.Writer , diagnostics []* ast.Diagnostic , formatOpts * DiagnosticsFormattingOptions ) {
347+ func WriteFormatDiagnostics (output io.Writer , diagnostics []* ast.Diagnostic , formatOpts * FormattingOptions ) {
348348 for _ , diagnostic := range diagnostics {
349349 WriteFormatDiagnostic (output , diagnostic , formatOpts )
350350 }
351351}
352352
353- func WriteFormatDiagnostic (output io.Writer , diagnostic * ast.Diagnostic , formatOpts * DiagnosticsFormattingOptions ) {
353+ func WriteFormatDiagnostic (output io.Writer , diagnostic * ast.Diagnostic , formatOpts * FormattingOptions ) {
354354 if diagnostic .File () != nil {
355355 line , character := scanner .GetLineAndCharacterOfPosition (diagnostic .File (), diagnostic .Loc ().Pos ())
356356 fileName := diagnostic .File ().FileName ()
357357 relativeFileName := tspath .ConvertToRelativePath (fileName , formatOpts .ComparePathsOptions )
358358 fmt .Fprintf (output , "%s(%d,%d): " , relativeFileName , line + 1 , character + 1 )
359359 }
360360
361- fmt .Fprintf (output , "%s TS%d: " , diagnostic .Category ().String (), diagnostic .Code ())
361+ fmt .Fprintf (output , "%s TS%d: " , diagnostic .Category ().Name (), diagnostic .Code ())
362362 WriteFlattenedDiagnosticMessage (output , diagnostic , formatOpts .NewLine )
363363 fmt .Fprint (output , formatOpts .NewLine )
364364}
0 commit comments