Skip to content

Commit eebc4dc

Browse files
committed
interface with lsp
1 parent 96313f2 commit eebc4dc

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

myserver.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
from fastmcp import FastMCP
66

7+
from codeflash.lsp.server import CodeflashLanguageServer
8+
from codeflash.lsp.beta import perform_function_optimization, FunctionOptimizationParams, \
9+
initialize_function_optimization
710
from tests.scripts.end_to_end_test_utilities import TestConfig, run_codeflash_command
11+
from lsprotocol import types
812

913

1014
# Define lifespan context manager
@@ -13,10 +17,20 @@ async def lifespan(mcp: FastMCP) -> AsyncGenerator[None, Any]:
1317
print("Starting up...")
1418
print(mcp.name)
1519
# Do startup work here (connect to DB, initialize cache, etc.)
20+
server = CodeflashLanguageServer(name = "codeflash", version = "0.0.1")
21+
config_file = Path("/Users/codeflash/Downloads/codeflash-dev/codeflash/pyproject.toml")
22+
file = "/Users/codeflash/Downloads/codeflash-dev/codeflash/code_to_optimize/bubble_sort.py"
23+
function = "sorter"
24+
params = FunctionOptimizationParams(functionName=function, textDocument=types.TextDocumentIdentifier(Path(file).as_uri()))
25+
server.prepare_optimizer_arguments(config_file)
26+
initialize_function_optimization(server, params)
27+
perform_function_optimization(server, params)
28+
#optimize_code(file, function)
1629
yield
1730
# Cleanup work after shutdown
1831
print("Shutting down...")
19-
32+
server.cleanup_the_optimizer()
33+
server.shutdown()
2034

2135
mcp = FastMCP(
2236
name="codeflash",
@@ -28,7 +42,7 @@ async def lifespan(mcp: FastMCP) -> AsyncGenerator[None, Any]:
2842
)
2943

3044

31-
@mcp.tool
45+
#@mcp.tool
3246
def optimize_code(file: str, function: str) -> str:
3347
# TODO ask for pr or no pr if successful
3448
config = TestConfig(file_path=Path(f"{file}"), function_name=f"{function}", test_framework="pytest")
@@ -42,3 +56,4 @@ def optimize_code(file: str, function: str) -> str:
4256
if __name__ == "__main__":
4357
mcp.run(transport="stdio")
4458
# Optimize my codebase, the file is "/Users/codeflash/Downloads/codeflash-dev/codeflash/code_to_optimize/bubble_sort.py" and the function is "sorter"
59+

0 commit comments

Comments
 (0)