Skip to content

Commit

Permalink
fix request reading
Browse files Browse the repository at this point in the history
  • Loading branch information
dmed256 committed Oct 4, 2024
1 parent 7c83e1d commit 7d2e258
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 3 additions & 3 deletions python/src/aibo/tools/lang/python/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import aibo.tools.lsp.types as lsp_types
import aibo.tools.lsp.utils as lsp_utils
from aibo.tools.lang.python import ast_types
from aibo.tools.lang.python.source_finder import SourceFinder, SourceInfo
from aibo.tools.lang.python.source_finder import SourceFinder
from aibo.tools.lsp.lsp_service import LspService

__all__ = ["Finder"]
Expand All @@ -18,7 +18,7 @@
class SymbolSourceInfo(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)

symbol: lsp_types.WorkspaceSymbol
symbol: lsp_types.WorkspaceSymbol | lsp_types.DocumentSymbol
source_location: lsp_types.Location
source: str

Expand Down Expand Up @@ -156,7 +156,7 @@ async def find_symbol(
]

def get_source_info(
self, symbol: lsp_types.WorkspaceSymbol
self, symbol: lsp_types.WorkspaceSymbol | lsp_types.DocumentSymbol
) -> SymbolSourceInfo | None:
source_finder = SourceFinder(
filepath=lsp_utils.uri_to_filepath(symbol.location.uri),
Expand Down
7 changes: 6 additions & 1 deletion python/src/aibo/tools/lsp/types/location_types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Optional, Self

import aibo.tools.lsp.utils as lsp_utils
from aibo.tools.lsp.types.base_lsp_types import BaseLspModel

__all__ = [
Expand All @@ -15,7 +16,7 @@ class Position(BaseLspModel):
character: int

def __le__(self, other: Self) -> bool:
return (self.line, self.character) < (other.line, other.character)
return (self.line, self.character) <= (other.line, other.character)


class Range(BaseLspModel):
Expand Down Expand Up @@ -49,6 +50,10 @@ def content(self) -> str:

return "".join(lines)

@property
def filepath(self) -> str:
return lsp_utils.uri_to_filepath(self.uri)

def __contains__(self, other: Self) -> bool:
return other.range in self.range

Expand Down
13 changes: 11 additions & 2 deletions python/src/aibo/tools/lsp/types/lsp_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,18 @@ def _sync_read(cls, read_pipe: int) -> Union["LspResponse", None]:
for header_content in header.split(LSP_HEADER_DELIMITER)
if header_content.strip() and (kv := header_content.split(":"))
}
content_length = int(headers["Content-Length"])
if (content_length_str := headers.get("Content-Length")) is None:
return None

content_length = int(content_length_str)

response_json = ""
while content_length:
content_to_read = min(content_length, 65536)
content_bytes = os.read(read_pipe, content_to_read)
response_json += content_bytes.decode("utf-8").strip()
content_length -= len(content_bytes)

response_json = os.read(read_pipe, content_length).decode("utf-8").strip()
response_dict = json.loads(response_json)

# Sometimes we are passed a request ... but let's ignore them for now
Expand Down

0 comments on commit 7d2e258

Please sign in to comment.