Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c53f2f6
windows fix in vsc correct function choosing from the file
mashraf-222 Nov 28, 2025
f869b61
ensure the optimization starts for the function
mashraf-222 Nov 28, 2025
da1fca0
using pathlib
mashraf-222 Nov 28, 2025
f0b4657
formatting and linting fixes
mashraf-222 Nov 28, 2025
d62462d
fix linting errors
mashraf-222 Nov 28, 2025
8b4a5f5
FIX FAILING TEST
mashraf-222 Dec 1, 2025
d2a2e96
fix linting error
mashraf-222 Dec 1, 2025
3694c80
fixing one test after windows changes
mashraf-222 Dec 2, 2025
5987a57
update the unicode delimiter to be windows compatible
mashraf-222 Dec 4, 2025
1964abd
Merge branch 'main' into ashraf/cf-918-fix-vsc-extension-windows-bugs
mashraf-222 Dec 4, 2025
4344374
fix tests discovery in windows for vsc
mashraf-222 Dec 4, 2025
9b78d88
fix Starting baseline establishment in windows
mashraf-222 Dec 8, 2025
784378c
adding _manual_cleanup_worktree_directory
mashraf-222 Dec 8, 2025
194bad5
Improved the manual cleanup function to handle Windows file locking a…
mashraf-222 Dec 8, 2025
5e1b108
clean and optimize the git worktree deletion failure handling
mashraf-222 Dec 8, 2025
7404d01
clean up added logs
mashraf-222 Dec 9, 2025
5b2dfc1
Merge branch 'main' into ashraf/cf-918-fix-vsc-extension-windows-bugs
mashraf-222 Dec 9, 2025
dff190d
fix conflict
mashraf-222 Dec 9, 2025
9833272
Merge branch 'main' into ashraf/cf-918-fix-vsc-extension-windows-bugs
mashraf-222 Dec 9, 2025
04fbab9
fix capture_mode for windows for failing tests
mashraf-222 Dec 9, 2025
c443801
fix linting
mashraf-222 Dec 9, 2025
9336f3b
fix linting
mashraf-222 Dec 9, 2025
cc742fc
fix pre-commit errors
mashraf-222 Dec 9, 2025
db8cb46
Merge branch 'main' into ashraf/cf-918-fix-vsc-extension-windows-bugs
mashraf-222 Dec 10, 2025
f824ea5
FIX for failing test test_function_discovery.py::test_filter_functions
mashraf-222 Dec 10, 2025
e05aab2
removing git worktree logs
mashraf-222 Dec 10, 2025
a12f002
fix linting after removing logs
mashraf-222 Dec 10, 2025
52f19e4
Fixed inconsistent path resolution which can cause relative_to() chec…
mashraf-222 Dec 10, 2025
bc779ff
Updated trace_benchmarks_pytest to use the same Windows-safe subproce…
mashraf-222 Dec 10, 2025
ac35af3
pre-commit fixes
mashraf-222 Dec 10, 2025
84d056d
Merge branch 'main' into ashraf/cf-918-fix-vsc-extension-windows-bugs
Saga4 Dec 12, 2025
1d0802d
Merge branch 'main' into ashraf/cf-918-fix-vsc-extension-windows-bugs
Saga4 Dec 12, 2025
df29969
Merge branch 'main' into ashraf/cf-918-fix-vsc-extension-windows-bugs
mohammedahmed18 Dec 19, 2025
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
12 changes: 8 additions & 4 deletions codeflash/discovery/functions_to_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,28 +671,32 @@ def filter_functions(
previous_checkpoint_functions_removed_count: int = 0
tests_root_str = str(tests_root)
module_root_str = str(module_root)
# Normalize paths for case-insensitive comparison on Windows
tests_root_normalized = os.path.normcase(tests_root_str)
module_root_normalized = os.path.normcase(module_root_str)

# We desperately need Python 3.10+ only support to make this code readable with structural pattern matching
for file_path_path, functions in modified_functions.items():
_functions = functions
file_path = str(file_path_path)
if file_path.startswith(tests_root_str + os.sep):
file_path_normalized = os.path.normcase(file_path)
if file_path_normalized.startswith(tests_root_normalized + os.sep):
test_functions_removed_count += len(_functions)
continue
if file_path in ignore_paths or any(
file_path.startswith(str(ignore_path) + os.sep) for ignore_path in ignore_paths
file_path_normalized.startswith(os.path.normcase(str(ignore_path)) + os.sep) for ignore_path in ignore_paths
):
ignore_paths_removed_count += 1
continue
if file_path in submodule_paths or any(
file_path.startswith(str(submodule_path) + os.sep) for submodule_path in submodule_paths
file_path_normalized.startswith(os.path.normcase(str(submodule_path)) + os.sep) for submodule_path in submodule_paths
):
submodule_ignored_paths_count += 1
continue
if path_belongs_to_site_packages(Path(file_path)):
site_packages_removed_count += len(_functions)
continue
if not file_path.startswith(module_root_str + os.sep):
if not file_path_normalized.startswith(module_root_normalized + os.sep):
non_modules_removed_count += len(_functions)
continue
try:
Expand Down
7 changes: 5 additions & 2 deletions codeflash/lsp/beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,13 @@ def initialize_function_optimization(params: FunctionOptimizationInitParams) ->
server.current_optimization_init_result = initialization_result.unwrap()
server.show_message_log(f"Successfully initialized optimization for {params.functionName}", "Info")

files = [document.path]
# Use the worktree file path (which is normalized) instead of document.path
# document.path might be malformed on Windows (missing drive letter)
worktree_file_path = str(server.optimizer.args.file.resolve())
files = [worktree_file_path]

_, _, original_helpers = server.current_optimization_init_result
files.extend([str(helper_path) for helper_path in original_helpers])
files.extend([str(helper_path.resolve()) for helper_path in original_helpers])

return {"functionName": params.functionName, "status": "success", "files_inside_context": files}

Expand Down
43 changes: 42 additions & 1 deletion codeflash/optimization/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,48 @@ def mirror_paths_for_worktree_mode(self, worktree_dir: Path) -> None:


def mirror_path(path: Path, src_root: Path, dest_root: Path) -> Path:
relative_path = path.relative_to(src_root)
# Resolve both paths to absolute paths to handle Windows path normalization issues
# This ensures paths with/without drive letters are handled correctly
try:
path_resolved = path.resolve()
except (OSError, RuntimeError):
# If resolve fails (e.g., path doesn't exist or is malformed), try absolute()
path_resolved = path.absolute() if not path.is_absolute() else path

try:
src_root_resolved = src_root.resolve()
except (OSError, RuntimeError):
src_root_resolved = src_root.absolute() if not src_root.is_absolute() else src_root

# Normalize paths using os.path.normpath and normcase for cross-platform compatibility
path_str = os.path.normpath(str(path_resolved))
src_root_str = os.path.normpath(str(src_root_resolved))

# Convert to lowercase for case-insensitive comparison on Windows
path_normalized = os.path.normcase(path_str)
src_root_normalized = os.path.normcase(src_root_str)

# Try using Path.relative_to with resolved paths first
try:
relative_path = path_resolved.relative_to(src_root_resolved)
except ValueError:
# If relative_to fails, manually extract the relative path using normalized strings
if path_normalized.startswith(src_root_normalized):
# Extract relative path manually
# Use the original path_str to preserve proper path format
if path_str.startswith(src_root_str):
relative_str = path_str[len(src_root_str) :].lstrip(os.sep)
relative_path = Path(relative_str)
else:
# Fallback: use normalized paths
relative_str = path_normalized[len(src_root_normalized) :].lstrip(os.sep)
relative_path = Path(relative_str)
else:
raise ValueError(
f"Path {path_resolved} (normalized: {path_normalized}) is not relative to "
f"{src_root_resolved} (normalized: {src_root_normalized})"
)

return dest_root / relative_path


Expand Down
Loading