|
5 | 5 | "encoding/json"
|
6 | 6 | "fmt"
|
7 | 7 | "runtime"
|
| 8 | + "slices" |
8 | 9 | "strings"
|
9 | 10 | "time"
|
10 | 11 |
|
@@ -203,7 +204,7 @@ func performCompilation(sys System, cb cbType, config *tsoptions.ParsedCommandLi
|
203 | 204 | program := compiler.NewProgramFromParsedCommandLine(config, host)
|
204 | 205 | parseTime := time.Since(parseStart)
|
205 | 206 |
|
206 |
| - result := compileAndEmit(sys, program, reportDiagnostic) |
| 207 | + result := emitFilesAndReportErrors(sys, program, reportDiagnostic) |
207 | 208 | if result.status != ExitStatusSuccess {
|
208 | 209 | // compile exited early
|
209 | 210 | return result.status
|
@@ -245,59 +246,57 @@ type compileAndEmitResult struct {
|
245 | 246 | totalTime time.Duration
|
246 | 247 | }
|
247 | 248 |
|
248 |
| -func compileAndEmit(sys System, program *compiler.Program, reportDiagnostic diagnosticReporter) (result compileAndEmitResult) { |
249 |
| - // todo: check if third return needed after execute is fully implemented |
250 |
| - |
| 249 | +func emitFilesAndReportErrors(sys System, program *compiler.Program, reportDiagnostic diagnosticReporter) (result compileAndEmitResult) { |
251 | 250 | ctx := context.Background()
|
252 | 251 | options := program.Options()
|
253 |
| - allDiagnostics := program.GetConfigFileParsingDiagnostics() |
| 252 | + allDiagnostics := slices.Clip(program.GetConfigFileParsingDiagnostics()) |
| 253 | + configFileParsingDiagnosticsLength := len(allDiagnostics) |
| 254 | + |
| 255 | + allDiagnostics = append(allDiagnostics, program.GetSyntacticDiagnostics(ctx, nil)...) |
254 | 256 |
|
255 |
| - // todo: early exit logic and append diagnostics |
256 |
| - diagnostics := program.GetSyntacticDiagnostics(ctx, nil) |
257 |
| - if len(diagnostics) == 0 { |
| 257 | + if len(allDiagnostics) == configFileParsingDiagnosticsLength { |
| 258 | + // Options diagnostics include global diagnostics (even though we collect them separately), |
| 259 | + // and global diagnostics create checkers, which then bind all of the files. Do this binding |
| 260 | + // early so we can track the time. |
258 | 261 | bindStart := time.Now()
|
259 | 262 | _ = program.GetBindDiagnostics(ctx, nil)
|
260 | 263 | result.bindTime = time.Since(bindStart)
|
261 | 264 |
|
262 |
| - diagnostics = append(diagnostics, program.GetOptionsDiagnostics(ctx)...) |
263 |
| - if options.ListFilesOnly.IsFalse() { |
264 |
| - // program.GetBindDiagnostics(nil) |
265 |
| - diagnostics = append(diagnostics, program.GetGlobalDiagnostics(ctx)...) |
| 265 | + allDiagnostics = append(allDiagnostics, program.GetOptionsDiagnostics(ctx)...) |
| 266 | + |
| 267 | + if options.ListFilesOnly.IsFalseOrUnknown() { |
| 268 | + allDiagnostics = append(allDiagnostics, program.GetGlobalDiagnostics(ctx)...) |
| 269 | + |
| 270 | + if len(allDiagnostics) == configFileParsingDiagnosticsLength { |
| 271 | + checkStart := time.Now() |
| 272 | + allDiagnostics = append(allDiagnostics, program.GetSemanticDiagnostics(ctx, nil)...) |
| 273 | + result.checkTime = time.Since(checkStart) |
| 274 | + } |
| 275 | + |
| 276 | + // !!! GetDeclarationDiagnostics |
| 277 | + // if options.NoEmit.IsTrue() && options.GetEmitDeclarations() && len(allDiagnostics) == configFileParsingDiagnosticsLength { |
| 278 | + // } |
266 | 279 | }
|
267 | 280 | }
|
268 |
| - if len(diagnostics) == 0 { |
269 |
| - checkStart := time.Now() |
270 |
| - diagnostics = append(diagnostics, program.GetSemanticDiagnostics(ctx, nil)...) |
271 |
| - result.checkTime = time.Since(checkStart) |
272 |
| - } |
273 |
| - // TODO: declaration diagnostics |
274 |
| - if len(diagnostics) == 0 && options.NoEmit == core.TSTrue && (options.Declaration.IsTrue() && options.Composite.IsTrue()) { |
275 |
| - result.status = ExitStatusNotImplemented |
276 |
| - return result |
277 |
| - // addRange(allDiagnostics, program.getDeclarationDiagnostics(/*sourceFile*/ undefined, cancellationToken)); |
278 |
| - } |
279 | 281 |
|
280 | 282 | emitResult := &compiler.EmitResult{EmitSkipped: true, Diagnostics: []*ast.Diagnostic{}}
|
281 | 283 | if !options.ListFilesOnly.IsTrue() {
|
282 |
| - // !!! Emit is not yet fully implemented, will not emit unless `outfile` specified |
283 | 284 | emitStart := time.Now()
|
284 | 285 | emitResult = program.Emit(compiler.EmitOptions{})
|
285 | 286 | result.emitTime = time.Since(emitStart)
|
286 | 287 | }
|
287 |
| - diagnostics = append(diagnostics, emitResult.Diagnostics...) |
| 288 | + allDiagnostics = append(allDiagnostics, emitResult.Diagnostics...) |
288 | 289 |
|
289 |
| - allDiagnostics = append(allDiagnostics, diagnostics...) |
290 | 290 | allDiagnostics = compiler.SortAndDeduplicateDiagnostics(allDiagnostics)
|
291 | 291 | for _, diagnostic := range allDiagnostics {
|
292 | 292 | reportDiagnostic(diagnostic)
|
293 | 293 | }
|
294 | 294 |
|
295 |
| - // !!! if (write) |
296 | 295 | if sys.Writer() != nil {
|
297 | 296 | for _, file := range emitResult.EmittedFiles {
|
298 | 297 | fmt.Fprint(sys.Writer(), "TSFILE: ", tspath.GetNormalizedAbsolutePath(file, sys.GetCurrentDirectory()))
|
299 | 298 | }
|
300 |
| - // todo: listFiles(program, sys.Writer()) |
| 299 | + listFiles(sys, program) |
301 | 300 | }
|
302 | 301 |
|
303 | 302 | createReportErrorSummary(sys, program.Options())(allDiagnostics)
|
@@ -325,3 +324,13 @@ func showConfig(sys System, config *core.CompilerOptions) {
|
325 | 324 | enc.SetIndent("", " ")
|
326 | 325 | enc.Encode(config) //nolint:errcheck,errchkjson
|
327 | 326 | }
|
| 327 | + |
| 328 | +func listFiles(sys System, program *compiler.Program) { |
| 329 | + options := program.Options() |
| 330 | + // !!! explainFiles |
| 331 | + if options.ListFiles.IsTrue() || options.ListFilesOnly.IsTrue() { |
| 332 | + for _, file := range program.GetSourceFiles() { |
| 333 | + fmt.Fprintf(sys.Writer(), "%s%s", file.FileName(), sys.NewLine()) |
| 334 | + } |
| 335 | + } |
| 336 | +} |
0 commit comments