Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activating mmm-mode without any setup leads to error in typescript-ts-mode #138

Open
dschrempf opened this issue Sep 26, 2023 · 6 comments

Comments

@dschrempf
Copy link

I just wanted to try out mmm-mode before setting anything up (I need to edit SQL statements within TypeScript code).

I open a TypeScript file (*.ts), activate typescript-ts-mode, and activate mmm-mode.

I get an error with the following trace:

Debugger entered--Lisp error: (treesit-query-error "Node type error at" 2 "(jsx_opening_element [(member_expression (identifier)) (identifier)] @typescript-ts-jsx-tag-face) (jsx_closing_element [(member_expression (identifier)) (identifier)] @typescript-ts-jsx-tag-face) (jsx_self_closing_element [(member_expression (identifier)) (identifier)] @typescript-ts-jsx-tag-face) (jsx_attribute (property_identifier) @typescript-ts-jsx-attribute-face)" "Debug the query with `treesit-query-validate'")
  treesit-font-lock-fontify-region(1 7380 nil)
  font-lock-fontify-syntactically-region(1 7380 nil)
  font-lock-default-fontify-region(1 7380 nil)
  font-lock-fontify-region(1 7380 nil)
  font-lock-default-fontify-buffer()
  font-lock-fontify-buffer()
  font-lock-initial-fontify()
  font-lock-mode(1)
  treesit-major-mode-setup()
  typescript-ts-mode()
  mmm-update-mode-info(typescript-ts-mode)
  mmm-mode-on()
  mmm-mode(nil)
  funcall-interactively(mmm-mode nil)
  command-execute(mmm-mode record)
  execute-extended-command(nil "mmm-mode" nil)
  funcall-interactively(execute-extended-command nil "mmm-mode" nil)
  command-execute(execute-extended-command)
@dgutov
Copy link
Owner

dgutov commented Sep 26, 2023

Hi!

Are you sure you don't see any such errors in the Messages without enabling mmm-mode?

@dschrempf
Copy link
Author

I am not completely sure, but the few tests I made just now didn't show any warnings nor errors with TypeScript files.

@dgutov
Copy link
Owner

dgutov commented Sep 26, 2023

Okay, I can repro.

This is odd: the font-lock query with jsx_opening_element should only be used with tsx-ts-mode, not with this one.

@dgutov
Copy link
Owner

dgutov commented Sep 27, 2023

Unfortunately, the best fix I found so far is patch against Emacs:

diff --git a/lisp/treesit.el b/lisp/treesit.el
index f0d6f32b421..c1834bbfb9a 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -2725,7 +2725,7 @@ treesit-major-mode-setup
                 '( nil nil nil nil
                    (font-lock-fontify-syntactically-function
                     . treesit-font-lock-fontify-region)))
-    (font-lock-mode 1)
+    ;; (font-lock-mode 1)
     (treesit-font-lock-recompute-features)
     (dolist (parser (treesit-parser-list))
       (treesit-parser-add-notifier

I've filed a report to Debbugs (https://debbugs.gnu.org/66223), maybe we'll be able to have this in Emacs 29.2. Or you could patch locally, or build from source.

The problem is mostly specific to typescript-ts-mode (in the context of mmm-mode), so it should be better with most or all other TS modes. Still, the way tree-sitter works is both more likely to conflict with this package, so I'm curious to hear about your and others' experience with this combination.

In any case, treesit.el also has its own way of defining mixed-language modes, but it requires writing more Elisp.

@dschrempf
Copy link
Author

dschrempf commented Sep 27, 2023

Great work, thanks for finding the cause and reporting it uptream!

The following is definitely unrelated to mmm-mode, but I thought it may be relevant for the bug you reported:

I thought I could circumvent the bug by just using tsx-ts-mode (the TypeScript mode equivalent for tsx files, which, I thought, should also work for ts files). But when activating tsx-ts-mode (no mmm-mode activated), I also get

Debugger entered--Lisp error: (treesit-query-error "Structure error at" 22 "(jsx_opening_element [(member_expression (identifier)) (identifier)] @typescript-ts-jsx-tag-face) (jsx_closing_element [(member_expression (identifier)) (identifier)] @typescript-ts-jsx-tag-face) (jsx_self_closing_element [(member_expression (identifier)) (identifier)] @typescript-ts-jsx-tag-face) (jsx_attribute (property_identifier) @typescript-ts-jsx-attribute-face)" "Debug the query with `treesit-query-validate'")
  treesit-font-lock-fontify-region(1 307 nil)
  font-lock-fontify-syntactically-region(1 307 nil)
  font-lock-default-fontify-region(1 307 nil)
  font-lock-fontify-region(1 307)
  #f(compiled-function (fun) #<bytecode -0x1552e40ec3721b83>)(font-lock-fontify-region)
  jit-lock--run-functions(1 307)
  jit-lock-fontify-now(1 307)
  font-lock-ensure()
  orglink-mode()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook typescript-ts-base-mode-hook tsx-ts-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook typescript-ts-base-mode-hook tsx-ts-mode-hook))
  run-mode-hooks(tsx-ts-mode-hook)
  tsx-ts-mode()
  funcall-interactively(tsx-ts-mode)
  command-execute(tsx-ts-mode record)
  execute-extended-command(nil "tsx-ts-mode" nil)
  funcall-interactively(execute-extended-command nil "tsx-ts-mode" nil)
  command-execute(execute-extended-command)

@dgutov
Copy link
Owner

dgutov commented Sep 27, 2023

The following is definitely unrelated to mmm-mode, but I thought it may be relevant for the bug you reported:

Thank you. This is a known one, actually 😬 It's fixed in the emacs-29 branch (emacs-mirror/emacs@65f4810003b617ea), to become Emacs 29.2 is some not too-distant future.

To have it working right now, you can either build from source (or patch locally), or install an older version of the typescript grammar. Anything slightly older than tree-sitter/tree-sitter-typescript@b893426 should work (e.g. its parent).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants