@@ -10,6 +10,7 @@ import (
10
10
"unicode"
11
11
12
12
"github.com/microsoft/typescript-go/internal/ast"
13
+ "github.com/microsoft/typescript-go/internal/core"
13
14
"github.com/microsoft/typescript-go/internal/diagnostics"
14
15
"github.com/microsoft/typescript-go/internal/scanner"
15
16
"github.com/microsoft/typescript-go/internal/tspath"
@@ -139,7 +140,8 @@ func writeCodeSnippet(writer io.Writer, sourceFile *ast.SourceFile, start int, l
139
140
fmt .Fprint (writer , resetEscapeSequence )
140
141
fmt .Fprint (writer , gutterSeparator )
141
142
fmt .Fprint (writer , squiggleColor )
142
- if i == firstLine {
143
+ switch i {
144
+ case firstLine :
143
145
// If we're on the last line, then limit it to the last character of the last line.
144
146
// Otherwise, we'll just squiggle the rest of the line, giving 'slice' no end position.
145
147
var lastCharForLine int
@@ -153,10 +155,10 @@ func writeCodeSnippet(writer io.Writer, sourceFile *ast.SourceFile, start int, l
153
155
// then squiggle the remainder of the line.
154
156
fmt .Fprint (writer , strings .Repeat (" " , firstLineChar ))
155
157
fmt .Fprint (writer , strings .Repeat ("~" , lastCharForLine - firstLineChar ))
156
- } else if i == lastLine {
158
+ case lastLine :
157
159
// Squiggle until the final character.
158
160
fmt .Fprint (writer , strings .Repeat ("~" , lastLineChar ))
159
- } else {
161
+ default :
160
162
// Squiggle the entire line.
161
163
fmt .Fprint (writer , strings .Repeat ("~" , len (lineContent )))
162
164
}
@@ -263,13 +265,14 @@ func WriteErrorSummaryText(output io.Writer, allDiagnostics []*ast.Diagnostic, f
263
265
message = diagnostics .Found_1_error_in_0 .Format (firstFileName )
264
266
}
265
267
} else {
266
- if numErroringFiles == 0 {
268
+ switch numErroringFiles {
269
+ case 0 :
267
270
// No file-specific errors.
268
271
message = diagnostics .Found_0_errors .Format (totalErrorCount )
269
- } else if numErroringFiles == 1 {
272
+ case 1 :
270
273
// One file with errors.
271
274
message = diagnostics .Found_0_errors_in_the_same_file_starting_at_Colon_1 .Format (totalErrorCount , firstFileName )
272
- } else {
275
+ default :
273
276
// Multiple files with errors.
274
277
message = diagnostics .Found_0_errors_in_1_files .Format (totalErrorCount , numErroringFiles )
275
278
}
@@ -397,3 +400,19 @@ func FormatDiagnosticsStatusAndTime(output io.Writer, time string, diag *ast.Dia
397
400
fmt .Fprint (output , time , " - " )
398
401
WriteFlattenedDiagnosticMessage (output , diag , formatOpts .NewLine )
399
402
}
403
+
404
+ var ScreenStartingCodes = []int32 {
405
+ diagnostics .Starting_compilation_in_watch_mode .Code (),
406
+ diagnostics .File_change_detected_Starting_incremental_compilation .Code (),
407
+ }
408
+
409
+ func TryClearScreen (output io.Writer , diag * ast.Diagnostic , options * core.CompilerOptions ) bool {
410
+ if ! options .PreserveWatchOutput .IsTrue () &&
411
+ ! options .ExtendedDiagnostics .IsTrue () &&
412
+ ! options .Diagnostics .IsTrue () &&
413
+ slices .Contains (ScreenStartingCodes , diag .Code ()) {
414
+ fmt .Fprint (output , "\x1B [2J\x1B [3J\x1B [H" ) // Clear screen and move cursor to home position
415
+ return true
416
+ }
417
+ return false
418
+ }
0 commit comments