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

Add optional support for tree-sitter #396

Closed
dominikh opened this issue Dec 16, 2021 · 8 comments
Closed

Add optional support for tree-sitter #396

dominikh opened this issue Dec 16, 2021 · 8 comments

Comments

@dominikh
Copy link
Owner

dominikh commented Dec 16, 2021

We can replace most, if not all, of our custom movement functions with tree-sitter, making them more robust.

@To1ne
Copy link

To1ne commented Dec 8, 2022

Now tree-sitter is built-in in the new Emacs, this issue has become more relevant.

I think as a start we can implement a go-ts-mode (similar to other -ts-modes). I'd love to have a look at it, when I find some time.

There are some guidelines on how to do this at https://git.savannah.gnu.org/cgit/emacs.git/tree/admin/notes/tree-sitter/starter-guide

@edkolev
Copy link

edkolev commented Dec 14, 2022

Is it viable to contribute go-ts-mode to emacs itself? With eglot already part of emacs, emacs will be able to provide modern Go environment out of the box, provided gopls is available.

@dominikh
Copy link
Owner Author

If you want to put up with GNU and the FSF to get your code into Emacs, feel free to. I, however, won't take part in that.

(I think there are also less political arguments against having go-ts-mode in Emacs, such as mismatching release cycles between Go and Emacs.)

@dominikh
Copy link
Owner Author

Based on the document To1ne linked to, it seems like we should implement a new major mode go-ts-mode. Code that can be shared between the current go-mode and the new go-ts-mode will go in a base mode go-base-mode.

I will probably work on this myself in the near future.

@zwpaper
Copy link

zwpaper commented Dec 28, 2022

FYI

Emacs has worked on a go-ts-mode, https://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-29&id=fee2efe1b035d601ac53a32801227402e9be8bca

@To1ne
Copy link

To1ne commented Dec 28, 2022

Emacs has worked on a go-ts-mode, https://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-29&id=fee2efe1b035d601ac53a32801227402e9be8bca

That's great! With that I consider this issue closed.

One thing would be nice though, if it would be possible to use gofmt-before-save with go-ts-mode. The change would be something along the lines of:

 (defun gofmt-before-save ()
   "Add this to .emacs to run gofmt on the current buffer when saving:
 \(add-hook 'before-save-hook 'gofmt-before-save).

 Note that this will cause ‘go-mode’ to get loaded the first time
 you save any file, kind of defeating the point of autoloading."

   (interactive)
-   (when (eq major-mode 'go-mode) (gofmt)))
+   (when (member major-mode '(go-mode go-ts-mode)) (gofmt)))

Until that, I have this in my config:

(defun my-go-mode-setup ()
  "Setup Go mode to my liking."
  (add-hook 'before-save-hook 'gofmt nil t))

(use-package go-mode
  :ensure t
  :mode (("\\.go$" . go-ts-mode))
  :hook ((go-mode go-ts-mode) . my-go-mode-setup)
  :custom (gofmt-command "goimports"))

Or you could use this if you like: https://gist.github.com/GnaneshKunal/3d3f982ce1903990eedd586952893422

@dominikh
Copy link
Owner Author

That's great! With that I consider this issue closed.

I don't. Using that mode loses you most of the features of the current go-mode, and doesn't use tree-sitter to its full potential to replace most of the custom navigation functions in go-mode, like go-goto-arguments.

Big fan of the fact they took the name go-ts-mode, too, while not owning go-mode.

@dominikh
Copy link
Owner Author

Closing in favour of #428.

@dominikh dominikh closed this as not planned Won't fix, can't repro, duplicate, stale Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants