diff options
| author | Yuan Fu | 2022-12-07 14:50:16 -0800 |
|---|---|---|
| committer | Yuan Fu | 2022-12-09 17:24:08 -0800 |
| commit | ebef8905b0df9572e80e20fdc8da7829b9270e3f (patch) | |
| tree | 05f3b264babb0edf4d1a4d6985eca3f7aac1ed3d /test/src | |
| parent | 8f53fa10d9453f36aa601e5943cb903adeacc7fe (diff) | |
| download | emacs-ebef8905b0df9572e80e20fdc8da7829b9270e3f.tar.gz emacs-ebef8905b0df9572e80e20fdc8da7829b9270e3f.zip | |
Make indirect buffers use tree-sitter parsers of their base buffer
Fix the problem described in bug#59693.
* src/treesit.c (treesit_record_change): Always use the base buffer.
(Ftreesit_parser_create): Always use the base buffer. Also change the
for loop into FOR_EACH_TAIL (stylistic change).
(Ftreesit_parser_list): Always use the base buffer.
* doc/lispref/parsing.texi (Using Parser): Update manual.
* test/src/treesit-tests.el (treesit-indirect-buffer): New test.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/treesit-tests.el | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/src/treesit-tests.el b/test/src/treesit-tests.el index aba12759c34..1cc2217bd3b 100644 --- a/test/src/treesit-tests.el +++ b/test/src/treesit-tests.el | |||
| @@ -161,6 +161,40 @@ | |||
| 161 | (should (treesit-node-eq root-node root-node)) | 161 | (should (treesit-node-eq root-node root-node)) |
| 162 | (should (not (treesit-node-eq root-node doc-node)))))) | 162 | (should (not (treesit-node-eq root-node doc-node)))))) |
| 163 | 163 | ||
| 164 | (ert-deftest treesit-indirect-buffer () | ||
| 165 | "Tests for indirect buffers." | ||
| 166 | (skip-unless (treesit-language-available-p 'json)) | ||
| 167 | (let ((base (get-buffer-create "*treesit test*")) | ||
| 168 | parser indirect) | ||
| 169 | (unwind-protect | ||
| 170 | (progn | ||
| 171 | (with-current-buffer base | ||
| 172 | (setq indirect (clone-indirect-buffer "*treesit test 1*" nil))) | ||
| 173 | (with-current-buffer indirect | ||
| 174 | (setq parser (treesit-parser-create 'json))) | ||
| 175 | ;; 1. Parser created in the indirect buffer should be | ||
| 176 | ;; actually be created in the base buffer. | ||
| 177 | (with-current-buffer base | ||
| 178 | (should (equal (list parser) | ||
| 179 | (treesit-parser-list))) | ||
| 180 | (insert "[1,2,3]")) | ||
| 181 | ;; Change in the base buffer should be reflected in the | ||
| 182 | ;; indirect buffer. | ||
| 183 | (with-current-buffer indirect | ||
| 184 | (should (eq (treesit-node-end | ||
| 185 | (treesit-buffer-root-node)) | ||
| 186 | 8)) | ||
| 187 | (erase-buffer)) | ||
| 188 | ;; Change in the indirect buffer should be reflected in the | ||
| 189 | ;; base buffer. | ||
| 190 | (with-current-buffer base | ||
| 191 | (should (eq (treesit-node-end | ||
| 192 | (treesit-buffer-root-node)) | ||
| 193 | 1)) | ||
| 194 | (erase-buffer))) | ||
| 195 | (kill-buffer base) | ||
| 196 | (kill-buffer indirect)))) | ||
| 197 | |||
| 164 | (ert-deftest treesit-query-api () | 198 | (ert-deftest treesit-query-api () |
| 165 | "Tests for query API." | 199 | "Tests for query API." |
| 166 | (skip-unless (treesit-language-available-p 'json)) | 200 | (skip-unless (treesit-language-available-p 'json)) |