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: move some scope calculations out of main loop #795

Merged
merged 2 commits into from
Dec 21, 2023

Conversation

Danielkonge
Copy link
Contributor

@Danielkonge Danielkonge commented Dec 15, 2023

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 both min and max 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?

Copy link
Owner

@lukas-reineke lukas-reineke left a 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 Show resolved Hide resolved
lua/ibl/init.lua Outdated
Comment on lines 286 to 290
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
Copy link
Owner

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.

Copy link
Contributor Author

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 Show resolved Hide resolved
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)
Copy link
Owner

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.

Copy link
Contributor Author

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?

@Danielkonge
Copy link
Contributor Author

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.

Copy link
Owner

@lukas-reineke lukas-reineke left a comment

Choose a reason for hiding this comment

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

thanks 🚀

@lukas-reineke lukas-reineke merged commit 258b5d8 into lukas-reineke:master Dec 21, 2023
7 of 8 checks passed
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.

Bad indentation of scope for multi-line function definition
2 participants