diff options
| author | Yuan Fu | 2025-02-27 04:06:36 -0800 |
|---|---|---|
| committer | Yuan Fu | 2025-02-27 17:22:04 -0800 |
| commit | 8a45c2da226e188420956fd6269f72db3f437e38 (patch) | |
| tree | 73f0b006c4b406957d59c879e1adf4900cd9385f | |
| parent | 1314272bf398e068385572ca16d4dfcd55a48828 (diff) | |
| download | emacs-8a45c2da226e188420956fd6269f72db3f437e38.tar.gz emacs-8a45c2da226e188420956fd6269f72db3f437e38.zip | |
Make treesit-node-at take advantage of the embed-level property
* lisp/treesit.el (treesit-node-at): Select the local parser
with the highest embed-level.
| -rw-r--r-- | lisp/treesit.el | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el index 5a067575e65..8374ce936de 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el | |||
| @@ -258,10 +258,20 @@ language and doesn't match the language of the local parser." | |||
| 258 | ;; finding parser, try local parser first, then global | 258 | ;; finding parser, try local parser first, then global |
| 259 | ;; parser. | 259 | ;; parser. |
| 260 | (t | 260 | (t |
| 261 | ;; LANG can be nil. | 261 | ;; LANG can be nil. We don't want to use the fallback |
| 262 | (let* ((lang (treesit-language-at pos)) | 262 | ;; in `treesit-language-at', so here we call |
| 263 | (local-parser (car (treesit-local-parsers-at | 263 | ;; `treesit-language-at-point-function' directly. |
| 264 | pos lang))) | 264 | (let* ((lang (and treesit-language-at-point-function |
| 265 | (funcall treesit-language-at-point-function | ||
| 266 | pos))) | ||
| 267 | (local-parser | ||
| 268 | ;; Find the local parser with highest | ||
| 269 | ;; embed-level at point. | ||
| 270 | (car (seq-sort-by #'treesit-parser-embed-level | ||
| 271 | (lambda (a b) | ||
| 272 | (> (or a 0) (or b 0))) | ||
| 273 | (treesit-local-parsers-at | ||
| 274 | pos lang)))) | ||
| 265 | (global-parser (car (treesit-parser-list | 275 | (global-parser (car (treesit-parser-list |
| 266 | nil lang))) | 276 | nil lang))) |
| 267 | (parser (or local-parser global-parser))) | 277 | (parser (or local-parser global-parser))) |