Skip to content
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

fix: avoid propagating empty context_lines #433

Closed
wants to merge 1 commit into from

Conversation

Freyskeyd
Copy link

Description

This PR fixes an issue where sometime the ctx_lines used to define the height were empty, triggering an error about invalid height:

lua/treesitter-context/render.lua:51: 'height' key must be a positive Integer

The fix is checking if the context_lines are not empty, if it is, the close method is called.

PR Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added or updated tests that comprehensively prove my change is effective or that my feature works

@@ -106,7 +106,10 @@ local update = throttle(function()
return
end

assert(context_lines)
if not context_lines or #context_lines == 0 then
Copy link
Member

Choose a reason for hiding this comment

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

The block above should catch this. context_lines should be nil is context is.

Copy link
Author

Choose a reason for hiding this comment

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

I get this response from get_context as an example:

context_ranges: { { 74, 0, 73, -1 } }
context_lines: { {} }
context_lines (flatten): {}

After investigating a bit it seems that the trim_contexts is the problem:

print(vim.inspect(context_ranges), vim.inspect(context_lines))
trim_contexts(context_ranges, context_lines, trim, config.trim_scope == 'outer')
print(vim.inspect(context_ranges), vim.inspect(context_lines))

---

{ { 62, 0, 62, -1 }, { 64, 0, 64, -1 }, { 74, 0, 73, -1 } }  |  { { "impl TaskManager {" }, { "    pub fn new(" }, {} } 
-> trim
{ { 74, 0, 73, -1 } } { {} }

Copy link
Author

Choose a reason for hiding this comment

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

@lewis6991 After some tests I think that the problem rely in the cleaning of the contexts

@Freyskeyd
Copy link
Author

Hey @lewis6991 !

Any chance to make this problem fix in some way? It is pretty annoying on a daily basis ahah.
I'm ready to make changes or update to this PR if needed !

Signed-off-by: Simon Paitrault <simon.paitrault@gmail.com>
@lewis6991
Copy link
Member

I've done some changes recently is this still an issue? If so do you have a way to reproduce the problem?

@Freyskeyd
Copy link
Author

@lewis6991 I'll update and let you know if I encounter the issue again, thanks !

@lewis6991
Copy link
Member

I'll assume this isn't an issue any more. Let me know if it is.

@lewis6991 lewis6991 closed this Sep 3, 2024
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