Skip to content

fix: set language singleton early so git diff auto-detection works for non-Python languages#1859

Open
mashraf-222 wants to merge 2 commits intomainfrom
fix/set-language-singleton-early
Open

fix: set language singleton early so git diff auto-detection works for non-Python languages#1859
mashraf-222 wants to merge 2 commits intomainfrom
fix/set-language-singleton-early

Conversation

@mashraf-222
Copy link
Contributor

@mashraf-222 mashraf-222 commented Mar 18, 2026

Summary

Running codeflash --subagent without --file (auto-detect mode) always found 0 functions for Java/JS/TS projects because the language singleton defaulted to Python when get_git_diff() filtered by file extension.

Fix

  • config_parser.py: Always set config["language"] based on config file type (codeflash.toml → java, pyproject.toml → python; package.json already handled)
  • cli.py: Call set_current_language() in process_pyproject_config() before the optimizer runs

Testing

  • 15/15 tests/test_git_utils.py pass
  • E2E verified: cc-plugin stop hook → codeflash --subagent → Java function discovered from git diff

🤖 Generated with Claude Code

…r all languages

The language singleton was only set after function discovery, but get_git_diff()
needs it during discovery to filter by file extension. Now set it in
process_pyproject_config() based on the config file type.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude
Copy link
Contributor

claude bot commented Mar 18, 2026

Claude finished @mashraf-222's task in 9s —— View job


PR Review Summary

  • Triage: check changed files
  • Lint and typecheck
  • Resolve stale threads
  • Code review
  • Duplicate detection
  • Test coverage

Prek Checks

uv run prek run --from-ref origin/mainpassed (ruff check + ruff format both clean). No auto-fixes needed.

Mypy errors in config_parser.py (lines 151, 180, 187, 195, 208, 209) are pre-existing and not introduced by this PR.


Code Review

codeflash/code_utils/config_parser.py:163-166

if "language" not in config:
    config["language"] = "java" if config_file_path.name == "codeflash.toml" else "python"

The inference is correct: find_pyproject_toml() (line 138) walks up directories and returns either pyproject.toml or codeflash.toml, so mapping codeflash.toml → java and anything else → python is sound. JS/TS projects return early from parse_config_file via parse_package_json_config and never reach this code. The "language" not in config guard prevents overriding an explicitly set value.

codeflash/cli_cmds/cli.py:115-118

# Set the language singleton early so downstream code (e.g. get_git_diff)
# can use current_language_support() before function discovery.
if pyproject_config.get("language"):
    set_current_language(pyproject_config["language"])

Correct placement — process_pyproject_config runs before the optimizer/discovery, so get_git_diff (which calls current_language_support().file_extensions) will see the right language.

Minor note: since config_parser.py now always sets "language", the if pyproject_config.get("language") guard will always be truthy for valid configs. This is harmless but slightly redundant.

The set_current_language call in optimizer.py:478 (set_current_language(funcs[0].language)) is complementary — it runs later post-discovery and is consistent with the config-based value.

No bugs or security issues found.


Duplicate Detection

No duplicates detected. The two set_current_language call sites serve different purposes: the new one in cli.py sets the language from config early (before discovery), while optimizer.py:478 sets it from the discovered function's language after discovery.


Test Coverage

Relevant tests pass: 15/15 test_git_utils.py, 49 passed across test_worktree.py, test_formatter.py, test_git_utils.py.

One gap: there is no dedicated unit test for the new language-inference logic in config_parser.py (specifically the codeflash.toml → java path). The process_pyproject_config early set_current_language call also lacks a direct test for non-Python configs. Consider adding a test that parses a minimal codeflash.toml and asserts config["language"] == "java" to lock in this behavior.


Last updated: 2026-03-18T00:36Z

…r all languages

The language singleton was only set after function discovery, but get_git_diff()
needs it during discovery to filter by file extension.

- config_parser.py: set config["language"] based on config file type (codeflash.toml
  → java, pyproject.toml → python) so all project types return a language
- cli.py: call set_current_language() in process_pyproject_config() using the
  config value, before the optimizer runs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mashraf-222 mashraf-222 force-pushed the fix/set-language-singleton-early branch from 8c9aab5 to d9dfb0b Compare March 18, 2026 00:34
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.

2 participants