Skip to content

Commit d03f85c

Browse files
committed
fix(python): exclude comments from function contexts
1 parent 660861b commit d03f85c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

queries/python/context.scm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
(class_definition
22
body: (_) @context.end) @context
33

4+
; If the function starts with a comment, then use that to end the context.
5+
;
6+
; Note: priority of overlapping rules isn't defined, but this one seems to
7+
; always take precedence over the one below, regardless of the order in which
8+
; they are defined. Maybe the smallest match wins?
9+
(function_definition
10+
(comment) @context.end) @context
11+
412
(function_definition
513
body: (_) @context.end) @context
614

test/lang/test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,13 @@ def hello(name: str, age: int) -> None: # {{CONTEXT}}
44

55

66
# {{CURSOR}}
7+
8+
def hello2( # {{CONTEXT}}
9+
name: str, # {{CONTEXT}}
10+
age: int) -> None: # {{CONTEXT}}
11+
# comment
12+
13+
14+
15+
16+
name = 'barry' # {{CURSOR}}

0 commit comments

Comments
 (0)