Subject: bug#77848: 31.0.50; treesit-update-ranges: offset setting is ignored for local parsers

From: Yuan Fu <[email-masked]>
Date: Fri, 18 Apr 2025 16:34:39 -0700

> On Apr 18, 2025, at 12:32 AM, Roman Rudakov <[email-masked]> wrote:
> 
> Yuan Fu <[email-masked]> writes:
> 
>>> On Apr 16, 2025, at 11:24 PM, Juri Linkov <[email-masked]> wrote:
>>> 
>>> Cc-ing Yuan for the help.
>>> 
>>>> Hello, I've noticed that when defining 'treesit-range-settings' using the
>>>> 'treesit-range-rules helper function, such as:
>>>> 
>>>> (treesit-range-rules
>>>> :embed 'markdown-inline
>>>> :host 'clojure
>>>> :offset '(1 . -1)
>>>> :local t
>>>> (clojure-ts--docstring-query '@capture))
>>>> 
>>>> The ':offset' setting doesn't have any effect.
>>>> 
>>>> After debugging the 'treesit-update-ranges' function, I noticed that it
>>>> calls 'treesit--update-range-1', which in turn calls
>>>> 'treesit--update-ranges-local' if ':local t' is
>>>> specified. 'treesit--update-ranges-local' does not accept offset as an
>>>> argument, although it is mentioned in its documentation string:
>>>> 
>>>>> OFFSET is a cons of start and end offsets that are applied to the range
>>>>> for the local parser.
>>>> 
>>>> This discrepancy between the documented behavior and the actual
>>>> implementation of 'treesit--update-ranges-local' regarding the offset
>>>> argument might be a bug.
>> 
>> Yes, it’s indeed a bug. I’ve pushed a fix for it. Thanks to you both!
>> 
>> Yuan
> 
> Thank you!
> 
> Would it be possible to also install the fix on emacs-30 branch?
> --
> Best regards, Roman

Ah right, thanks for the reminder. I thought this is a regression brought by the recent embedded parser change. Indeed, the local parser range function in Emacs 30 doesn’t handle offset either. I’ve pushed a separate fix to emacs-30.

Yuan