@@ -22,7 +22,7 @@ def current_word(cursor_offset: int, line: str) -> Optional[LinePart]:
22
22
end = pos
23
23
word = None
24
24
for m in current_word_re .finditer (line ):
25
- if m .start (1 ) < pos and m .end (1 ) >= pos :
25
+ if m .start (1 ) < pos <= m .end (1 ):
26
26
start = m .start (1 )
27
27
end = m .end (1 )
28
28
word = m .group (1 )
@@ -37,7 +37,7 @@ def current_word(cursor_offset: int, line: str) -> Optional[LinePart]:
37
37
def current_dict_key (cursor_offset : int , line : str ) -> Optional [LinePart ]:
38
38
"""If in dictionary completion, return the current key"""
39
39
for m in current_dict_key_re .finditer (line ):
40
- if m .start (1 ) <= cursor_offset and m .end (1 ) >= cursor_offset :
40
+ if m .start (1 ) <= cursor_offset <= m .end (1 ):
41
41
return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
42
42
return None
43
43
@@ -48,7 +48,7 @@ def current_dict_key(cursor_offset: int, line: str) -> Optional[LinePart]:
48
48
def current_dict (cursor_offset : int , line : str ) -> Optional [LinePart ]:
49
49
"""If in dictionary completion, return the dict that should be used"""
50
50
for m in current_dict_re .finditer (line ):
51
- if m .start (2 ) <= cursor_offset and m .end (2 ) >= cursor_offset :
51
+ if m .start (2 ) <= cursor_offset <= m .end (2 ):
52
52
return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
53
53
return None
54
54
@@ -67,7 +67,7 @@ def current_string(cursor_offset: int, line: str) -> Optional[LinePart]:
67
67
string is a string based on previous lines in the buffer."""
68
68
for m in current_string_re .finditer (line ):
69
69
i = 3 if m .group (3 ) else 4
70
- if m .start (i ) <= cursor_offset and m .end (i ) >= cursor_offset :
70
+ if m .start (i ) <= cursor_offset <= m .end (i ):
71
71
return LinePart (m .start (i ), m .end (i ), m .group (i ))
72
72
return None
73
73
@@ -108,10 +108,7 @@ def current_object_attribute(
108
108
matches = current_object_attribute_re .finditer (word )
109
109
next (matches )
110
110
for m in matches :
111
- if (
112
- m .start (1 ) + start <= cursor_offset
113
- and m .end (1 ) + start >= cursor_offset
114
- ):
111
+ if m .start (1 ) + start <= cursor_offset <= m .end (1 ) + start :
115
112
return LinePart (m .start (1 ) + start , m .end (1 ) + start , m .group (1 ))
116
113
return None
117
114
@@ -131,8 +128,8 @@ def current_from_import_from(
131
128
"""
132
129
# TODO allow for as's
133
130
for m in current_from_import_from_re .finditer (line ):
134
- if (m .start (1 ) < cursor_offset and m .end (1 ) >= cursor_offset ) or (
135
- m .start (2 ) < cursor_offset and m .end (2 ) >= cursor_offset
131
+ if (m .start (1 ) < cursor_offset <= m .end (1 )) or (
132
+ m .start (2 ) < cursor_offset <= m .end (2 )
136
133
):
137
134
return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
138
135
return None
@@ -162,7 +159,7 @@ def current_from_import_import(
162
159
):
163
160
start = baseline .end () + m .start (1 )
164
161
end = baseline .end () + m .end (1 )
165
- if start < cursor_offset and end >= cursor_offset :
162
+ if start < cursor_offset <= end :
166
163
return LinePart (start , end , m .group (1 ))
167
164
return None
168
165
@@ -185,7 +182,7 @@ def current_import(cursor_offset: int, line: str) -> Optional[LinePart]:
185
182
):
186
183
start = baseline .end () + m .start (1 )
187
184
end = baseline .end () + m .end (1 )
188
- if start < cursor_offset and end >= cursor_offset :
185
+ if start < cursor_offset <= end :
189
186
return LinePart (start , end , m .group (1 ))
190
187
return None
191
188
@@ -198,7 +195,7 @@ def current_method_definition_name(
198
195
) -> Optional [LinePart ]:
199
196
"""The name of a method being defined"""
200
197
for m in current_method_definition_name_re .finditer (line ):
201
- if m .start (1 ) <= cursor_offset and m .end (1 ) >= cursor_offset :
198
+ if m .start (1 ) <= cursor_offset <= m .end (1 ):
202
199
return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
203
200
return None
204
201
@@ -209,7 +206,7 @@ def current_method_definition_name(
209
206
def current_single_word (cursor_offset : int , line : str ) -> Optional [LinePart ]:
210
207
"""the un-dotted word just before or under the cursor"""
211
208
for m in current_single_word_re .finditer (line ):
212
- if m .start (1 ) <= cursor_offset and m .end (1 ) >= cursor_offset :
209
+ if m .start (1 ) <= cursor_offset <= m .end (1 ):
213
210
return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
214
211
return None
215
212
@@ -238,6 +235,6 @@ def current_expression_attribute(
238
235
"""If after a dot, the attribute being completed"""
239
236
# TODO replace with more general current_expression_attribute
240
237
for m in current_expression_attribute_re .finditer (line ):
241
- if m .start (1 ) <= cursor_offset and m .end (1 ) >= cursor_offset :
238
+ if m .start (1 ) <= cursor_offset <= m .end (1 ):
242
239
return LinePart (m .start (1 ), m .end (1 ), m .group (1 ))
243
240
return None
0 commit comments