]> git.eshelyaron.com Git - emacs.git/commit
Fix treesit--indent-1 regarding local parsers
authorYuan Fu <casouri@gmail.com>
Wed, 31 Jan 2024 06:18:33 +0000 (22:18 -0800)
committerEshel Yaron <me@eshelyaron.com>
Wed, 31 Jan 2024 20:16:54 +0000 (21:16 +0100)
commitc5c5e079fd304c0aecd0e69367fd8ec3af294c2f
treefd9c873702a7e9b991972edb013e1200261de80c
parent3058712b100060d12b6ef4a689576b5788cefecd
Fix treesit--indent-1 regarding local parsers

Take this code as an example:

1 class Foo
2 {
3     /**
4      * Block comment
5      */
6     function foo($c) {
7     }
8 }

Suppose the block comment is covered by a local parser.  When we
indent line 3, treesit--indent-1 will try to get the local parser at
the BOL, and it'll get the local parser.  But it shouldn't use the
local parser to indent this line, it should use the host parser of
that local parser instead.

So now, if treesit--indent-1 gets a local parser, but the local
parser's root node's start coincides with BOL, treesit--indent-1 will
use the host parser to indent this line.

We also need to make treesit--update-ranges-local to save the host
parser along with the local parser, and make
treesit-local-parsers-at/on extract and return the host parser.

I also switch the two cases in the cond form in treesit--indent-1:
(null (treesit-parser-list)) and (car local-parsers), (car
local-parsers) now takes precedence.

* lisp/treesit.el (treesit-local-parsers-at):
(treesit-local-parsers-on): Add WITH-HOST parameter.
(treesit--update-ranges-local): Save the host parser to the local
overlay.
(treesit--indent-1): If the root node of the local parser is at BOL,
use the host parser instead.

(cherry picked from commit f63bcf2dfeb26de511f468adc237e6ea8a3cb6cc)
lisp/treesit.el