@@ -71,33 +71,40 @@ def __hash__(self) -> int:
7171 return hash ((self .path , self .position .line , self .position .character ))
7272
7373
74+ class Range (BaseModel ):
75+ start : Position = Field (..., description = "Start position of the range." )
76+ end : Position = Field (..., description = "End position of the range." )
77+
78+ def __hash__ (self ) -> int :
79+ return hash ((self .start .line , self .start .character , self .end .line , self .end .character ))
80+
81+
7482class FileRange (BaseModel ):
7583 """Range within a file, defined by start and end positions."""
7684
7785 path : str = Field (..., description = "The path to the file." , example = "src/main.py" )
78- start : Position = Field (..., description = "Start position of the range." )
79- end : Position = Field (..., description = "End position of the range." )
86+ range : Range = Field (..., description = "The range within the file." )
8087
8188 def contains (self , file_position : FilePosition ) -> bool :
8289 """Check if a position is within the range."""
8390 return (
8491 self .path == file_position .path
85- and self .start <= file_position .position
86- and file_position .position <= self .end
92+ and self .range . start <= file_position .position
93+ and file_position .position <= self .range . end
8794 )
8895
8996 def __lt__ (self , other : "FileRange" ) -> bool :
9097 """Compare ranges by path first, then start position."""
9198 if self .path != other .path :
9299 return self .path < other .path
93- return self .start < other .start
100+ return self .range . start < other . range .start
94101
95102 def __eq__ (self , other : "FileRange" ) -> bool :
96103 """Check if two ranges are equal."""
97104 return (
98105 self .path == other .path
99- and self .start == other .start
100- and self .end == other .end
106+ and self .range . start == other . range .start
107+ and self .range . end == other . range .end
101108 )
102109
103110 def __le__ (self , other : "FileRange" ) -> bool :
@@ -116,10 +123,10 @@ def __hash__(self) -> int:
116123 return hash (
117124 (
118125 self .path ,
119- self .start .line ,
120- self .start .character ,
121- self .end .line ,
122- self .end .character ,
126+ self .range . start .line ,
127+ self .range . start .character ,
128+ self .range . end .line ,
129+ self .range . end .character ,
123130 )
124131 )
125132
@@ -145,17 +152,17 @@ class Symbol(BaseModel):
145152 identifier_position : FilePosition = Field (
146153 ..., description = "The start position of the symbol's identifier."
147154 )
148- range : FileRange = Field (..., description = "The full range of the symbol." )
155+ file_range : FileRange = Field (..., description = "The full range of the symbol." )
149156
150157 def __hash__ (self ) -> int :
151- return hash ((self .kind , self .name , self .identifier_position , self .range ))
158+ return hash ((self .kind , self .name , self .identifier_position , self .file_range ))
152159
153160
154161class Identifier (BaseModel ):
155162 """Representation of an identifier in code."""
156163
157164 name : str = Field (..., description = "The name of the identifier." )
158- range : FileRange = Field (
165+ file_range : FileRange = Field (
159166 ..., description = "The range of the identifier in the file."
160167 )
161168 kind : Optional [str ] = Field (
@@ -253,10 +260,6 @@ class GetReferencesRequest(BaseModel):
253260 description = "Number of source code lines to include around each reference." ,
254261 ge = 0 ,
255262 )
256- include_declaration : Optional [bool ] = Field (
257- False ,
258- description = "Whether to include the declaration of the symbol in the references." ,
259- )
260263 include_raw_response : Optional [bool ] = Field (
261264 False ,
262265 description = "Whether to include the raw response from the language server." ,
@@ -308,3 +311,9 @@ class ReadSourceCodeResponse(BaseModel):
308311 source_code : str = Field (
309312 ..., description = "The source code for the specified range."
310313 )
314+
315+
316+ class ReadSourceCodeRequest (BaseModel ):
317+ """Request to read source code from a file with an optional range."""
318+ path : str = Field (..., description = "Path to the file, relative to the workspace root" )
319+ range : Optional [Range ] = Field (None , description = "Optional range within the file to read" )
0 commit comments