Open dannyfreeman opened 1 year ago
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?
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.
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 perhapstreesit-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
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.