Skip to content

Fix listFiles/listFilesOnly #964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 37 additions & 28 deletions internal/execute/tsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"runtime"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -203,7 +204,7 @@ func performCompilation(sys System, cb cbType, config *tsoptions.ParsedCommandLi
program := compiler.NewProgramFromParsedCommandLine(config, host)
parseTime := time.Since(parseStart)

result := compileAndEmit(sys, program, reportDiagnostic)
result := emitFilesAndReportErrors(sys, program, reportDiagnostic)
if result.status != ExitStatusSuccess {
// compile exited early
return result.status
Expand Down Expand Up @@ -245,59 +246,57 @@ type compileAndEmitResult struct {
totalTime time.Duration
}

func compileAndEmit(sys System, program *compiler.Program, reportDiagnostic diagnosticReporter) (result compileAndEmitResult) {
// todo: check if third return needed after execute is fully implemented

func emitFilesAndReportErrors(sys System, program *compiler.Program, reportDiagnostic diagnosticReporter) (result compileAndEmitResult) {
ctx := context.Background()
options := program.Options()
allDiagnostics := program.GetConfigFileParsingDiagnostics()
allDiagnostics := slices.Clip(program.GetConfigFileParsingDiagnostics())
configFileParsingDiagnosticsLength := len(allDiagnostics)

allDiagnostics = append(allDiagnostics, program.GetSyntacticDiagnostics(ctx, nil)...)

// todo: early exit logic and append diagnostics
diagnostics := program.GetSyntacticDiagnostics(ctx, nil)
if len(diagnostics) == 0 {
if len(allDiagnostics) == configFileParsingDiagnosticsLength {
// Options diagnostics include global diagnostics (even though we collect them separately),
// and global diagnostics create checkers, which then bind all of the files. Do this binding
// early so we can track the time.
bindStart := time.Now()
_ = program.GetBindDiagnostics(ctx, nil)
result.bindTime = time.Since(bindStart)

diagnostics = append(diagnostics, program.GetOptionsDiagnostics(ctx)...)
if options.ListFilesOnly.IsFalse() {
// program.GetBindDiagnostics(nil)
diagnostics = append(diagnostics, program.GetGlobalDiagnostics(ctx)...)
allDiagnostics = append(allDiagnostics, program.GetOptionsDiagnostics(ctx)...)

if options.ListFilesOnly.IsFalseOrUnknown() {
allDiagnostics = append(allDiagnostics, program.GetGlobalDiagnostics(ctx)...)

if len(allDiagnostics) == configFileParsingDiagnosticsLength {
checkStart := time.Now()
allDiagnostics = append(allDiagnostics, program.GetSemanticDiagnostics(ctx, nil)...)
result.checkTime = time.Since(checkStart)
}

// !!! GetDeclarationDiagnostics
// if options.NoEmit.IsTrue() && options.GetEmitDeclarations() && len(allDiagnostics) == configFileParsingDiagnosticsLength {
// }
}
}
if len(diagnostics) == 0 {
checkStart := time.Now()
diagnostics = append(diagnostics, program.GetSemanticDiagnostics(ctx, nil)...)
result.checkTime = time.Since(checkStart)
}
// TODO: declaration diagnostics
if len(diagnostics) == 0 && options.NoEmit == core.TSTrue && (options.Declaration.IsTrue() && options.Composite.IsTrue()) {
result.status = ExitStatusNotImplemented
return result
// addRange(allDiagnostics, program.getDeclarationDiagnostics(/*sourceFile*/ undefined, cancellationToken));
}

emitResult := &compiler.EmitResult{EmitSkipped: true, Diagnostics: []*ast.Diagnostic{}}
if !options.ListFilesOnly.IsTrue() {
// !!! Emit is not yet fully implemented, will not emit unless `outfile` specified
emitStart := time.Now()
emitResult = program.Emit(compiler.EmitOptions{})
result.emitTime = time.Since(emitStart)
}
diagnostics = append(diagnostics, emitResult.Diagnostics...)
allDiagnostics = append(allDiagnostics, emitResult.Diagnostics...)

allDiagnostics = append(allDiagnostics, diagnostics...)
allDiagnostics = compiler.SortAndDeduplicateDiagnostics(allDiagnostics)
for _, diagnostic := range allDiagnostics {
reportDiagnostic(diagnostic)
}

// !!! if (write)
if sys.Writer() != nil {
for _, file := range emitResult.EmittedFiles {
fmt.Fprint(sys.Writer(), "TSFILE: ", tspath.GetNormalizedAbsolutePath(file, sys.GetCurrentDirectory()))
}
// todo: listFiles(program, sys.Writer())
listFiles(sys, program)
}

createReportErrorSummary(sys, program.Options())(allDiagnostics)
Expand Down Expand Up @@ -325,3 +324,13 @@ func showConfig(sys System, config *core.CompilerOptions) {
enc.SetIndent("", " ")
enc.Encode(config) //nolint:errcheck,errchkjson
}

func listFiles(sys System, program *compiler.Program) {
options := program.Options()
// !!! explainFiles
if options.ListFiles.IsTrue() || options.ListFilesOnly.IsTrue() {
for _, file := range program.GetSourceFiles() {
fmt.Fprintf(sys.Writer(), "%s%s", file.FileName(), sys.NewLine())
}
}
}
2 changes: 1 addition & 1 deletion internal/execute/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func createWatcher(sys System, configParseResult *tsoptions.ParsedCommandLine, r
func (w *watcher) compileAndEmit() {
// !!! output/error reporting is currently the same as non-watch mode
// diagnostics, emitResult, exitStatus :=
compileAndEmit(w.sys, w.program, w.reportDiagnostic)
emitFilesAndReportErrors(w.sys, w.program, w.reportDiagnostic)
}

func (w *watcher) hasErrorsInTsConfig() bool {
Expand Down