-
-
Notifications
You must be signed in to change notification settings - Fork 106
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: move some scope calculations out of main loop #795
fix: move some scope calculations out of main loop #795
Conversation
ae9404d
to
a9162ae
Compare
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.
A couple small points, but looks good overall.
lua/ibl/init.lua
Outdated
local current_left_offset = left_offset | ||
while #whitespace_tbl > 0 and current_left_offset > 0 do | ||
table.remove(whitespace_tbl, 1) | ||
current_left_offset = current_left_offset - 1 | ||
end |
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.
The horizontal scroll fix is exactly the same as in the main loop, I think it would be nicer to make this a util function.
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.
I made a util function now. Please let me know if you want me to change anything.
lua/ibl/init.lua
Outdated
offset = top_offset - math.min(top_offset - math.min(offset, scope:start()), config.viewport_buffer.max) | ||
local scope_start = scope:start() | ||
local scope_end = scope:end_() | ||
offset = top_offset - math.min(top_offset - math.min(offset, scope_start), config.viewport_buffer.max) |
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.
The only reason I adjust offset here at all was to compensate for the scope calculation. This is no longer needed with this PR. You can just remove this line.
And maybe add a note in the docs that viewport_buffer.max
is deprecated. But don't remove it, we don't want to make this a breaking change.
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.
I made a small update to the docs now. I think it would also make sense to add small change to the min
docs too, noting that it is now the exact offset and not minimal. Should I just add that too?
I updated this based on your comments now. If you have anything else you would like to update, I can do that too, and then I plan to squish the commits afterwards. |
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.
thanks 🚀
This pull request moves the calculation of the scope index out of the main loop, since we want to be able to figure this out without including lines all the way from the start of the scope if we are in the middle of a very long scope.
Since we no longer need to include as many lines to get good highlighting, I also lowered the default value of
viewport_buffer.max
from 500 to 60. I think we can lower bothmin
andmax
even more, but at that point it becomes a question of personal preference. I picked 60, since that should about cover one full screen for most people (I think?).Furthermore, I added a comparison between the start line and end line whitespace tables, and we use the smaller one to calculate the scope index. This fixes #752, and I can't think of any normal formatting style that will get worse highlighting by this. If you want, I can include an option for whether to use the start (of the scope), end or the minimum of both?