@@ -10,6 +10,7 @@ import (
1010 "unicode"
1111
1212 "github.com/microsoft/typescript-go/internal/ast"
13+ "github.com/microsoft/typescript-go/internal/core"
1314 "github.com/microsoft/typescript-go/internal/diagnostics"
1415 "github.com/microsoft/typescript-go/internal/scanner"
1516 "github.com/microsoft/typescript-go/internal/tspath"
@@ -139,7 +140,8 @@ func writeCodeSnippet(writer io.Writer, sourceFile *ast.SourceFile, start int, l
139140 fmt .Fprint (writer , resetEscapeSequence )
140141 fmt .Fprint (writer , gutterSeparator )
141142 fmt .Fprint (writer , squiggleColor )
142- if i == firstLine {
143+ switch i {
144+ case firstLine :
143145 // If we're on the last line, then limit it to the last character of the last line.
144146 // Otherwise, we'll just squiggle the rest of the line, giving 'slice' no end position.
145147 var lastCharForLine int
@@ -153,10 +155,10 @@ func writeCodeSnippet(writer io.Writer, sourceFile *ast.SourceFile, start int, l
153155 // then squiggle the remainder of the line.
154156 fmt .Fprint (writer , strings .Repeat (" " , firstLineChar ))
155157 fmt .Fprint (writer , strings .Repeat ("~" , lastCharForLine - firstLineChar ))
156- } else if i == lastLine {
158+ case lastLine :
157159 // Squiggle until the final character.
158160 fmt .Fprint (writer , strings .Repeat ("~" , lastLineChar ))
159- } else {
161+ default :
160162 // Squiggle the entire line.
161163 fmt .Fprint (writer , strings .Repeat ("~" , len (lineContent )))
162164 }
@@ -263,13 +265,14 @@ func WriteErrorSummaryText(output io.Writer, allDiagnostics []*ast.Diagnostic, f
263265 message = diagnostics .Found_1_error_in_0 .Format (firstFileName )
264266 }
265267 } else {
266- if numErroringFiles == 0 {
268+ switch numErroringFiles {
269+ case 0 :
267270 // No file-specific errors.
268271 message = diagnostics .Found_0_errors .Format (totalErrorCount )
269- } else if numErroringFiles == 1 {
272+ case 1 :
270273 // One file with errors.
271274 message = diagnostics .Found_0_errors_in_the_same_file_starting_at_Colon_1 .Format (totalErrorCount , firstFileName )
272- } else {
275+ default :
273276 // Multiple files with errors.
274277 message = diagnostics .Found_0_errors_in_1_files .Format (totalErrorCount , numErroringFiles )
275278 }
@@ -397,3 +400,19 @@ func FormatDiagnosticsStatusAndTime(output io.Writer, time string, diag *ast.Dia
397400 fmt .Fprint (output , time , " - " )
398401 WriteFlattenedDiagnosticMessage (output , diag , formatOpts .NewLine )
399402}
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