Subject: bug#75456: 31.0.50; Cannot find the definition of the predicate in `treesit-thing-settings'" sexp-list)

From: Yuan Fu <[email-masked]>
Date: Fri, 17 Jan 2025 22:27:32 -0800

> On Jan 10, 2025, at 5:50 AM, Vincenzo Pupillo <[email-masked]> wrote:
> 
> Ciao Yuan
> 
> In data venerdì 10 gennaio 2025 04:23:42 Ora standard dell’Europa centrale, 
> Yuan Fu ha scritto:
>>> On Jan 9, 2025, at 2:42 PM, Vincenzo Pupillo <[email-masked]> wrote:
>>> 
>>> Ciao Juri,
>>> 
>>> In data giovedì 9 gennaio 2025 19:10:28 Ora standard dell’Europa centrale,
>>> 
>>> Juri Linkov ha scritto:
>>>>> Ciao,
>>>>> this problem occurs with js-ts-mode when jsdoc is enabled. Occurs when
>>>>> you
>>>>> place the cursor in a comment highlighted by jsdoc.
>>>>> This is the error message:
>>>>> 
>>>>> "treesit-show-paren-data--categorize: peculiar error: ("Cannot find the
>>>>> definition of the predicate in `treesit-thing-settings'" sexp-list)"
>>>> 
>>>> Recently I fixed bug#75198 and tested it on your mhtml-ts-mode
>>>> where it works nicely, and (treesit-language-at (point))
>>>> returns e.g. 'css' on embedded css.
>>>> 
>>>> However, now I discovered that (treesit-language-at (point))
>>>> returns 'javascript' on embedded jsdoc parts of a js file.
>>>> 
>>>> I wonder is this intended?
>>>> 
>>>> Since 'treesit-node-match-p' uses node's parser, I could use
>>>> (treesit-parser-language (treesit-node-parser (treesit-node-at (point))))
>>>> that returns 'jsdoc'.
>>>> 
>>>> But first I'd like to know why treesit-language-at doesn't return the
>>>> same?
>>> 
>>> Local parsers, like jsdoc or phpdoc, are "ignored" by several functions
>>> used by treesit. But I don't know in detail how treesit works.
>>> I tried to return local parser languages ​​in the past, but both
>>> indentation and font-locking got messed up.
>>> I just tried and the result is the same (maybe I did something wrong), and
>>> then treesit-parser-list also returns jsdoc as if it were a global parser.
>>> 
>>> @Yuan can be of more help.
>>> 
>>> Thanks.
>>> 
>>> Vincenzo
>> 
>> If local parsers somehow doesn’t work, it’s a bug. What are the functions
>> that ignore local parsers? And how exactly does indentation and font-lock
>> mess up?
>> 
>> For indentation, there’s a special condition: if the largest node at point
>> is a root node for the local parser, we don’t use it for matching indent
>> rules, because it’s impossible to figure out how to indent it; instead,
>> Emacs uses the host parser’s node at that point. (The logic is in
>> treesit--indent-largest-node-at).
>> 
>> What do you mean by  treesit-parser-list also returns jsdoc as if it were a
>> global parser? Does it return the jsdoc parser even you pass nil to the TAG
>> parameter? If so, I think it’s because some treesit function accidentally
>> created it when looking for a parser for jsdoc. I’ll try fix that.
>> 
>> Yuan
> As I wrote I might have made some mistakes (I tried with the new version of 
> mhtml-ts-mode which is more complicated than js-ts-mode). So I preferred to 
> write a patch for js-ts-mode. I could not replicate the indentation problems 
> but only the font-locking ones.
> If you try with the attached javascript file (setting treesit-font-lock-level 
> to 4) you will see the problem and if you invoke (treesit-parser-list) you 
> will see that jsdoc also appears in the list.
> 
> 
> Vincenzo
> 
> p.s. Gmail doesn't like my .js file so I wrote it below:
> /**
> * Foo
> * @param {int} a blah blah
> */
> var foo = function(a) {
>    console.log(a); // blah blah
> };
> 
> 
> /**
> * Bar
> * @param {int} a blah blah
> */
> var bar = function(a) {
>    console.log(a); // blah blah
> };
> 
> <0001-language-at-point-function-that-handles-local-parser.patch>

I just pushed a fix, now you shouldn’t see jsdoc parsers anymore. Can you see if this fixes the problem you had?

Yuan