Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions lua/treesitter-context/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -377,18 +377,19 @@ function M.get(winid)
local range0 = context_range(parent, bufnr, query)
if range0 and range_is_valid(range0) then
local range, lines = get_text_for_range(range0, bufnr)
if range_is_valid(range) then
local last_context = context_ranges[#context_ranges]
if last_context and parent_start_row == last_context[1] then
-- If there are multiple contexts on the same row, then prefer the inner
contexts_height = contexts_height - util.get_range_height(last_context)
context_ranges[#context_ranges] = nil
context_lines[#context_lines] = nil
if range[1] < contexts_end_row then
if range_is_valid(range) then
local last_context = context_ranges[#context_ranges]
if last_context and parent_start_row == last_context[1] then
-- If there are multiple contexts on the same row, then prefer the inner
contexts_height = contexts_height - util.get_range_height(last_context)
context_ranges[#context_ranges] = nil
context_lines[#context_lines] = nil
end
contexts_height = contexts_height + util.get_range_height(range)
context_ranges[#context_ranges + 1] = range
context_lines[#context_lines + 1] = lines
end

contexts_height = contexts_height + util.get_range_height(range)
context_ranges[#context_ranges + 1] = range
context_lines[#context_lines + 1] = lines
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions queries/java/context.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
) @context

(method_declaration
type: (_) @context.start
body: (_) @context.end
) @context

(constructor_declaration
name: (_) @context.start
body: (_) @context.end
) @context

Expand All @@ -15,6 +21,7 @@
) @context

(class_declaration
name: (_) @context.start
body: (_) @context.end
) @context

Expand Down
8 changes: 4 additions & 4 deletions test/lang/test.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import stuff1;
import stuff2;

@class_annot_1 // {{CONTEXT}}
@class_annot_2 // {{CONTEXT}}
@class_annot_1
@class_annot_2
public class MyClass { // {{CONTEXT}}



// {{CURSOR}}
@method_annot_1 // {{CONTEXT}}
@method_annot_2 // {{CONTEXT}}
@method_annot_1
@method_annot_2
public void my_method(int param) { // {{CONTEXT}}


Expand Down
Loading