Skip to content

Fix --showConfig to include files field#3343

Open
Copilot wants to merge 4 commits intomainfrom
copilot/fix-showconfig-missing-files-field
Open

Fix --showConfig to include files field#3343
Copilot wants to merge 4 commits intomainfrom
copilot/fix-showconfig-missing-files-field

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 5, 2026

tsgo --showConfig omits the files field from output while tsc --showConfig includes all resolved files.

Root cause: matchesSpecs in showconfig.go used the config file's directory as the base path for glob matching, causing include patterns like **/* to correctly match source files and filter them all out. TypeScript's convertToTSConfig has a bug where it passes the config file path (including tsconfig.json filename) to getFileMatcherPatterns, producing patterns that never match actual source files—so all resolved files pass through to the output.

Fix:

  • Removed the matchesSpecs function entirely rather than porting TypeScript's buggy filtering logic
  • Removed the vfsmatch import (no longer needed)
  • Simplified the file list building to just include all resolved files directly as relative paths, making the intent obvious:
    // Build the list of all resolved files as relative paths from the config file.
    var files []string
    for _, f := range configParseResult.FileNames() {
        normalizedFilePath := tspath.GetNormalizedAbsolutePath(f, configParseResult.GetCurrentDirectory())
        relativePath := tspath.GetRelativePathFromFile(normalizedConfigPath, normalizedFilePath, comparePathsOptions)
        files = append(files, relativePath)
    }
  • Handled the empty configFileName case (e.g., tsgo --showConfig file0.ts with no tsconfig loaded) by defaulting to "tsconfig.json", so path relativization works correctly from the current directory instead of its parent
  • Added test case reproducing the reported scenario (tsconfig with outDir + exclude, no explicit files/include)
  • Updated 9 affected baselines that now correctly include the files field

Copilot AI linked an issue Apr 5, 2026 that may be closed by this pull request
The matchesSpecs function used the config file directory as the base path
for pattern matching, causing include patterns to correctly match source
files and filter them out. TypeScript's convertToTSConfig uses the config
file path (including the filename) as the base, which causes include
patterns to never match source files, so all resolved files appear in
the files output. Changed Go code to match TypeScript's behavior.

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/6094e405-8017-4e5c-aa1d-5faafce1f785

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix --showConfig to include files field in output Fix --showConfig to include files field Apr 5, 2026
Copilot AI requested a review from jakebailey April 5, 2026 05:46
// (including the filename, e.g. "/project/tsconfig.json") is used as the base path
// for pattern matching, not the directory. This causes include patterns like "**/*"
// to resolve relative to the file (e.g. "/project/tsconfig.json/**/*"), which never
// matches actual source files, so all resolved files appear in the "files" output.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Rather than port the buggy code to maintain this behavior, just implement it from scratch in a way that makes it obvious that we are just sticking everything in here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified in b66ec50 — removed matchesSpecs entirely and just include all resolved files directly. No more porting the buggy filter logic.

Instead of porting TypeScript's buggy matchesSpecs behavior (where
using the config file path as base causes patterns to never match),
simply include all resolved files in the output directly.

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/219fac50-44be-4142-ad1c-7c5eed695897

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI requested a review from jakebailey April 5, 2026 07:46
@jakebailey jakebailey marked this pull request as ready for review April 6, 2026 19:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes tsgo --showConfig so it includes the files field (listing resolved root files) in cases where tsc --showConfig does, aligning tsgo output with TypeScript’s behavior.

Changes:

  • Removed include/exclude-based filtering when constructing the files list; --showConfig now emits all resolved files.
  • Added a regression test covering outDir + exclude with no explicit files/include.
  • Updated/added showConfig baselines to reflect the newly-present files field.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/tsoptions/showconfig.go Always emits files as all resolved root files (relative paths), removing prior filtering logic and dependency on vfsmatch.
internal/execute/tsctests/showconfig_test.go Adds a new --showConfig test scenario for exclude + outDir.
testdata/baselines/reference/tsc/showConfig/Show-TSConfig-with-transitively-implied-options.js Baseline updated to include files.
testdata/baselines/reference/tsc/showConfig/Show-TSConfig-with-references.js Baseline updated to include files.
testdata/baselines/reference/tsc/showConfig/Show-TSConfig-with-paths-and-more.js Baseline updated to include files.
testdata/baselines/reference/tsc/showConfig/Show-TSConfig-with-include-filtering-files.js Baseline updated to include files.
testdata/baselines/reference/tsc/showConfig/Show-TSConfig-with-files-and-include.js Baseline updated to include files (now includes resolved included files too).
testdata/baselines/reference/tsc/showConfig/Show-TSConfig-with-exclude.js Baseline updated to include files.
testdata/baselines/reference/tsc/showConfig/Show-TSConfig-with-exclude-and-outDir.js New baseline for the added regression test scenario.
testdata/baselines/reference/tsc/showConfig/Show-TSConfig-with-compileOnSave-and-more.js Baseline updated to include files.
Comments suppressed due to low confidence (1)

internal/tsoptions/showconfig.go:77

  • Minor perf: files grows via append without a capacity hint. Since configParseResult.FileNames() is already available, consider preallocating files with make([]string, 0, len(...)) to avoid repeated reallocations for large projects.
	var files []string
	for _, f := range configParseResult.FileNames() {
		normalizedFilePath := tspath.GetNormalizedAbsolutePath(f, configParseResult.GetCurrentDirectory())
		relativePath := tspath.GetRelativePathFromFile(normalizedConfigPath, normalizedFilePath, comparePathsOptions)
		files = append(files, relativePath)
	}

When no tsconfig is loaded (e.g., `tsgo --showConfig file0.ts`),
configFileName is empty. GetNormalizedAbsolutePath("", cwd) returns
just the cwd, and GetRelativePathFromFile treats it as a file path,
relativizing from its parent directory — producing incorrect paths
like ./project/file0.ts.

Default to "tsconfig.json" so relativization works correctly from
the current directory.

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/54494f3a-f6b4-4dd4-9f3d-37adcfd6a231

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--showConfig does not include files field

3 participants