unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Tree-sitter node type error when trying to set up font lock
@ 2024-05-03  7:39 Jeremy Baxter via Users list for the GNU Emacs text editor
  2024-05-04  1:54 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 2+ messages in thread
From: Jeremy Baxter via Users list for the GNU Emacs text editor @ 2024-05-03  7:39 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 655 bytes --]

Hi list,

I'm working on a tree-sitter-based major mode for D, and after setting
up font lock I receive the following error in the *Messages* buffer:

    Error during redisplay: (jit-lock-function 3193) signaled (treesit-query-error
    "Node type error at" 3 "[\"alias\" \"class\" ...] @font-lock-keyword-face"
    "Debug the query with `treesit-query-validate'")

A minimal sample of the source is attached but this vector in the
error is replaced with the contents of `d-ts--keywords' spliced into a
vector. Calling `treesit-query-validate' doesn't tell me anything new
either. Does anyone know what I'm doing wrong?

Thanks,
 ~Jeremy

[-- Attachment #2: d-ts-mode.el --]
[-- Type: text/x-emacs-lisp, Size: 1494 bytes --]

(require 'c-ts-mode)

(defvar d-ts--keywords
  (list
    ;; declarations
    "alias" "class" "interface" "module" "struct" "template" "union"

    ;; expressions
    "__FILE__" "__FILE_FULL_PATH__" "__MODULE__"
    "__LINE__" "__FUNCTION__" "_PRETTY_FUNCTION_"
    "__traits" "__parameters" "cast" "is" "new"

    ;; labels
    "case" "default"

    ;; modifiers
    "__gshared" "abstract" "align" "auto" "const" "deprecated"
    "enum" "export" "extern" "final" "immutable" "in" "inout" 
    "lazy" "nothrow" "out" "override" "package" "pragma" "private"
    "protected" "public" "pure" "ref" "scope" "shared" "static"
    "synchronized"
    "@disable" "@nogc" "@property" "@safe" "@system" "@trusted"

    ;; statements
    "asm" "assert" "break" "catch" "continue" "debug" "do" "else"
    "finally" "for" "foreach" "foreach_reverse" "goto" "if" "import"
    "invariant" "mixin" "return" "super" "switch" "this" "throw"
    "try" "typeid" "typeof" "unittest" "version" "while" "with"

    ;; unused
    "macro"))

(defvar d-ts--font-lock-rules
  (treesit-font-lock-rules
   :language 'd
   :feature 'keyword
   `([,@d-ts--keywords] @font-lock-keyword-face)))

(define-derived-mode d-ts-mode c-ts-base-mode "D"
  "Major mode for editing D, powered by tree-sitter."

  (when (treesit-ready-p 'd)
    ;; Font-lock.
    (setq-local treesit-font-lock-settings d-ts--font-lock-rules)
    (treesit-major-mode-setup)))

(add-to-list 'auto-mode-alist '("\\.di?\\'" . d-ts-mode))

(provide 'd-ts-mode)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Tree-sitter node type error when trying to set up font lock
  2024-05-03  7:39 Tree-sitter node type error when trying to set up font lock Jeremy Baxter via Users list for the GNU Emacs text editor
@ 2024-05-04  1:54 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-05-04  1:54 UTC (permalink / raw)
  To: help-gnu-emacs

"Jeremy Baxter" wrote:
> I'm working on a tree-sitter-based major mode for D, and after setting
> up font lock I receive the following error in the *Messages* buffer:
>
>     Error during redisplay: (jit-lock-function 3193) signaled (treesit-query-error
>     "Node type error at" 3 "[\"alias\" \"class\" ...] @font-lock-keyword-face"
>     "Debug the query with `treesit-query-validate'")

You might like to try `jit-lock-debug-mode` which will delay the
jit-lock code so it runs from a timer instead of running from within
redisplay: that makes it easier to debug (you should be able to get
a backtrace, for example).


        Stefan




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-04  1:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-03  7:39 Tree-sitter node type error when trying to set up font lock Jeremy Baxter via Users list for the GNU Emacs text editor
2024-05-04  1:54 ` Stefan Monnier via Users list for the GNU Emacs text editor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).