mickeynp / combobulate

Structured Editing and Navigation in Emacs with Tree-Sitter
GNU General Public License v3.0
945 stars 54 forks source link

Failed to compile warning when enabling combobulate-mode in typescript #80

Closed anderso closed 8 months ago

anderso commented 9 months ago

Whenever i enable combobulate-mode in a typescript-ts-mode buffer, the Warnings buffer is displayed with this message:

Warning (emacs): Query ((arrow_function body:
                 ((_
                   (sequence_expression left:
                                        (_)
                                        @combobulate-query-highlight-vibrant-veggie-face))))) failed to compile: (85 . Structure error at).

combobulate seems to work fine though.

mickeynp commented 9 months ago

Thanks for raising that. Could be your libtreesitter that's old; your grammar that's old (or really new!) and that's causing it. I'll investigate.

anderso commented 9 months ago

It might be because they are new, this is my emacs version:

GNU Emacs 29.2 (build 3, x86_64-pc-linux-gnu, GTK+ Version 3.24.41, cairo version 1.18.0) of 2024-01-27

and the grammar should be from git master as of yesterday.

mickeynp commented 9 months ago

Thanks, I'll have a look. They are stupidly not versioned at all, and the query engine throws a hissyfit if it encounters a node type it does not know.

anderso commented 9 months ago

It is indeed caused by updates in the grammar(s) because changing from master to v0.20.3, ie:

(setq treesit-language-source-alist
  '((tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "v0.20.3" "tsx/src"))
    (typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "v0.20.3" "typescript/src"))))

and reinstalling makes the error go away. And it seems they have actually started tagging versions: https://github.com/tree-sitter/tree-sitter-typescript/releases

mickeynp commented 9 months ago

Thanks for investigating.

domq commented 9 months ago

Today I ran into what I believe is the same issue; I pulled Combobulate from the development branch and I got roughly the same warning, except with 66 instead of 85:

⛔ Warning (emacs): Query ((arrow_function body:
                 ((_ (sequence_expression left: (_) @combobulate-query-highlight-vibrant-veggie-face))))) failed to compile: (66 . Structure error at).

After some debugging and source-code reading, I am able to provide a smaller reproduction case: evaluating

(treesit-query-capture 'tsx "((arrow_function body:\n                 ((_ (sequence_expression left: (_) @combobulate-query-highlight-vibrant-veggie-face)))))")

produces the following error,

progn: Query pattern is malformed: "Structure error at", 66, "((arrow_function body:
                 ((_ (sequence_expression left: (_) @combobulate-query-highlight-vibrant-veggie-face)))))", "Debug the query with `treesit-query-validate'"

Indeed, commenting out line 266 of combobulate-js-ts.el, that reads

((arrow_function body: ((_ (sequence_expression left: (_) @hl.veggie)))))

makes the warning go away.

mickeynp commented 9 months ago

Yeah you need to use an older, tagged, release of TSX -- it's rather annoying. I'll have to build something into combobulate to test if queries are valid.

domq commented 9 months ago

Yeah you need to use an older, tagged, release of TSX -- it's rather annoying. I'll have to build something into combobulate to test if queries are valid.

Got it, what are your thoughts on https://github.com/mickeynp/combobulate/pull/81 ?

mickeynp commented 8 months ago

Should be fixed in Combobulate master. Note that you must now keep your grammar consistent with what Combobulate/Emacs expects