Skip to content

Commit 8decd73

Browse files
committed
fix(python): exclude comments from function contexts
1 parent 48b9ebc commit 8decd73

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1+
# {{TEST}}
12
def hello(name: str, age: int) -> None: # {{CONTEXT}}
23
print(f"Hello {name}! You are {age} years old.")
34

45

56

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

0 commit comments

Comments
 (0)