From d0fed2b4d7045ac04b643665170077ef3b40cb40 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Tue, 12 Mar 2024 15:01:06 +0800 Subject: [PATCH 1/2] feat: Sync base library code updates from workflows - Expanded `__all__` in `types.py` to include new classes - Introduced `find_def_locations` method in `service.py` - Enhanced readability and hashing for model reprs in `types.py` --- devchat/ide/__init__.py | 3 ++- devchat/ide/service.py | 4 ++++ devchat/ide/types.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/devchat/ide/__init__.py b/devchat/ide/__init__.py index dbfd10ad..f86ae78b 100644 --- a/devchat/ide/__init__.py +++ b/devchat/ide/__init__.py @@ -1,5 +1,6 @@ from .service import IDEService +from .types import * -__all__ = [ +__all__ = types.__all__ + [ "IDEService", ] diff --git a/devchat/ide/service.py b/devchat/ide/service.py index 7afff5c2..ce477e1d 100644 --- a/devchat/ide/service.py +++ b/devchat/ide/service.py @@ -97,6 +97,10 @@ def find_type_def_locations(self, abspath: str, line: int, character: int) -> Li """ return [Location.parse_obj(loc) for loc in self._result] + @rpc_method + def find_def_locations(self, abspath: str, line: int, character: int) -> List[Location]: + return [Location.parse_obj(loc) for loc in self._result] + @rpc_method def ide_name(self) -> str: """Returns the name of the IDE. diff --git a/devchat/ide/types.py b/devchat/ide/types.py index 01fb463b..c999e53b 100644 --- a/devchat/ide/types.py +++ b/devchat/ide/types.py @@ -2,21 +2,47 @@ from pydantic import BaseModel +__all__ = [ + "Position", + "Range", + "Location", + "SymbolNode", + "LocationWithText" +] + class Position(BaseModel): line: int # 0-based character: int # 0-based + def __repr__(self): + return f"Ln{self.line}:Col{self.character}" + + def __hash__(self): + return hash(self.__repr__()) + class Range(BaseModel): start: Position end: Position + def __repr__(self): + return f"{self.start} - {self.end}" + + def __hash__(self): + return hash(self.__repr__()) + class Location(BaseModel): abspath: str range: Range + def __repr__(self): + return f"{self.abspath}::{self.range}" + + def __hash__(self): + return hash(self.__repr__()) + class SymbolNode(BaseModel): name: str @@ -29,3 +55,9 @@ class LocationWithText(BaseModel): abspath: str range: Range text: str + + def __repr__(self): + return f"{self.abspath}::{self.range}::{self.text}" + + def __hash__(self): + return hash(self.__repr__()) From b5355f9cf49c033a8a97ee134f31a951273978bd Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Tue, 12 Mar 2024 15:11:56 +0800 Subject: [PATCH 2/2] Import IDEService and types_all from types module in __init__.py --- devchat/ide/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/devchat/ide/__init__.py b/devchat/ide/__init__.py index f86ae78b..986fe28c 100644 --- a/devchat/ide/__init__.py +++ b/devchat/ide/__init__.py @@ -1,6 +1,7 @@ from .service import IDEService from .types import * +from .types import __all__ as types_all -__all__ = types.__all__ + [ +__all__ = types_all + [ "IDEService", ]