File tree 1 file changed +8
-11
lines changed
1 file changed +8
-11
lines changed Original file line number Diff line number Diff line change 11
11
from .lazyre import LazyReCompile
12
12
13
13
LinePart = namedtuple ("LinePart" , ["start" , "stop" , "word" ])
14
-
15
14
current_word_re = LazyReCompile (r"(?<![)\]\w_.])" r"([\w_][\w0-9._]*[(]?)" )
16
15
17
16
18
17
def current_word (cursor_offset : int , line : str ) -> Optional [LinePart ]:
19
18
"""the object.attribute.attribute just before or under the cursor"""
20
- pos = cursor_offset
21
- start = pos
22
- end = pos
19
+ start = cursor_offset
20
+ end = cursor_offset
23
21
word = None
24
22
for m in current_word_re .finditer (line ):
25
- if m .start (1 ) < pos <= m .end (1 ):
23
+ if m .start (1 ) < cursor_offset <= m .end (1 ):
26
24
start = m .start (1 )
27
25
end = m .end (1 )
28
26
word = m .group (1 )
@@ -82,12 +80,11 @@ def current_object(cursor_offset: int, line: str) -> Optional[LinePart]:
82
80
if match is None :
83
81
return None
84
82
start , end , word = match
85
- s = ""
86
- for m in current_object_re .finditer (word ):
87
- if m .end (1 ) + start < cursor_offset :
88
- if s :
89
- s += "."
90
- s += m .group (1 )
83
+ s = "." .join (
84
+ m .group (1 )
85
+ for m in current_object_re .finditer (word )
86
+ if m .end (1 ) + start < cursor_offset
87
+ )
91
88
if not s :
92
89
return None
93
90
return LinePart (start , start + len (s ), s )
You can’t perform that action at this time.
0 commit comments