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

Interactive function for diagnosing grammar version issues #19

Open
dannyfreeman opened this issue Sep 9, 2023 · 2 comments
Open

Interactive function for diagnosing grammar version issues #19

dannyfreeman opened this issue Sep 9, 2023 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@dannyfreeman
Copy link
Contributor

dannyfreeman commented Sep 9, 2023

Create an interactive function, called something like clojure-ts-grammar-doctor that checks the available clojure and markdown grammars for compatibility with the current queries we issue.

This can be done by calling treesit-query-capture and checking for errors, or perhaps treesit-query-validate with a series of diagnostic queries that can help us narrow down what version of the grammar is loaded, and other info to see where the grammar was loaded from the file system.

These diagnostic queries should check for nodes and tree structures we depend on that may not exist in older versions of the grammars.

If the doctor function finds no issues, a nice message should be displayed in the echo area.
If the doctor does find issues, perhaps a special buffer *clojure-ts-doctor* can be shown with details about the issues found.

Example

A query like this

(kwd_lit (kwd_name) @capture)

Would only work on versions of tree-sitter-clojure greater than v0.0.10 and later. If a user has an older grammar clojure-ts-mode will break. If that happens the user can run clojure-ts-grammar-doctor to get a "diagnosis" about the grammar they do have and recommendations for remedying the problem.

@rrudakov
Copy link
Contributor

Some major modes in emacs has workarounds for different versions of grammars (for example https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/progmodes/typescript-ts-mode.el?h=emacs-29#n157). Would something like this work for clojure-ts-mode?

@dannyfreeman
Copy link
Contributor Author

Indeed, I've submitted a couple bug fixes to Emacs for js-ts-mode where those version workarounds didn't work properly.

When tree-sitter-clojure or another grammar this mode depends on is inevitably updated we will have to use workarounds like that. In my experience those are very cumbersome to write and test. Mostly because there is no way to tell what version of a grammar is loaded.

Depending on the nature of a future grammar update, that may mean users of the latest grammar get more features than those using an older grammar. If a user wonders why they aren't seeing some new fancy highlighting then the functionality described in this issue would help them figure out why.

tree-sitter-clojure is pretty stable though, and the only other grammar we depend on is a markdown grammar, and in that we only query for 1 type of node. Because there isn't a great need for this this feature at the moment, it is low on my priority list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants