aboutsummaryrefslogtreecommitdiffstats
path: root/src/treesit.c
diff options
context:
space:
mode:
authorYuan Fu2022-11-25 15:10:20 -0800
committerYuan Fu2022-11-25 19:00:22 -0800
commit4ffca85f1eefea5adc96efc276acfae4d737aa17 (patch)
tree248cd341134212e1242be51c3d6d21c802a0d765 /src/treesit.c
parent245366b18a0675dc56d3236895cf0e099385d720 (diff)
downloademacs-4ffca85f1eefea5adc96efc276acfae4d737aa17.tar.gz
emacs-4ffca85f1eefea5adc96efc276acfae4d737aa17.zip
Rename treesit_ensure_position_synced to treesit_sync_visible_region
* src/treesit.c: Rename to better convey the purpose of the function.
Diffstat (limited to 'src/treesit.c')
-rw-r--r--src/treesit.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/treesit.c b/src/treesit.c
index 66fd884efc3..d18e77a3531 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -314,7 +314,7 @@ init_treesit_functions (void)
314 See: https://github.com/tree-sitter/tree-sitter/issues/445 314 See: https://github.com/tree-sitter/tree-sitter/issues/445
315 315
316 treesit.h has some commentary on the two main data structure for 316 treesit.h has some commentary on the two main data structure for
317 the parser and node. treesit_ensure_position_synced has some 317 the parser and node. treesit_sync_visible_region has some
318 commentary on how we make tree-sitter play well with narrowing (the 318 commentary on how we make tree-sitter play well with narrowing (the
319 tree-sitter parser only sees the visible region, so we need to 319 tree-sitter parser only sees the visible region, so we need to
320 translate positions back and forth). Most action happens in 320 translate positions back and forth). Most action happens in
@@ -782,7 +782,7 @@ treesit_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte,
782 matches that of the buffer, and update visible_beg/end. 782 matches that of the buffer, and update visible_beg/end.
783 783
784 That is, the whole purpose of visible_beg/end (and 784 That is, the whole purpose of visible_beg/end (and
785 treesit_record_change and treesit_ensure_position_synced) is to 785 treesit_record_change and treesit_sync_visible_region) is to
786 update the tree (by ts_tree_edit). So if the tree is NULL, we 786 update the tree (by ts_tree_edit). So if the tree is NULL, we
787 don't update the tree and there is no need to keep tracking of 787 don't update the tree and there is no need to keep tracking of
788 them. Only when we already have a tree, do we need to keep track 788 them. Only when we already have a tree, do we need to keep track
@@ -796,8 +796,8 @@ treesit_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte,
796 treesit_record_change(tree) | user edits buffer 796 treesit_record_change(tree) | user edits buffer
797 ... / 797 ... /
798 798
799 treesit_ensure_position_synced(tree) \ treesit_ensure_parsed 799 treesit_sync_visible_region(tree) \ treesit_ensure_parsed
800 ts_parser_parse(tree) -> tree / 800 ts_parser_parse(tree) -> tree /
801 801
802 treesit_record_change(tree) \ 802 treesit_record_change(tree) \
803 treesit_record_change(tree) | user edits buffer 803 treesit_record_change(tree) | user edits buffer
@@ -805,13 +805,14 @@ treesit_record_change (ptrdiff_t start_byte, ptrdiff_t old_end_byte,
805 805
806 and so on. */ 806 and so on. */
807 807
808/* Make sure PARSER's visible_beg and visible_end are in sync with 808/* Make sure the tree's visible range is in sync with the buffer's
809 BUF_BEGV_BYTE and BUG_ZV_BYTE. When calling this function you must 809 visible range, and PARSER's visible_beg and visible_end are in sync
810 make sure the current buffer's size is not larger than UINT32_MAX. 810 with BUF_BEGV_BYTE and BUG_ZV_BYTE. When calling this function you
811 Basically always call treesit_check_buffer_size before this 811 must make sure the current buffer's size is not larger than
812 function. */ 812 UINT32_MAX. Basically always call treesit_check_buffer_size before
813 this function. */
813static void 814static void
814treesit_ensure_position_synced (Lisp_Object parser) 815treesit_sync_visible_region (Lisp_Object parser)
815{ 816{
816 TSTree *tree = XTS_PARSER (parser)->tree; 817 TSTree *tree = XTS_PARSER (parser)->tree;
817 818
@@ -924,7 +925,7 @@ treesit_ensure_parsed (Lisp_Object parser)
924 925
925 /* Before we parse, catch up with the narrowing situation. */ 926 /* Before we parse, catch up with the narrowing situation. */
926 treesit_check_buffer_size (buffer); 927 treesit_check_buffer_size (buffer);
927 treesit_ensure_position_synced (parser); 928 treesit_sync_visible_region (parser);
928 929
929 TSTree *new_tree = ts_parser_parse (treesit_parser, tree, input); 930 TSTree *new_tree = ts_parser_parse (treesit_parser, tree, input);
930 /* This should be very rare (impossible, really): it only happens 931 /* This should be very rare (impossible, really): it only happens
@@ -1453,7 +1454,7 @@ buffer. */)
1453 treesit_initialize (); 1454 treesit_initialize ();
1454 /* Before we parse, catch up with narrowing/widening. */ 1455 /* Before we parse, catch up with narrowing/widening. */
1455 treesit_check_buffer_size (XBUFFER (XTS_PARSER (parser)->buffer)); 1456 treesit_check_buffer_size (XBUFFER (XTS_PARSER (parser)->buffer));
1456 treesit_ensure_position_synced (parser); 1457 treesit_sync_visible_region (parser);
1457 1458
1458 bool success; 1459 bool success;
1459 if (NILP (ranges)) 1460 if (NILP (ranges))
@@ -1539,7 +1540,7 @@ return nil. */)
1539 /* Our return value depends on the buffer state (BUF_BEGV_BYTE, 1540 /* Our return value depends on the buffer state (BUF_BEGV_BYTE,
1540 etc), so we need to sync up. */ 1541 etc), so we need to sync up. */
1541 treesit_check_buffer_size (XBUFFER (XTS_PARSER (parser)->buffer)); 1542 treesit_check_buffer_size (XBUFFER (XTS_PARSER (parser)->buffer));
1542 treesit_ensure_position_synced (parser); 1543 treesit_sync_visible_region (parser);
1543 1544
1544 struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer); 1545 struct buffer *buffer = XBUFFER (XTS_PARSER (parser)->buffer);
1545 return treesit_make_ranges (ranges, len, buffer); 1546 return treesit_make_ranges (ranges, len, buffer);