Skip to content

Fix tsconfig/jsconfig priority for JS files when both configs coexist in same directory#3740

Merged
andrewbranch merged 2 commits into
mainfrom
copilot/fix-tsconfig-priority-issue
May 7, 2026
Merged

Fix tsconfig/jsconfig priority for JS files when both configs coexist in same directory#3740
andrewbranch merged 2 commits into
mainfrom
copilot/fix-tsconfig-priority-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 7, 2026

When tsconfig.json and jsconfig.json coexist in the same directory, JS files were always falling through to the inferred project instead of being picked up by jsconfig.json. The ancestor config search in computeConfigFileName was skipping the entire starting directory, preventing discovery of a sibling jsconfig.json after tsconfig.json rejected the file.

Fix

Aligned computeConfigFileName with TSServer's forEachConfigFileLocation behavior:

  • When searching for ancestor of tsconfig.json: skip tsconfig.json but still check jsconfig.json in the same directory
  • When searching for ancestor of jsconfig.json: skip both (unchanged behavior)
// Before: single boolean skipped everything in the directory
skip := skipSearchInDirectoryOfFile

// After: granular skip per config type
skipTsconfig := skipSearchInDirectoryOfFile
skipJsconfig := skipSearchInDirectoryOfFile && !strings.HasSuffix(fileName, "/tsconfig.json")

Test

Added test verifying JS files route to jsconfig.json and TS files route to tsconfig.json when both configs exist in the same directory.

… when searching for ancestor of tsconfig.json

When both tsconfig.json and jsconfig.json exist in the same directory,
JS files should be managed by jsconfig.json when tsconfig.json doesn't
include them (e.g., allowJs is false).

Previously, computeConfigFileName would skip the entire directory when
searching for ancestor configs. Now, matching TSServer's behavior, when
searching for the ancestor of a tsconfig.json, we only skip tsconfig.json
itself and still check for jsconfig.json in the same directory.

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/8525f366-6fcd-472b-8124-ef393ba8263b

Co-authored-by: sandersn <293473+sandersn@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix tsconfig.json priority over jsconfig.json in same directory Fix tsconfig/jsconfig priority for JS files when both configs coexist in same directory May 7, 2026
Copilot AI requested a review from sandersn May 7, 2026 19:17
@sandersn sandersn marked this pull request as ready for review May 7, 2026 20:09
@sandersn sandersn requested review from andrewbranch and Copilot May 7, 2026 20: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

Fixes configured-project discovery so that when tsconfig.json and jsconfig.json coexist in the same directory, JavaScript files can still be correctly picked up by jsconfig.json (instead of falling through to the inferred project) after tsconfig.json is found but does not include the JS file.

Changes:

  • Adjusted computeConfigFileName ancestor search to skip tsconfig.json but still consider a sibling jsconfig.json when the starting file is tsconfig.json.
  • Added a session test asserting JS files route to the jsconfig.json project while TS files route to the tsconfig.json project when both configs exist.
Show a summary per file
File Description
internal/project/configfileregistrybuilder.go Refines per-config skipping behavior during ancestor config discovery to match TSServer behavior in mixed tsconfig/jsconfig directories.
internal/project/session_test.go Adds regression test for JS-vs-TS default project selection when both configs exist side-by-side.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread internal/project/configfileregistrybuilder.go
@andrewbranch andrewbranch enabled auto-merge May 7, 2026 20:34
@andrewbranch andrewbranch added this pull request to the merge queue May 7, 2026
Merged via the queue into main with commit 16ff7f0 May 7, 2026
25 checks passed
@andrewbranch andrewbranch deleted the copilot/fix-tsconfig-priority-issue branch May 7, 2026 21:10
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.

TSGo prioritizes tsconfig.json over jsconfig.json in the same directory, even for file types the former excludes

4 participants