Skip to content

Commit 4e1b5cf

Browse files
committed
Initial attempt at phase 1
1 parent 6187eb1 commit 4e1b5cf

12 files changed

Lines changed: 2918 additions & 16 deletions

File tree

codeflash/discovery/functions_to_optimize.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ class FunctionToOptimize:
135135
parents: A list of parent scopes, which could be classes or functions.
136136
starting_line: The starting line number of the function in the file.
137137
ending_line: The ending line number of the function in the file.
138+
starting_col: The starting column offset (for precise location in multi-line contexts).
139+
ending_col: The ending column offset (for precise location in multi-line contexts).
138140
is_async: Whether this function is defined as async.
141+
language: The programming language of this function (default: "python").
139142
140143
The qualified_name property provides the full name of the function, including
141144
any parent class or function names. The qualified_name_with_modules_from_root
@@ -148,7 +151,10 @@ class FunctionToOptimize:
148151
parents: list[FunctionParent] # list[ClassDef | FunctionDef | AsyncFunctionDef]
149152
starting_line: Optional[int] = None
150153
ending_line: Optional[int] = None
154+
starting_col: Optional[int] = None # Column offset for precise location
155+
ending_col: Optional[int] = None # Column offset for precise location
151156
is_async: bool = False
157+
language: str = "python" # Language identifier for multi-language support
152158

153159
@property
154160
def top_level_parent_name(self) -> str:

codeflash/languages/__init__.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Multi-language support for Codeflash.
3+
4+
This package provides the abstraction layer that allows Codeflash to support
5+
multiple programming languages while keeping the core optimization pipeline
6+
language-agnostic.
7+
8+
Usage:
9+
from codeflash.languages import get_language_support, Language
10+
11+
# Get language support for a file
12+
lang = get_language_support(Path("example.py"))
13+
14+
# Discover functions
15+
functions = lang.discover_functions(file_path)
16+
17+
# Replace a function
18+
new_source = lang.replace_function(file_path, function, new_code)
19+
"""
20+
21+
from codeflash.languages.base import (
22+
CodeContext,
23+
FunctionInfo,
24+
HelperFunction,
25+
Language,
26+
LanguageSupport,
27+
ParentInfo,
28+
TestInfo,
29+
TestResult,
30+
)
31+
from codeflash.languages.registry import (
32+
detect_project_language,
33+
get_language_support,
34+
get_supported_extensions,
35+
get_supported_languages,
36+
register_language,
37+
)
38+
39+
__all__ = [
40+
# Base types
41+
"Language",
42+
"LanguageSupport",
43+
"FunctionInfo",
44+
"ParentInfo",
45+
"CodeContext",
46+
"HelperFunction",
47+
"TestResult",
48+
"TestInfo",
49+
# Registry functions
50+
"get_language_support",
51+
"detect_project_language",
52+
"register_language",
53+
"get_supported_languages",
54+
"get_supported_extensions",
55+
]

0 commit comments

Comments
 (0)