[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Tree-sitter api
From: |
Theodor Thornhill |
Subject: |
Re: Tree-sitter api |
Date: |
Fri, 22 Apr 2022 13:41:47 +0200 |
>>>
>>> What happens is that the arguments list triggers as an indentation step,
>>> but it should only do so when when on its own line. I believe this is
>>> what SMIE calls "hanging-p" in its engine.
>>
>> I think an anchor preset that finds the parent that’s at the beginning
>> of a line should solve this. I’ll definitely add that one.
So I made this rule which is a good starting point for this, I think.
It's a pretty naive implementation still, but I wanted to share it
nonetheless.
```elisp
(defun ts-parent-until (type)
(lambda (node parent bol &rest _)
(when-let ((found-node
(tree-sitter-parent-until
node
(lambda (parent)
(equal type (tree-sitter-node-type parent))))))
(save-excursion
(goto-char (tree-sitter-node-start found-node))
(back-to-indentation)
(tree-sitter-node-start
(tree-sitter-node-at (point) (point) 'tree-sitter-tsx))))))
(defvar ts-tsx-tree-sitter-indent-rules
`((tree-sitter-tsx
((ts-parent-until "statement_block") (ts-parent-until "statement_block") 2)
(no-node prev-line 0)
)))
```
This at least marks the start of me understanding how it works, hehe...
Theodor
- Re: Tree-sitter api, (continued)
- Re: Tree-sitter api, Yuan Fu, 2022/04/04
- Re: Tree-sitter api, Theodor Thornhill, 2022/04/20
- Re: Tree-sitter api, Yuan Fu, 2022/04/20
- Re: Tree-sitter api, Eli Zaretskii, 2022/04/21
- Re: Tree-sitter api, Lars Ingebrigtsen, 2022/04/21
- Re: Tree-sitter api, Theodor Thornhill, 2022/04/21
- Re: Tree-sitter api, Yuan Fu, 2022/04/21
- Re: Tree-sitter api, Theodor Thornhill, 2022/04/22
- Re: Tree-sitter api, Yuan Fu, 2022/04/22
- Re: Tree-sitter api, Theodor Thornhill, 2022/04/22
- Re: Tree-sitter api,
Theodor Thornhill <=
Re: Tree-sitter api, Eli Zaretskii, 2022/04/01
Re: Tree-sitter api, Jostein Kjønigsen, 2022/04/04