Skip to content

Commit f0146ae

Browse files
committed
fix: Ignore Java annotations
1 parent 59f318a commit f0146ae

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

lua/treesitter-context/context.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ function M.get(winid)
377377
local range0 = context_range(parent, bufnr, query)
378378
if range0 and range_is_valid(range0) then
379379
local range, lines = get_text_for_range(range0, bufnr)
380+
if range[1] > contexts_end_row - 1 then
381+
return
382+
end
380383
if range_is_valid(range) then
381384
local last_context = context_ranges[#context_ranges]
382385
if last_context and parent_start_row == last_context[1] then

queries/java/context.scm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
) @context
44

55
(method_declaration
6+
type: (_) @context.start
7+
body: (_) @context.end
8+
) @context
9+
10+
(constructor_declaration
11+
name: (_) @context.start
612
body: (_) @context.end
713
) @context
814

@@ -15,6 +21,7 @@
1521
) @context
1622

1723
(class_declaration
24+
name: (_) @context.start
1825
body: (_) @context.end
1926
) @context
2027

test/lang/test.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import stuff1;
44
import stuff2;
55

6-
@class_annot_1 // {{CONTEXT}}
7-
@class_annot_2 // {{CONTEXT}}
6+
@class_annot_1
7+
@class_annot_2
88
public class MyClass { // {{CONTEXT}}
99

1010

1111

1212
// {{CURSOR}}
13-
@method_annot_1 // {{CONTEXT}}
14-
@method_annot_2 // {{CONTEXT}}
13+
@method_annot_1
14+
@method_annot_2
1515
public void my_method(int param) { // {{CONTEXT}}
1616

1717

0 commit comments

Comments
 (0)