1
- package compiler
1
+ package diagnosticwriter
2
2
3
3
import (
4
4
"fmt"
@@ -15,7 +15,7 @@ import (
15
15
"github.com/microsoft/typescript-go/internal/tspath"
16
16
)
17
17
18
- type DiagnosticsFormattingOptions struct {
18
+ type FormattingOptions struct {
19
19
tspath.ComparePathsOptions
20
20
NewLine string
21
21
}
@@ -35,7 +35,7 @@ const (
35
35
ellipsis = "..."
36
36
)
37
37
38
- func FormatDiagnosticsWithColorAndContext (output io.Writer , diags []* ast.Diagnostic , formatOpts * DiagnosticsFormattingOptions ) {
38
+ func FormatDiagnosticsWithColorAndContext (output io.Writer , diags []* ast.Diagnostic , formatOpts * FormattingOptions ) {
39
39
if len (diags ) == 0 {
40
40
return
41
41
}
@@ -80,7 +80,7 @@ func FormatDiagnosticsWithColorAndContext(output io.Writer, diags []*ast.Diagnos
80
80
}
81
81
}
82
82
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 ) {
84
84
firstLine , firstLineChar := scanner .GetLineAndCharacterOfPosition (sourceFile , start )
85
85
lastLine , lastLineChar := scanner .GetLineAndCharacterOfPosition (sourceFile , start + length )
86
86
@@ -196,7 +196,7 @@ func writeWithStyleAndReset(output io.Writer, text string, formatStyle string) {
196
196
fmt .Fprint (output , resetEscapeSequence )
197
197
}
198
198
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 ) {
200
200
firstLine , firstChar := scanner .GetLineAndCharacterOfPosition (file , pos )
201
201
var relativeFileName string
202
202
if formatOpts != nil {
@@ -221,7 +221,7 @@ type ErrorSummary struct {
221
221
SortedFileList []* ast.SourceFile
222
222
}
223
223
224
- func WriteErrorSummaryText (output io.Writer , allDiagnostics []* ast.Diagnostic , formatOpts * DiagnosticsFormattingOptions ) {
224
+ func WriteErrorSummaryText (output io.Writer , allDiagnostics []* ast.Diagnostic , formatOpts * FormattingOptions ) {
225
225
// Roughly corresponds to 'getErrorSummaryText' from watch.ts
226
226
227
227
errorSummary := getErrorSummary (allDiagnostics )
@@ -299,7 +299,7 @@ func getErrorSummary(diags []*ast.Diagnostic) *ErrorSummary {
299
299
}
300
300
}
301
301
302
- func writeTabularErrorsDisplay (output io.Writer , errorSummary * ErrorSummary , formatOpts * DiagnosticsFormattingOptions ) {
302
+ func writeTabularErrorsDisplay (output io.Writer , errorSummary * ErrorSummary , formatOpts * FormattingOptions ) {
303
303
sortedFiles := errorSummary .SortedFileList
304
304
305
305
maxErrors := 0
@@ -330,7 +330,7 @@ func writeTabularErrorsDisplay(output io.Writer, errorSummary *ErrorSummary, for
330
330
}
331
331
}
332
332
333
- func prettyPathForFileError (file * ast.SourceFile , fileErrors []* ast.Diagnostic , formatOpts * DiagnosticsFormattingOptions ) string {
333
+ func prettyPathForFileError (file * ast.SourceFile , fileErrors []* ast.Diagnostic , formatOpts * FormattingOptions ) string {
334
334
line , _ := scanner .GetLineAndCharacterOfPosition (file , fileErrors [0 ].Loc ().Pos ())
335
335
fileName := file .FileName ()
336
336
if tspath .PathIsAbsolute (fileName ) && tspath .PathIsAbsolute (formatOpts .CurrentDirectory ) {
@@ -344,21 +344,21 @@ func prettyPathForFileError(file *ast.SourceFile, fileErrors []*ast.Diagnostic,
344
344
)
345
345
}
346
346
347
- func WriteFormatDiagnostics (output io.Writer , diagnostics []* ast.Diagnostic , formatOpts * DiagnosticsFormattingOptions ) {
347
+ func WriteFormatDiagnostics (output io.Writer , diagnostics []* ast.Diagnostic , formatOpts * FormattingOptions ) {
348
348
for _ , diagnostic := range diagnostics {
349
349
WriteFormatDiagnostic (output , diagnostic , formatOpts )
350
350
}
351
351
}
352
352
353
- func WriteFormatDiagnostic (output io.Writer , diagnostic * ast.Diagnostic , formatOpts * DiagnosticsFormattingOptions ) {
353
+ func WriteFormatDiagnostic (output io.Writer , diagnostic * ast.Diagnostic , formatOpts * FormattingOptions ) {
354
354
if diagnostic .File () != nil {
355
355
line , character := scanner .GetLineAndCharacterOfPosition (diagnostic .File (), diagnostic .Loc ().Pos ())
356
356
fileName := diagnostic .File ().FileName ()
357
357
relativeFileName := tspath .ConvertToRelativePath (fileName , formatOpts .ComparePathsOptions )
358
358
fmt .Fprintf (output , "%s(%d,%d): " , relativeFileName , line + 1 , character + 1 )
359
359
}
360
360
361
- fmt .Fprintf (output , "%s TS%d: " , diagnostic .Category ().String (), diagnostic .Code ())
361
+ fmt .Fprintf (output , "%s TS%d: " , diagnostic .Category ().Name (), diagnostic .Code ())
362
362
WriteFlattenedDiagnosticMessage (output , diagnostic , formatOpts .NewLine )
363
363
fmt .Fprint (output , formatOpts .NewLine )
364
364
}
0 commit comments