Skip to content
This repository has been archived by the owner on Jul 5, 2022. It is now read-only.

Ensure treesitter parse tree is up-to-date to support dynamic update #70

Merged
merged 1 commit into from
Feb 9, 2022

Conversation

wookayin
Copy link
Contributor

@wookayin wookayin commented Feb 9, 2022

Whenever get_location() is called, we request the treesitter parser
to refresh the parse tree for the current buffer up to date.

This may be not needed when the treesitter-highlight module is enabled,
but when the module is disabled the plugin may not display the
correct context information (as reported in #69).

Such calls will be throttled properly: refreshing the treesitter
parse tree will happen only when the buffer has changed.

Whenever get_location() is called, we request the treesitter parser
to refresh the parse tree for the current buffer up to date.

This may be not needed when the treesitter-highlight module is enabled,
but when the module is disabled the plugin may not display the
correct context information (as reported in SmiteshP#69).

Such calls will be throttled properly: refreshing the treesitter
parse tree will happen only when the buffer has changed.
@wookayin wookayin mentioned this pull request Feb 9, 2022
@SmiteshP
Copy link
Owner

SmiteshP commented Feb 9, 2022

What counts as buf_tick? If the parser is made to parser at every keystroke in insert mode then that could be excessive

@SmiteshP
Copy link
Owner

SmiteshP commented Feb 9, 2022

Oh, nevermind. The function won't be called in insert mode anyways cause get_location will return the cached value. So this will effectively work on InsertLeave. Great, its much cleaner than setting up a autocommand too

@SmiteshP SmiteshP merged commit 6afd8f7 into SmiteshP:master Feb 9, 2022
@wookayin
Copy link
Contributor Author

wookayin commented Feb 9, 2022

Thanks!

FYI, actually with the treesitter highlight plugin parser:parse() call will be made almost at every keystroke (like as frequent as TextChanged). Practically this implementation would call as frequent as InsertLeave (which is very reasonable). I tested and it indeed doesn't get called while we are in the insert mode. It also works with some commands that doesn't involve the insert mode, such as yy or dd motions.

@wookayin wookayin deleted the update-tree branch February 10, 2022 03:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants