Skip to content

Commit 8c9aab5

Browse files
mashraf-222claude
andcommitted
fix: set language singleton early so git diff auto-detection works for 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>
1 parent 0412be7 commit 8c9aab5

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

code_to_optimize/java/src/main/java/com/example/Fibonacci.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static long fibonacci(int n) {
1919
throw new IllegalArgumentException("Fibonacci not defined for negative numbers");
2020
}
2121
if (n <= 1) {
22-
return n;
22+
return n; // base case
2323
}
2424
return fibonacci(n - 1) + fibonacci(n - 2);
2525
}

codeflash/cli_cmds/cli.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,13 @@ def process_pyproject_config(args: Namespace) -> Namespace:
109109
assert args.module_root is not None, "--module-root must be specified"
110110
assert Path(args.module_root).is_dir(), f"--module-root {args.module_root} must be a valid directory"
111111

112-
# Determine project language from explicit config or config file name.
113-
# Java projects use codeflash.toml but don't always have an explicit language field.
114-
config_language = pyproject_config.get("language")
115-
if config_language is None and pyproject_file_path.name == "codeflash.toml":
116-
config_language = "java"
117-
is_js_ts_project = config_language in ("javascript", "typescript")
118-
is_java_project = config_language == "java"
112+
is_js_ts_project = pyproject_config.get("language") in ("javascript", "typescript")
113+
is_java_project = pyproject_config.get("language") == "java"
119114

120115
# Set the language singleton early so downstream code (e.g. get_git_diff)
121116
# can use current_language_support() before function discovery.
122-
if config_language:
123-
set_current_language(config_language)
117+
if pyproject_config.get("language"):
118+
set_current_language(pyproject_config["language"])
124119

125120
# Set the test framework singleton for JS/TS projects
126121
if is_js_ts_project and pyproject_config.get("test_framework"):

codeflash/code_utils/config_parser.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ def parse_config_file(
160160
if config == {} and lsp_mode:
161161
return {}, config_file_path
162162

163-
# Preserve language field if present (important for Java/JS projects using codeflash.toml)
163+
# Set language based on config file type if not already present.
164+
# JS/TS projects set this in parse_package_json_config; for toml projects we infer it here.
165+
if "language" not in config:
166+
config["language"] = "java" if config_file_path.name == "codeflash.toml" else "python"
167+
164168
# default values:
165169
path_keys = ["module-root", "tests-root", "benchmarks-root"]
166170
path_list_keys = ["ignore-paths"]

0 commit comments

Comments
 (0)