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

Incremental TS edits #21

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions textLSP/documents/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ def __len__(self):
class TreeSitterDocument(CleanableDocument):
LIB_PATH_TEMPLATE = '{}/treesitter/{}.so'.format(get_user_cache(), '{}')

# faster persing method is still buggy
CONFIGURATION_REPARSE_ALL = 'reparse_all'
DEFAULT_REPARSE_ALL = True

def __init__(self, language_name, grammar_url, branch, *args, **kwargs):
super().__init__(*args, **kwargs)
#######################################################################
Expand Down Expand Up @@ -862,6 +866,13 @@ def _build_updated_text_intervals(

def _apply_incremental_change(self, change: TextDocumentContentChangeEvent_Type1) -> None:
"""Apply an ``Incremental`` text change to the document"""
reparse_all = self.config.setdefault(
self.CONFIGURATION_REPARSE_ALL,
self.DEFAULT_REPARSE_ALL,
)
if reparse_all:
self._tree = None

if self._tree is None:
super()._apply_incremental_change(change)
return
Expand Down
Loading