Hi! Today I wrote my first Doom module. As far as I can tell it works as intended, but I’d like a review. Especially, after reading Common config anti-patterns, I worry about the performance impact of the LSP part. Below is what I have as of today.
;;; lang/roc/config.el -*- lexical-binding: t; -*-
;; Setup the major mode for roc source files
(define-derived-mode roc-mode fundamental-mode "Roc"
"Major mode for the Roc programming language")
(add-to-list 'auto-mode-alist
'("\\.roc\\'" . roc-mode))
;; Setup the LSP support
;; TODO: Is this the right way to set up the server? Am I hindering Doom's performance?
;; See https://discourse.doomemacs.org/t/common-config-anti-patterns/119#loading-packages-too-early-3
(if (and
(modulep! :tools lsp)
(modulep! :lang roc +lsp))
(use-package! lsp-mode
:config
(progn
(add-to-list 'lsp-language-id-configuration '(roc-mode . "roc"))
(lsp-register-client (make-lsp-client :new-connection (lsp-stdio-connection "roc_ls")
:activation-fn (lsp-activate-on "roc")
:major-modes '(roc-mode)
:server-id 'roc_ls))
(add-hook 'roc-mode-local-vars-hook #'lsp!))))
You can also see the same code in context of my whole system configuration. I will be pushing eventual updates there.
What are you trying to do?
It’s working as intended
When I visit any .roc file, Emacs sets the major mode to roc-mode
and connects to the language server (starting it if necessary). The code assumes that roc_ls
program is installed (I provide language servers on a per-project basis, see here for example https://gitlab.com/tad-lispy/roc-language-playground/-/blob/31b53052f24666d85ef8fc035f1f92c5006fb49c/flake.nix#L21).
I consider myself a novice at Emacs Lisp, so I will appreciate any constructive feedback.