zig-mode icon indicating copy to clipboard operation
zig-mode copied to clipboard

[Request] Emacs 29 tree sitter mode

Open amusingimpala75 opened this issue 1 year ago • 4 comments

With Emacs 29.1 being released, Tree Sitter support is now natively in Emacs. However, to use it there needs to be a dedicated major mode extending the base mode. In this case there would need to be a zig-ts-mode. Would that be possible?

amusingimpala75 avatar Jul 31 '23 18:07 amusingimpala75

With Emacs 29.1 being released, Tree Sitter support is now natively in Emacs. However, to use it there needs to be a dedicated major mode extending the base mode. In this case there would need to be a zig-ts-mode. Would that be possible?

Same issue here, I install the following language grammar libraries:

  ;;
  ;; Configuration for downloading and installing
  ;; tree-sitter language grammars.
  ;;
  (setq treesit-language-source-alist
    '((c "https://github.com/tree-sitter/tree-sitter-c")
      (cpp "https://github.com/tree-sitter/tree-sitter-cpp")
      (zig "https://github.com/maxxnino/tree-sitter-zig")
  )

  ;;
  ;; remap the non-treesitter mode to treesitter mode
  ;;
  (setq major-mode-remap-alist
   '((c-mode . c-ts-mode)
     (cpp-mode . cpp-ts-mode)
     (zig-mode . zig-ts-mode)
    )
  )

Then I saw 812K Aug 17 19:10 libtree-sitter-zig.so* in my ~/.config/emacs/tree-sitter/ folder.

And run (treesit-language-available-p 'zig) return t means install successfully.

Also, I installed zig-mode:

  (use-package zig-mode
    :hook (zig-mode . lsp-deferred)
    :hook (zig-ts-mode . lsp-deferred)
  )

But when I open zig project, there is NO zig-ts-mode there (only got zig-mode)....:(

wisonye avatar Aug 17 '23 07:08 wisonye

This was also something I was interested in. I took a stab at doing this in my fork on the tree-sitter branch https://github.com/nanzhong/zig-mode/tree/tree-sitter.

On a high level, it refactors the current zig-mode into a generic zig-base-mode and a concrete zig-mode, while introducing a tree-sitter enabled zig-ts-mode that also derives from zig-base-mode. The main purpose of zig-base-mode is to make it possible to share common configuration between the concrete major modes.

At its current state it only makes use of tree-sitter for syntax highlighting, but I plan to work on indentation next, and imenu integration after that.

If this is an appropriate direction, I'd be happy to make a PR once I have tree-sitter based indentation working.

nanzhong avatar Jan 03 '24 05:01 nanzhong

I've got an initial version of tree-sitter based indentation working and I've created a PR for feedback and review.

nanzhong avatar Jan 04 '24 03:01 nanzhong

I've got an initial version of tree-sitter based indentation working and I've created a PR for feedback and review.

I tried using your branch with eglot/lsp-mode, but I can't seem to make it work with zig-ts-mode.

Doomwhite avatar Mar 09 '24 16:03 Doomwhite