-
-
Notifications
You must be signed in to change notification settings - Fork 225
fix: Ignore Java annotations #629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
09d719c
to
f0146ae
Compare
lua/treesitter-context/context.lua
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you able to explain why this is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is backed up with tests so I don't mind too much if it's messy, I'd just like to understand it myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for the great delay on this. From how I understand it, range[1]
is the context's start row and contexts_end_row is the top row of the current
"view". Adding @context.start
in queries/java/context.scm:
(method_declaration
type: (_) @context.start
body: (_) @context.end
) @context
This makes it so that the return type is the start of the context of the
method.
-- lua/treesitter-context/context.lua
if parent_start_row < contexts_end_row then
This checks if the current treesitter's hovered node parent's start row (The
entire method node including annotations) is now above the top of the screen.
This however includes the modifiers node which also includes the annotations
node. Atm, I couldn't figure out how to make it check the
method_declaration
's @context.start row instead of the Treesitter parent
node's start row.
so basically, parent_start_row checks if above highlighted node's start row is out of view. Normally it would display the first annotation in the context window. But I've modified the scm file to make the actual function definition line the start.
if range[1] < contexts_end_row then
This is meant to check for the actual start of the definition (@context.start).
If range[1] is still in view, do not show the context window.
Annotations are displayed instead of the actual method/class definitions. I noticed that #53 has been closed as well as #207. Added some
@context.start
fields to the queries/java/context.scm file to ignore the annotations. Also added a node there for constructor declarations. I also added a check for when the@context.start
is still below the top of the screen. I'm not sure if it's the most efficient way to do it but maybe someone else can improve it.Note: I've modified the test file for java to not treat annotations as contexts. Also, tests for php keep failing and I don't think I should modify the expected output in test/ts_context_spec.lua. Hoping someone can help fix this.
before
java:
https://github.com/user-attachments/assets/6fa66fbb-4ee6-4f46-87eb-52de651d4491
php:
https://github.com/user-attachments/assets/d9d7e4bb-4594-4809-bce8-6adfcb4ac2d3
after
java:
https://github.com/user-attachments/assets/51a16450-09d8-4ac1-bebf-e2bcbfdf1b8d
php:
https://github.com/user-attachments/assets/542a8f2f-dcd8-4c1b-8871-9e154bd100bc