Skip to content

Conversation

RedFlameKen
Copy link

@RedFlameKen RedFlameKen commented Jun 30, 2025

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

@RedFlameKen RedFlameKen marked this pull request as draft June 30, 2025 05:32
@RedFlameKen RedFlameKen force-pushed the master branch 3 times, most recently from 09d719c to f0146ae Compare June 30, 2025 05:52
@RedFlameKen RedFlameKen marked this pull request as ready for review June 30, 2025 06:10
@RedFlameKen RedFlameKen marked this pull request as draft June 30, 2025 07:27
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
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was meant to check if the row of the start of the context (@context.start) is still below the top of the screen. I got this bug after I added stuff the queries/java/context.scm:

image

also sorry if this is messy, it's my first time making a pull request here

Copy link
Member

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.

Copy link
Author

@RedFlameKen RedFlameKen Jul 4, 2025

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.

image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants