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: defer execution to avoid segfaults and fix throttler #526

Merged
merged 2 commits into from
Dec 4, 2024

Conversation

apollo1321
Copy link
Contributor

@apollo1321 apollo1321 commented Nov 17, 2024

Should fix #522 reliably.
It is inspired by the satellite.nvim plugin https://github.com/lewis6991/satellite.nvim/blob/main/lua/satellite.lua#L74, which is more stable and consistently uses deferred execution. In contrast, the current implementation sometimes uses deferred execution and other times executes callbacks in-place, when they are not throttled.

Also, there was a problem with throttler, the following execution was possible:

  Time ->
|cb|-----timeout-------|cb||cb|-----timeout-----|cb||cb| ...

@@ -165,7 +167,6 @@ function M.enable()

if config.multiwindow then
table.insert(update_events, 'WinResized')
table.insert(update_events, 'WinLeave')
Copy link
Contributor Author

@apollo1321 apollo1321 Nov 17, 2024

Choose a reason for hiding this comment

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

I can't recall why I used this event for multi-window support. It appears to be unnecessary because it triggers for the window being left (nvim_get_current_win() returns the window that the user is leaving).

@apollo1321 apollo1321 marked this pull request as draft December 4, 2024 14:35
@apollo1321 apollo1321 changed the title fix: defer execution to avoid segfaults fix: defer execution to avoid segfaults and fix throttler Dec 4, 2024
@apollo1321 apollo1321 force-pushed the fix-segfault branch 2 times, most recently from 1d8a3a7 to b50f8db Compare December 4, 2024 14:37
@apollo1321 apollo1321 force-pushed the fix-segfault branch 2 times, most recently from 01ca79f to 6307099 Compare December 4, 2024 14:47
@apollo1321 apollo1321 marked this pull request as ready for review December 4, 2024 16:06
@@ -15,25 +15,52 @@ local all_contexts = {}
--- @param ms? number
--- @return F
local function throttle_by_id(f, ms)
ms = ms or 200
ms = ms or 150
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is have decreased throttle timeout a little to compensate previous incorrect behavior.

@lewis6991 lewis6991 merged commit 8ebcf62 into nvim-treesitter:master Dec 4, 2024
2 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.

bug: crash on tab switch with multiwindow enabled
2 participants