Skip to content

Commit 56a1e37

Browse files
committed
feat: add read_file api
1 parent ed8c643 commit 56a1e37

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/lsp_client/protocol/client.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from abc import abstractmethod
4-
from collections.abc import AsyncGenerator, Sequence
4+
from collections.abc import AsyncGenerator
55
from contextlib import asynccontextmanager
66
from pathlib import Path
77
from typing import Protocol, runtime_checkable
@@ -37,12 +37,6 @@ def open_files(self, *file_paths: AnyPath) -> AsyncGenerator[None]:
3737
@abstractmethod
3838
async def request[R](self, req: Request, schema: type[Response[R]]) -> R: ...
3939

40-
async def file_request[R](
41-
self, req: Request, schema: type[Response[R]], file_paths: Sequence[AnyPath]
42-
):
43-
async with self.open_files(*file_paths):
44-
return await self.request(req, schema)
45-
4640
@abstractmethod
4741
async def notify(self, msg: Notification) -> None: ...
4842

@@ -77,3 +71,10 @@ def as_uri(self, file_path: AnyPath) -> str:
7771
def from_uri(self, uri: str) -> Path:
7872
"""Convert a URI to an absolute path."""
7973
return from_local_uri(uri)
74+
75+
def read_file(self, file_path: AnyPath) -> str:
76+
"""Read the content of a file in the workspace."""
77+
78+
uri = self.as_uri(file_path)
79+
abs_file_path = self.from_uri(uri)
80+
return abs_file_path.read_text()

0 commit comments

Comments
 (0)