Proper way to get full syntax highlighting when building grammar into a library for consumption? #2990
Replies: 3 comments 5 replies
-
Highlighting typically happens from using queries to match on certain sexp patterns and apply a capture/highlight to them. I would ask this in emacs wherever relevant as to how this is done, but you can test out highlighting with the |
Beta Was this translation helpful? Give feedback.
-
Also, for Emacs >= 29.1 with tree-sitter library support compiled in [1], typically highlighting is "programmatically" provided as part of a tree-sitter specific mode that If you look for FWIW, I don't see much discussion at this repository about using tree-sitter with Emacs. I've seen discussion at the gnu emacs devel mailing list though. There is also a discord server (mentioned at the top of here), but I don't know how many Emacs-using types hang out there ATM. [1] This stuff is used by the Rust bindings effort for tree-sitter support for Emacs. AFAIU, it's not what Emacs >= 29.1 + tree-sitter stuff uses. Also, the [2] There may be exceptions -- this is just the way it had been for a while. |
Beta Was this translation helpful? Give feedback.
-
Closing for now then since it sounds like this isn't really a Treesitter specific issue. |
Beta Was this translation helpful? Give feedback.
-
👋
Apologies if this isn't the right spot to ask, but figured this might be the right place to start at least. It's likely a skill / knowledge issue on my part but the documentation on how this particular aspect of Treesitter works is a bit lacking and I was hoping someone could help clear things up.
tldr' - I can build a library for use in Emacs just fine; but syntax highlighting isn't complete and only some parts are highlighted.
Setting the scene
My current understanding of the process is as follows
npm install
, thentree-sitter generate
parser.c
(andscanner.c
if present) into appropriate library format with some kind of c compiler depending on system or runtree-sitter generate -b
in the previous step instead.After fiddling around with things I'm about 98% there - While using the cli, testing, highlighting, etc helpers all work as expected.
However the missing 2% is the syntax highlighting inside of Emacs. I can successfully build a library for use inside of Emacs and while there is "some" highlighting, there is not as much compared to using one of the pre-built libraries out there or the cli highlighter.
Obviously I'm missing a step and I'm not sure where to go from here.
I should note that running the cli's
generate -b
command appears to result in the same library behavior compared to when I compile things myself.Any help is appreciated! Thank you!🍻
For comparison
First is using pre-built, second is the version I built
Possibly related?
tree-sitter init-config
) is utilized. It does look like that's potentially part of the issue(?)queries
folder of a grammar stores the important syntax highlighting bits but it's not clear how to compile thescm
files into the library.npm install
I see Node generates a VS studio project - When I look at what it automatically builds, I get a bunch of build artifacts including a.node
file which appears to be what the project is supposed to output to(this also happens when I open/build the project myself). Trying to use this file however results in Emacs not being able to find the grammar library, even if I rename it to a.dll
(which is what the project is supposed to generate anyways)Last Notes
I realize there are alternatives to building grammars myself, however
With the built-in function within Emacs 29, for some reason, while it manages to create the appropriate temporary directories, it somehow isn't able to clone a grammar repo to the directory and fails midway. Not sure if it's a Windows / Emacs issue or not and not sure how to debug.This is more a combination of user error + unexpected repo setup as it turns out. I initially ran into this error with the Typescript grammar which splits things into typescript + tsx and it didn't occur to me that that I wasn't accounting for that. I could have swore I tried this with a single language grammar as well but maybe not.I know pre-built libraries exist for Emacs - I just wanted to better understand the process myself from a more general perspective rather than relying on specific tooling(which is what the existing script that's available is doing). I will likely just end up running the script that's provided and see what happens but my Elisp knowledge isn't great yet and I'm not sure I'd fully understand what's happening without a bunch more debugging)
Beta Was this translation helpful? Give feedback.
All reactions