Skip to content

Commit cfc83ed

Browse files
authored
Merge pull request #60 from agentic-labs/identifiers
Add find_identifier method and related models to Lsproxy
2 parents 060fb98 + 1910f43 commit cfc83ed

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

lsproxy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
GetReferencesRequest,
1212
)
1313

14-
__version__ = "0.1.6"
14+
__version__ = "0.2.0"
1515

1616
__all__ = [
1717
"Lsproxy",

lsproxy/client.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
GetDefinitionRequest,
1616
GetReferencesRequest,
1717
Symbol,
18+
FindIdentifierRequest,
19+
IdentifierResponse,
1820
)
1921

2022
from .auth import create_jwt
@@ -87,6 +89,25 @@ def find_references(self, request: GetReferencesRequest) -> ReferencesResponse:
8789
references = ReferencesResponse.model_validate_json(response.text)
8890
return references
8991

92+
def find_identifier(self, request: FindIdentifierRequest) -> IdentifierResponse:
93+
"""Find all occurrences of an identifier by name in a file.
94+
95+
Args:
96+
request: The request containing the identifier name, file path, and optional position.
97+
If position is provided, returns exact match or closest matches.
98+
99+
Returns:
100+
Response containing the found identifiers.
101+
"""
102+
if not isinstance(request, FindIdentifierRequest):
103+
raise TypeError(
104+
f"Expected FindIdentifierRequest, got {type(request).__name__}. Please use FindIdentifierRequest model to construct the request."
105+
)
106+
response = self._request(
107+
"POST", "/symbol/find-identifier", json=request.model_dump()
108+
)
109+
return IdentifierResponse.model_validate_json(response.text)
110+
90111
def list_files(self) -> List[str]:
91112
"""Get a list of all files in the workspace."""
92113
response = self._request("GET", "/workspace/list-files")
@@ -111,7 +132,7 @@ def initialize_with_modal(
111132
git_token: Optional[str] = None,
112133
sha: Optional[str] = None,
113134
timeout: Optional[int] = None,
114-
version: str = "latest",
135+
version: str = "0.3",
115136
) -> "Lsproxy":
116137
"""
117138
Initialize lsproxy by starting a Modal sandbox with the server and connecting to it.

lsproxy/models.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,43 @@ def __hash__(self) -> int:
151151
return hash((self.kind, self.name, self.identifier_position, self.range))
152152

153153

154+
class Identifier(BaseModel):
155+
"""Representation of an identifier in code."""
156+
157+
name: str = Field(..., description="The name of the identifier.")
158+
range: FileRange = Field(
159+
..., description="The range of the identifier in the file."
160+
)
161+
162+
163+
class FindIdentifierRequest(BaseModel):
164+
"""Request to find all occurrences of an identifier by name in a file."""
165+
166+
name: str = Field(..., description="The name of the identifier to search for.")
167+
path: str = Field(
168+
..., description="The path to the file to search for identifiers."
169+
)
170+
position: Optional[Position] = Field(
171+
None,
172+
description="The position hint to search for identifiers. If provided, returns exact match or closest matches.",
173+
)
174+
175+
176+
class IdentifierResponse(BaseModel):
177+
"""Response containing found identifiers."""
178+
179+
identifiers: List[Identifier] = Field(..., description="List of found identifiers.")
180+
181+
154182
class DefinitionResponse(BaseModel):
155183
"""Response containing definition locations of a symbol."""
156184

157185
definitions: List[FilePosition] = Field(
158186
..., description="List of definition locations for the symbol."
159187
)
188+
selected_identifier: Optional[Identifier] = Field(
189+
None, description='The identifier that was "clicked-on" to get the definition.'
190+
)
160191
raw_response: Optional[Union[dict, list]] = Field(
161192
None,
162193
description=(
@@ -192,6 +223,9 @@ class ReferencesResponse(BaseModel):
192223
references: List[FilePosition] = Field(
193224
..., description="List of reference locations for the symbol."
194225
)
226+
selected_identifier: Optional[Identifier] = Field(
227+
None, description='The identifier that was "clicked-on" to get the references.'
228+
)
195229
context: Optional[List[CodeContext]] = Field(
196230
None, description="Source code contexts around the references."
197231
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "lsproxy-sdk"
3-
version = "0.1.6"
3+
version = "0.2.0"
44
description = "SDK for interacting with lsproxy container"
55
readme = "README.md"
66
requires-python = ">=3.10"

0 commit comments

Comments
 (0)