Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0cf7518

Browse files
Bug fix: make node_from_range Correctly yielded decorator when the cursor is at the beginning of the line or the whole line is selected
resolves #30
1 parent c565682 commit 0cf7518

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

‎library/selection_node.py‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ def nearest_node_from_offset(root,atok,offset,special=False):
2424
r = node_from_range(root,atok,(s,s),special= special,lenient = True)
2525
return r
2626

27-
def node_from_range_old(root,atok, r ):
28-
inside = lambda x,y: (y[0]<=x[0]<y[1] and y[0]<x[1]<=y[1])
29-
candidates =([(node,atok.get_text_range(node)) for node in ast.walk( root ) if not isinstance(node,ast.Module)
30-
and inside(r,atok.get_text_range(node))])
31-
print("inside note from range \n")
32-
for x in candidates:
33-
print(x,atok.get_text_range(x))
34-
print("outside note from range \n",min( candidates , key= lambda y :(y[1][1]-y[1][0]) )[0])
35-
36-
return min( candidates , key= lambda y :(y[1][1]-y[1][0]) )[0]
3727

3828

3929
def node_from_range_new(root,atok,r,special = False,lenient = False):
@@ -63,6 +53,18 @@ def node_from_range_new(root,atok,r,special = False,lenient = False):
6353
if l and l!=temporary:
6454
return l
6555

56+
if match_node(root,(ast.FunctionDef,ast.ClassDef)):
57+
converter = atok._line_numbers
58+
sr,sc = converter.offset_to_line(r[0])
59+
er,ec = converter.offset_to_line(r[1])
60+
for decorator in root.decorator_list:
61+
if sr != decorator.first_token.start[0]:
62+
continue
63+
if er != decorator.last_token.start[0]:
64+
if er != decorator.last_token.start[0] + 1 or ec != 0:
65+
continue
66+
return decorator
67+
6668

6769
return root
6870

@@ -74,6 +76,16 @@ def node_from_range(root,atok, r,special = False,lenient = False):
7476

7577

7678

79+
def node_from_range_old(root,atok, r ):
80+
inside = lambda x,y: (y[0]<=x[0]<y[1] and y[0]<x[1]<=y[1])
81+
candidates =([(node,atok.get_text_range(node)) for node in ast.walk( root ) if not isinstance(node,ast.Module)
82+
and inside(r,atok.get_text_range(node))])
83+
print("inside note from range \n")
84+
for x in candidates:
85+
print(x,atok.get_text_range(x))
86+
print("outside note from range \n",min( candidates , key= lambda y :(y[1][1]-y[1][0]) )[0])
87+
88+
return min( candidates , key= lambda y :(y[1][1]-y[1][0]) )[0]
7789

7890

7991

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /