Add language server support to Emacs
I suspect this will involve a similar process to getting vim support.
Looks like we'd need to add it to https://github.com/emacs-lsp/lsp-mode
It's a little involved and since we don't have a ton of demand for this right now, I'm going to put it back in the backlog.
This would be a feature I would use. I prefer to use the built-in eglot package (because it's built-in. Maybe lsp-mode is better, I'm not sure). https://github.com/joaotavora/eglot
It might be as simple as customizing eglot-server-programs, something that could be added to documentation for the user to do with no code change to eglot.
I have not looked into it
Thanks @MorganJamesSmith . Eglot looks like it should work. Not sure if we will get time to add this support any time soon but happy to help advise if you wanted to have a go in the mean time :)
So I have added this code snippet to my init file:
(define-derived-mode sway-mode prog-mode "sway")
(add-to-list 'auto-mode-alist '("\\.sw\\'" . sway-mode))
(add-to-list
'eglot-server-programs
'((sway-mode) .
("nix" "shell" "github:fuellabs/fuel.nix#fuel" "--command" "forc-lsp")))
As far as I can tell the language server part works great!
I'm able to jump to definitions and view documentation in the mode-line via eldoc.
The only problem seems to be that there is zero code highlighting. No colors. Like staring at a plain text file.
This is sub-optimal.
I think the current thing holding back emacs support is not actually the LSP server, but the lack of a major mode for sway. I was unable to find anything myself but could you confirm there is no emacs major mode for sway?
Actually if we define sway mode like this (inheriting the rust tree-sitter mode (emacs doesn't have a normal rust-mode, only a tree-sitter version)):
(define-derived-mode sway-mode rust-ts-mode "sway")
Then the highlighting seems about right. Are there any major differences between sway and rust? Can I rely on rust tree-sitter (https://github.com/tree-sitter/tree-sitter-rust) to parse sway code correctly?
Nice! sounds like good progress. We actually have a tree-sitter definition for sway here that you could use https://github.com/FuelLabs/tree-sitter-sway
Hey @sdankel @JoshuaBatty, I'm part of the Mira core team through ChartHouse Labs working on some major tooling, ecosystem, and design overhauls.
Also an Emacs (Doom) user that would really appreciate LSP support as I'm learning Sway currently, could be interested in contributing :)
Oh look @MorganJamesSmith is here too 👀
Hello! I have written sway-ts-mode to add sway syntax highlighting to Emacs. It was a lot more work then I was expecting. Here is the link: https://git.sr.ht/~morgansmith/sway-ts-mode
It seems to work but I haven't tested it extensively. If other people could try it I would appreciate that. I should probably add better documentation but that will have to wait until at least tomorrow