diff options
| author | Yuan Fu | 2025-03-02 20:26:28 -0800 |
|---|---|---|
| committer | Yuan Fu | 2025-03-02 20:28:07 -0800 |
| commit | a211a940a1e085d53172ceddf6bfc2391985e861 (patch) | |
| tree | 0af6e785d23bb2c9abc0152d2e3260293e10d52e | |
| parent | 76342efe9d758a6ca66cdc0ed197381664a6fbbd (diff) | |
| download | emacs-a211a940a1e085d53172ceddf6bfc2391985e861.tar.gz emacs-a211a940a1e085d53172ceddf6bfc2391985e861.zip | |
Don't process function range settings in treesit--update-range-1
This fixes a bug where we call treesit-query-language on a
function, which happens before the QUERY in a range setting can
be either a function or a query, but we call it with
treesit-query-language before knowing whether it's a query or
function.
* lisp/treesit.el:
(treesit--update-range-1): Skip function range settings.
(treesit-update-ranges): Handle function range settings here.
| -rw-r--r-- | lisp/treesit.el | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el index 640b75769bb..313916dd077 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el | |||
| @@ -1059,7 +1059,9 @@ embedded language parsers. | |||
| 1059 | EMBED-LEVEL is the embed level for the embedded parser being created or | 1059 | EMBED-LEVEL is the embed level for the embedded parser being created or |
| 1060 | updated. When looking for existing embedded parsers, only look for | 1060 | updated. When looking for existing embedded parsers, only look for |
| 1061 | parsers of this level; when creating new parsers, set their level to | 1061 | parsers of this level; when creating new parsers, set their level to |
| 1062 | this level." | 1062 | this level. |
| 1063 | |||
| 1064 | Function range settings in SETTINGS are ignored." | ||
| 1063 | (let ((touched-parsers nil) | 1065 | (let ((touched-parsers nil) |
| 1064 | (modified-tick (buffer-chars-modified-tick))) | 1066 | (modified-tick (buffer-chars-modified-tick))) |
| 1065 | (dolist (setting settings) | 1067 | (dolist (setting settings) |
| @@ -1071,7 +1073,9 @@ this level." | |||
| 1071 | (range-fn (nth 4 setting))) | 1073 | (range-fn (nth 4 setting))) |
| 1072 | (when (eq query-lang (treesit-parser-language host-parser)) | 1074 | (when (eq query-lang (treesit-parser-language host-parser)) |
| 1073 | (cond | 1075 | (cond |
| 1074 | ((functionp query) (funcall query beg end)) | 1076 | ;; Function range settings don't participate in the recursive |
| 1077 | ;; update, they're handled by `treesit--update-range'. | ||
| 1078 | ((functionp query) nil) | ||
| 1075 | (local | 1079 | (local |
| 1076 | (setq touched-parsers | 1080 | (setq touched-parsers |
| 1077 | (append touched-parsers | 1081 | (append touched-parsers |
| @@ -1100,6 +1104,11 @@ region." | |||
| 1100 | (end (or end (point-max))) | 1104 | (end (or end (point-max))) |
| 1101 | (host-parsers (list treesit-primary-parser)) | 1105 | (host-parsers (list treesit-primary-parser)) |
| 1102 | (embed-level 0)) | 1106 | (embed-level 0)) |
| 1107 | ;; Handle function range settings here once. They don't participate | ||
| 1108 | ;; in the recursive update below. | ||
| 1109 | (dolist (setting treesit-range-settings) | ||
| 1110 | (when (functionp (car setting)) | ||
| 1111 | (funcall (car setting) beg end))) | ||
| 1103 | (while (and host-parsers (< embed-level 4)) | 1112 | (while (and host-parsers (< embed-level 4)) |
| 1104 | (cl-incf embed-level) | 1113 | (cl-incf embed-level) |
| 1105 | (let ((next-round-of-host-parsers nil)) | 1114 | (let ((next-round-of-host-parsers nil)) |