Subject: bug#77727: [PATCH] Limit rust-ts-specific comment-start check to rust-ts (bug#77727)

From: Yuan Fu <[email-masked]>
Date: Wed, 16 Apr 2025 22:58:35 -0700

> On Apr 11, 2025, at 4:51 AM, Konstantin Kharlamov <[email-masked]> wrote:
> 
> On Fri, 2025-04-11 at 11:34 +0300, Konstantin Kharlamov wrote:
>> CC: Yuan Fu as the author of the code in question.
>> 
>> What happens in the code makes sense: since the comment resides at
>> top-
>> level, the parent of any top-level statement (returned by (treesit-
>> node-parent node)) is, well, beginning of a buffer.
>> 
>> So the question is, why the check works that way.
> 
> Please see the attached patch, it'd seem this is exactly the fix that's
> expected here. Basically, the problematic check is specific to Rust
> treesitter mode, so shouldn't be executed in other languages. The patch
> factors out the entire check to a separate function and adds additional
> condition of (eq major-mode 'rust-ts-mode).
> 
> Tested in tsx-ts-mode, it fixes the problem.
> <1.patch>

Thanks! Your analysis is correct. But I don’t want to hard-code rust-ts-mode in the function, since modes with other names can very well use rust parser. I pushed 9d43715baa5 that operates in the similar vein as your patch. Instead of checking for the current major mode, I tighten the condition by adding an additional check that ensure the parent node is a comment node. So now if the parent node is the root node (as in your initial example), the condition should fail. Please see if it fixes your problem.

Yuan