@@ -24,6 +24,16 @@ class Reference(PydanticModel):
2424 description : t .Optional [str ] = None
2525
2626
27+ def is_position_in_range (range : Range , position : Position ) -> bool :
28+ return (
29+ range .start .line < position .line
30+ or (range .start .line == position .line and range .start .character <= position .character )
31+ ) and (
32+ range .end .line > position .line
33+ or (range .end .line == position .line and range .end .character >= position .character )
34+ )
35+
36+
2737def by_position (position : Position ) -> t .Callable [[Reference ], bool ]:
2838 """
2939 Filter reference to only filter references that contain the given position.
@@ -35,17 +45,8 @@ def by_position(position: Position) -> t.Callable[[Reference], bool]:
3545 A function that returns True if the reference contains the position, False otherwise
3646 """
3747
38- def contains_position (r : Reference ) -> bool :
39- return (
40- r .range .start .line < position .line
41- or (
42- r .range .start .line == position .line
43- and r .range .start .character <= position .character
44- )
45- ) and (
46- r .range .end .line > position .line
47- or (r .range .end .line == position .line and r .range .end .character >= position .character )
48- )
48+ def contains_position (reference : Reference ) -> bool :
49+ return is_position_in_range (reference .range , position )
4950
5051 return contains_position
5152
@@ -167,15 +168,15 @@ def get_model_definitions_for_a_path(
167168
168169 # Extract metadata for positioning
169170 table_meta = TokenPositionDetails .from_meta (table .this .meta )
170- table_range = _range_from_token_position_details (table_meta , read_file )
171+ table_range = range_from_token_position_details (table_meta , read_file )
171172 start_pos = table_range .start
172173 end_pos = table_range .end
173174
174175 # If there's a catalog or database qualifier, adjust the start position
175176 catalog_or_db = table .args .get ("catalog" ) or table .args .get ("db" )
176177 if catalog_or_db is not None :
177178 catalog_or_db_meta = TokenPositionDetails .from_meta (catalog_or_db .meta )
178- catalog_or_db_range = _range_from_token_position_details (catalog_or_db_meta , read_file )
179+ catalog_or_db_range = range_from_token_position_details (catalog_or_db_meta , read_file )
179180 start_pos = catalog_or_db_range .start
180181
181182 references .append (
@@ -215,7 +216,7 @@ def from_meta(meta: t.Dict[str, int]) -> "TokenPositionDetails":
215216 )
216217
217218
218- def _range_from_token_position_details (
219+ def range_from_token_position_details (
219220 token_position_details : TokenPositionDetails , read_file : t .List [str ]
220221) -> Range :
221222 """
0 commit comments