Skip to content

Commit ef1c9ef

Browse files
committed
Replace the usage of services functions with IDEService client
1 parent 5f1926f commit ef1c9ef

9 files changed

Lines changed: 32 additions & 76 deletions

File tree

ask-code/ask-code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "libs"))
77
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "libs"))
88

9-
from ide_services import get_lsp_brige_port # noqa: E402
9+
from ide_services import IDEService # noqa: E402
1010

1111

1212
def query(question, lsp_brige_port):
@@ -59,7 +59,7 @@ def main():
5959
print("Usage: python index_and_query.py query [question] [port]")
6060
sys.exit(1)
6161

62-
port = get_lsp_brige_port()
62+
port = IDEService().get_lsp_brige_port()
6363

6464
question = sys.argv[2]
6565
query(question, port)

commit/commit.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
sys.path.append(os.path.dirname(__file__))
1010

1111
from chatmark import Checkbox, Form, TextEditor # noqa: E402
12-
from ide_services.services import log_info
12+
from ide_services import IDEService # noqa: E402
1313
from llm_api import chat_completion_stream # noqa: E402
1414

1515
diff_too_large_message_en = (
@@ -67,17 +67,19 @@ def read_prompt_from_file(filename):
6767
- FileNotFoundError: If the file does not exist.
6868
- Exception: If any other error occurs during file reading.
6969
"""
70+
s = IDEService()
7071
try:
7172
with open(filename, "r", encoding="utf-8") as file:
7273
return file.read().strip()
7374
except FileNotFoundError:
74-
log_info(
75+
s.ide_logging(
76+
"info",
7577
f"File {filename} not found. "
76-
"Please make sure it exists in the same directory as the script."
78+
"Please make sure it exists in the same directory as the script.",
7779
)
7880
sys.exit(1)
7981
except Exception as e:
80-
log_info(f"An error occurred while reading the file {filename}: {e}")
82+
s.ide_logging("info", f"An error occurred while reading the file {filename}: {e}")
8183
sys.exit(1)
8284

8385

libs/ide_services/__init__.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
from .services import (
2-
get_lsp_brige_port,
3-
ide_language,
4-
ide_logging,
5-
install_python_env,
6-
update_slash_commands,
7-
)
1+
from .service import IDEService
82

93
__all__ = [
10-
"get_lsp_brige_port",
11-
"install_python_env",
12-
"update_slash_commands",
13-
"ide_language",
14-
"ide_logging",
4+
"IDEService",
155
]

libs/ide_services/service.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
from typing import List
21
import os
32
from functools import wraps
4-
from .types import Location, SymbolNode
3+
from typing import List
4+
55
import requests
66

7+
from .types import Location, SymbolNode
8+
79
BASE_SERVER_URL = os.environ.get("DEVCHAT_IDE_SERVICE_URL", "http://localhost:3000")
810

911

@@ -47,6 +49,15 @@ def wrapper(self, *args, **kwargs):
4749

4850

4951
class IDEService:
52+
"""
53+
Client for IDE service
54+
55+
Usage:
56+
client = IDEService()
57+
res = client.ide_language()
58+
res = client.ide_logging("info", "some message")
59+
"""
60+
5061
def __init__(self):
5162
self._result = None
5263

@@ -78,7 +89,5 @@ def get_document_symbols(self, abspath: str) -> List[SymbolNode]:
7889
return [SymbolNode.parse_obj(node) for node in self._result]
7990

8091
@rpc_method
81-
def find_type_def_locations(
82-
self, abspath: str, line: int, character: int
83-
) -> List[Location]:
92+
def find_type_def_locations(self, abspath: str, line: int, character: int) -> List[Location]:
8493
return [Location.parse_obj(loc) for loc in self._result]

libs/ide_services/services.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

libs/ide_services/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import List
2+
23
from pydantic import BaseModel
34

45

libs/llm_api/text_confirm.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
from chatmark import Checkbox, Form, TextEditor # noqa: #402
10-
from ide_services.services import log_info # noqa: #402
1110

1211

1312
class MissEditConfirmFieldException(Exception):

libs/llm_api/tools_call.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
1010

1111
from chatmark import Checkbox, Form, Radio, TextEditor # noqa: #402
12-
from ide_services.services import log_info, log_warn # noqa: #402
12+
from ide_services import IDEService # noqa: #402
1313

1414

1515
class MissToolsFieldException(Exception):
@@ -191,9 +191,10 @@ def wrapper(*args, **kwargs):
191191
# call function
192192
functions = {tool.function_name: tool for tool in tools}
193193
for call in response["all_calls"]:
194-
log_info(
194+
IDEService().ide_logging(
195+
"info",
195196
f"try to call function tool: {call['function_name']} "
196-
f"with {call['parameters']}"
197+
f"with {call['parameters']}",
197198
)
198199
tool = functions[call["function_name"]]
199200
result = tool(**json.loads(call["parameters"]))

unit_tests/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from chatmark import Checkbox, Form, Step, TextEditor # noqa: E402
1111
from find_reference_tests import find_reference_tests
1212
from i18n import TUILanguage, get_translation
13-
from ide_services import ide_language # noqa: E402
13+
from ide_services import IDEService # noqa: E402
1414
from model import (
1515
FuncToTest,
1616
TokenBudgetExceededException,
@@ -214,7 +214,8 @@ def main(input: str):
214214
user_prompt = f"Help me write unit tests for the `{func_name}` function"
215215

216216
repo_root = os.getcwd()
217-
ide_lang = ide_language()
217+
ide_lang = IDEService().ide_language()
218+
218219
tui_lang = TUILanguage.from_str(ide_lang)
219220
_i = get_translation(tui_lang)
220221

0 commit comments

Comments
 (0)