128 lines
2.2 KiB
Python
Raw Permalink Normal View History

2023-11-30 07:57:24 +08:00
import os
2023-11-30 07:50:49 +08:00
from functools import wraps
2024-01-05 12:27:57 +08:00
import requests
2023-12-08 18:28:36 +08:00
BASE_SERVER_URL = os.environ.get("DEVCHAT_IDE_SERVICE_URL", "http://localhost:3000")
2023-11-30 07:50:49 +08:00
def rpc_call(f):
@wraps(f)
def wrapper(*args, **kwargs):
if os.environ.get("DEVCHAT_IDE_SERVICE_URL", "") == "":
# maybe in a test, user don't want to mock services functions
return
2023-11-30 07:50:49 +08:00
try:
function_name = f.__name__
url = f"{BASE_SERVER_URL}/{function_name}"
data = dict(zip(f.__code__.co_varnames, args))
data.update(kwargs)
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=data, headers=headers)
2023-11-30 07:50:49 +08:00
if response.status_code != 200:
raise Exception(f"Server error: {response.status_code}")
response_data = response.json()
if "error" in response_data:
raise Exception(f"Server returned an error: {response_data['error']}")
return response_data["result"]
except ConnectionError as err:
# TODO
raise err
2023-11-30 07:50:49 +08:00
return wrapper
@rpc_call
def get_lsp_brige_port():
2023-12-08 18:28:36 +08:00
pass
2023-12-18 09:17:32 +08:00
2023-12-18 09:17:32 +08:00
2023-12-18 09:17:32 +08:00
@rpc_call
def install_python_env(command_name: str, requirements_file: str) -> str:
pass
2023-12-18 09:17:32 +08:00
2023-12-18 09:17:32 +08:00
@rpc_call
def update_slash_commands():
pass
2023-12-18 09:17:32 +08:00
2023-12-18 09:17:32 +08:00
@rpc_call
def open_folder(folder: str):
pass
@rpc_call
def ide_language() -> str:
pass
@rpc_call
def log_info(message: str):
pass
@rpc_call
def log_warn(message: str):
pass
@rpc_call
def log_error(message: str):
pass
@rpc_call
def visible_lines(message: str):
pass
@rpc_call
def selected_lines(message: str):
pass
@rpc_call
def document_symbols(abspath: str):
pass
@rpc_call
def workspace_symbols(query: str):
pass
@rpc_call
def find_definition(abspath: str, line: int, col: int):
pass
@rpc_call
def find_type_definition(abspath: str, line: int, col: int):
pass
@rpc_call
def find_declaration(abspath: str, line: int, col: int):
pass
@rpc_call
def find_implementation(abspath: str, line: int, col: int):
pass
@rpc_call
def find_reference(abspath: str, line: int, col: int):
pass
@rpc_call
def diff_apply(filepath, content):
pass