GNU bug report logs - #77256
Treesit language-at-point

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Tue, 25 Mar 2025 18:44:02 UTC

Severity: normal

Fixed in version 31.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Yuan Fu <casouri <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 77256 <at> debbugs.gnu.org, Vincenzo Pupillo <v.pupillo <at> gmail.com>
Subject: bug#77256: Treesit language-at-point
Date: Tue, 1 Apr 2025 16:59:03 -0700

> On Apr 1, 2025, at 9:53 AM, Juri Linkov <juri <at> linkov.net> wrote:
> 
>>> @@ -185,15 +185,15 @@ treesit-language-at
>>> This function assumes that parser ranges are up-to-date.  It
>>> returns the return value of `treesit-language-at-point-function'
>>> if it's non-nil, otherwise it returns the language of the first
>>> -parser in `treesit-parser-list', or nil if there is no parser.
>>> +parser from `treesit-parsers-at', or the primary parser.
>> 
>> If we handle the fallback case in treesit-language-at directly, rather than
>> defining a separate default function, IMO we should describe the fallback
>> behavior as the default. So something like “Return the language at
>> POS. When there are multiple parsers that covers POS, determine the most
>> relevant parser (hence language) by their embed level. If
>> treesit-language-at-point-function is non-nil, return the return value of
>> that function instead.” (Not saying we should use this exact docstring but
>> to illustrate the point.)
> 
> Now fixed in the next patch.
> 
>>> +(defun treesit-parsers-at (&optional pos language with-host local-only)
>>> +  "Return all the non-primary parsers at POS.
>> 
>> I get why you used treesit-parsers-at rather than a more technically
>> correct name like treesit-non-primary-parsers-at, or
>> treesit-embeded-parsers-at. But this is confusing for not much benefit
>> IMO. I suggest either use treesit-parsers-at, and add an optional argument
>> exclude-primary; or use a more correct name and don’t include the primary
>> parser. Also, instead of using LOCAL-ONLY, we might be more future-prove to
>> use a ONLY parameter, and let user pass ‘local to mean local-only. This way
>> we can add the option of returning only non-local non-primary parsers in
>> the future, should the need arises (it already kinda does in
>> treesit-node-at and treesit-simple-imenu, technically global-parser should
>> be picked from non-local parsers).
> 
> I can't find a better function signature than to add the argument ONLY
> with the following combinations of symbols for its list, wrt existing uses
> of treesit-parsers-at:
> 
>  nil                treesit-language-at (nil returns all parsers)
>  (local)            treesit-local-parsers-at
>  (primary global)   treesit-node-at, treesit-simple-imenu
>  (global local)     treesit-outline-level, treesit-up-list
> 
>> We should also update manual sections that mentions treesit-language-at.
> 
> Will do when everything is ok with this patch:
> 

Thanks! LGTM.

Yuan



This bug report was last modified 91 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.