-
Notifications
You must be signed in to change notification settings - Fork 56
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
Add tree-sitter enabled zig-ts-mode major mode #95
base: master
Are you sure you want to change the base?
Conversation
This change sets up the foundation for introducing a tree-sitter enabled zig-ts-mode that can also derive from zig-base-mode.
This initial version of zig-ts-mode only makes use of tree-sitter queries for syntax highlighting.
I genuinely think this should be a separated package, similar to the approach taken by numerous other major modes such as |
Would definitely need to be a separate package, otherwise it couldn't be byte-compiled on the older Emacsen that this package supports. |
I can't seem to be able to run eglot or lsp-mode with this major-mode... |
Eglot works for me, do you have logs you're willing to share? Edit: it started breaking for me recently too, I'm not sure why. Eglot will say it can't detect the language server, and once it's given zls, it'll succeed but say it's managing 0 buffers in the project. |
I agree with @jcs090218 and @purcell. At least as long as we support older Emacs versions which do not include tree sitter support by default, it is best to separate this into a different package/repository. There is https://github.com/ryleelyman/zig-ts-mode already, but it would be nice to have an official package under the ziglang organization. @andrewrk can we get a |
Would additional work be required to integrate the treesitter mode with this one? Or else commands that aren't specific to either the regular or tree sitter mode (such as the run command) would need to be duplicated across both. Kind of like what clojure is doing and IIRC Rustic mode used to have this too (where you can sub the treesitter mode in as a "backend" to the regular mode). Would a future official zig-ts-mode follow this architecture? |
There are two general patterns you'll see. Common base modeIn this scheme you'd have an artificial This pattern is probably the best overall, but you won't see it in some cases because it requires the "classic" major mode author to add that artificial base mode. Examples: Completely independent ts modeHere you'd have a Examples: If maintained in the same github org, or even if not, I'd suggest the first pattern is preferable. |
Since this thread doesn't seems to have much process by months, and github:robbielyman/zig-ts-mode is still an half-completed work (only font lock is based on tree sitter). I made my own |
Looks good! I'd be happy to add this to MELPA directly pretty much as-is, but I have a couple of requests first:
|
(Also the indent rules look surprisingly minimal, and at least one comment mentions rust-mode, probably copy-and-pasted) |
Thank you for ur advice. They all make sense :). I've correct it according to ur advice.
Copied from the upstream zig tree sitter grammar query file for indentation. They should work for most cases Edit: |
Cool, added to MELPA — it should start building within a few hours. If you add a version tag to the repo, it'll show up in MELPA Stable too. |
If in future everyone thinks it best, your repo could get moved to this GitHub org: we'd then need to adjust the MELPA recipe. Thanks for sharing your work! |
Addresses #89.
This PR refactors the existing
zig-mode
to derive from a new generic major modezig-base-mode
that holds common zig major mode configuration and then introduces a new tree-sitter enabledzig-ts-mode
major mode that makes use of the zig tree-sitter grammar from https://github.com/maxxnino/tree-sitter-zig.At the moment
zig-ts-mode
is pretty usable and supports tree-sitter powered syntax highlighting and indentation. It also derives common functionality like reformatter support, electric indent config, etc. fromzig-base-mode
. Two notable missing features are navigation and imenu integration (I don't use these much day to day -- I'm also very new to zig and have only been playing around with the language on the side -- so I have not yet implemented them).I wanted to create this draft PR to outline and share the approach that I've taken. If it's directionally sound, I'm happy to do the remaining work needed to get the PR across the finish line (e.g. readme updates, tests).
I've configured it for use as follows (using elpaca and use-package):