emacs: Giving eglot another go

This commit is contained in:
Erwin Boskma 2023-05-21 22:14:27 +02:00
parent 349f8cdb87
commit 08afcf25c8
Signed by: erwin
SSH key fingerprint: SHA256:9LmFDe1C6jSrEyqxxvX8NtJBmcbB105XoqyUZF092bg

View file

@ -905,11 +905,11 @@ Visualise git changes in the gutter, next to the line numbers
:after tree-sitter)
#+end_src
*** LSP
*** lsp-mode
[[https://emacs-lsp.github.io/lsp-mode][lsp-mode]] adds Language Server Protocol support to emacs.
#+begin_src emacs-lisp
#+begin_src emacs-lisp :tangle no
(use-package lsp-mode
:init
(setq lsp-keymap-prefix "C-c l"
@ -934,7 +934,7 @@ Visualise git changes in the gutter, next to the line numbers
[[https://emacs-lsp.github.io/lsp-ui/][lsp-ui]] provides higher level UI elements for =lsp-mode=, like code lenses and flycheck support.
#+begin_src emacs-lisp
#+begin_src emacs-lisp :tangle no
(use-package lsp-ui
:ghook 'lsp-mode-hook
:config
@ -955,22 +955,22 @@ Visualise git changes in the gutter, next to the line numbers
[[https://github.com/gagbo/consult-lsp][consult-lsp]] integrates =consult= into =lsp-mode=
#+begin_src emacs-lisp
#+begin_src emacs-lisp :tangle no
(use-package consult-lsp)
#+end_src
[[https://github.com/emacs-lsp/lsp-treemacs][lsp-treemacs]] provides an integration between =lsp-mode= and [[https://github.com/Alexander-Miller/treemacs][treemacs]].
#+begin_src emacs-lisp
#+begin_src emacs-lisp :tangle no
(use-package lsp-treemacs
:commands lsp-treemacs-errors-list)
#+end_src
*** DAP
*** dap-mode
[[http://emacs-lsp.github.io/dap-mode][dap-mode]] provides debugging facilities using the [[https://microsoft.github.io/debug-adapter-protocol/][Debug Adapter Protocol]]
#+begin_src emacs-lisp
#+begin_src emacs-lisp :tangle no
(use-package dap-mode
:defer t
:custom
@ -998,6 +998,35 @@ Visualise git changes in the gutter, next to the line numbers
(find-file-existing filename))))
#+end_src
*** eglot
[[https://joaotavora.github.io/eglot/][eglot]] is an alternative to =lsp-mode= that is builtin with emacs >= 29
#+begin_src emacs-lisp
(use-package eglot
:config
(add-to-list 'eglot-server-programs
'(conf-toml-mode . ("taplo" "lsp" "stdio"))
'(elixir-mode elixir-ts-mode heex-ts-mode . ("elixir-ls")))
(setq eglot-autoshutdown t))
#+end_src
[[https://github.com/nemethf/eglot-x][eglot-x]] adds support for some LSP extensions to =eglot=
#+begin_src emacs-lisp :tangle no
(use-package eglot-x
:vc (:fetcher github :repo nemethf/eglot-x)
:after eglot
:config
(eglot-x-setup))
#+end_src
[[https://github.com/mohkale/consult-eglot][consult-eglot]] adds an integration between =consult= and =eglot=
#+begin_src emacs-lisp
(use-package consult-eglot)
#+end_src
** Snippets
Snippets are predefined pieces of code that can be inserted and filled in. [[https://github.com/joaotavora/yasnippet][YASnippet]] uses syntax inspired by TextMate is the most popular, for good reason.
@ -1034,13 +1063,13 @@ Indent 2 spaces
#+begin_src emacs-lisp
(use-package js2-mode
:after lsp-mode
:after eglot
:mode
("\\.mjs\\'" . js2-mode)
("\\.jsx?\\'" . js2-jsx-mode)
:hook
(js2-mode . lsp-deferred)
(js2-jsx-mode . lsp-deferred))
(js2-mode . eglot-ensure)
(js2-jsx-mode . eglot-ensure))
#+end_src
Prettier has my preference for formatting JavaScript and TypeScript
@ -1057,10 +1086,10 @@ TypeScript stuff
#+begin_src emacs-lisp
(use-package typescript-mode
:after lsp-mode
:after eglot
:mode
("\\.tsx?\\'" . typescript-mode)
:hook (typescript-mode . lsp-deferred))
:hook (typescript-mode . eglot-ensure))
#+end_src
Prefer local packages from =node_modules= to global ones
@ -1075,7 +1104,7 @@ Prefer local packages from =node_modules= to global ones
#+begin_src emacs-lisp
(use-package web-mode
:after lsp-mode
:after eglot
:config
(setq web-mode-markup-indent-offset 2
web-mode-css-indent-offset 2
@ -1087,7 +1116,7 @@ Prefer local packages from =node_modules= to global ones
(add-to-list 'web-mode-engines-alist '(("elixir" . "\\.html.heex\\'")))
:hook
((html-mode css-mode web-mode) . lsp-deferred))
((html-mode css-mode web-mode) . eglot-ensure))
#+end_src
*** Markdown
@ -1096,7 +1125,7 @@ Prefer local packages from =node_modules= to global ones
#+begin_src emacs-lisp
(use-package markdown-mode
:after lsp-mode
:after eglot
:mode
(("README\\.md\\'" . gfm-mode)
("\\.md\\'" . markdown-mode)
@ -1105,7 +1134,7 @@ Prefer local packages from =node_modules= to global ones
(setq markdown-command "multimarkdown")
:hook
(markdown-mode . display-fill-column-indicator-mode)
(markdown-mode . lsp-deferred))
(markdown-mode . eglot-ensure))
#+end_src
[[https://github.com/skeeto/impatient-mode][impatient-mode]] live renders HTML, but it can be made to work with Markdown with a custom filter
@ -1132,7 +1161,7 @@ Add support for Elixir with [[https://github.com/elixir-editors/emacs-elixir][el
#+begin_src emacs-lisp
(use-package elixir-mode
:after lsp-mode
:after eglot
:hook ((elixir-format . (lambda ()
(if (projectile-project-p)
(setq elixir-format-arguments
@ -1140,7 +1169,7 @@ Add support for Elixir with [[https://github.com/elixir-editors/emacs-elixir][el
(concat (locate-dominating-file buffer-file-name ".formatter.exs") ".formatter.exs")))
(setq elixir-format-arguments nil))))
(elixir-mode . (lambda () (add-hook 'before-save-hook 'elixir-format nil t)))
(elixir-mode . lsp-deferred))
(elixir-mode . eglot-ensure))
:config
(setq lsp-elixir-server-command '("elixir-ls"))
(add-to-list 'auto-mode-alist '("\\.[hl]eex\\'" . elixir-mode)))
@ -1172,17 +1201,48 @@ Rust support with [[https://github.com/rust-lang/rust-mode][rust-mode]].
#+begin_src emacs-lisp
(use-package rust-mode
:after lsp-mode
:after eglot
:hook
(rust-mode . lsp-deferred)
(rust-ts-mode . lsp-deferred)
(before-save . lsp-format-buffer)
(before-save . lsp-organize-imports)
:init
(setq lsp-rust-analyzer-cargo-watch-command "clippy"
lsp-rust-analyzer-server-display-inlay-hints t
lsp-rust-analyzer-binding-mode-hints t
lsp-rust-analyzer-display-lifetime-elision-hints-enable "always"))
(rust-mode . eglot-ensure)
(rust-ts-mode . eglot-ensure)
(before-save . eglot-format-buffer)
(before-save . eglot-code-action-organize-imports)
;; :init
;; (setq lsp-rust-analyzer-cargo-watch-command "clippy"
;; lsp-rust-analyzer-server-display-inlay-hints t
;; lsp-rust-analyzer-binding-mode-hints t
;; lsp-rust-analyzer-display-lifetime-elision-hints-enable "always")
)
#+end_src
Configure [[https://rust-analyzer.github.io][rust-analyzer]]
#+begin_src emacs-lisp
(defun eb/ra-eglot-config (server)
"initializationOptions for rust-analyzer"
`(:diagnostics (:enable t)
:imports (:granularity (:enforce :json-false :group "crate")
:group t :merge
(:glob t)
:prefix "plain")
:lruCapacity nil
:checkOnSave (:enable t
:command "clippy"
:allTargets t)
:inlayHints (:bindingModeHints t
:chainingHints t
:lifetimeElisionHints (:enable "always" :useParameterNames :json-false)
:maxLength nil
:parameterHints :json-false
:renderColons t
:typeHints (:enable t
:hideClosureInitialization :json-false
:hideNamedConstructor :json-false))
:procMacro (:enable t)))
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs
'(rust-mode . ("rust-analyzer" :initializationOptions eb/ra-eglot-config))))
#+end_src
Add [[https://github.com/kwrooijen/cargo.el][cargo]] support
@ -1216,8 +1276,8 @@ Add docker support with [[https://github.com/spotify/dockerfile-mode][dockerfile
#+begin_src emacs-lisp
(use-package dockerfile-mode
:after lsp-mode
:hook (dockerfile-mode . lsp-deferred))
:after eglot
:hook (dockerfile-mode . eglot-ensure))
#+end_src
*** Bitbake / Yocto
@ -1241,8 +1301,8 @@ Add docker support with [[https://github.com/spotify/dockerfile-mode][dockerfile
#+begin_src emacs-lisp
(use-package json-mode
:after lsp-mode
:hook (json-mode . lsp-deferred))
:after eglot
:hook (json-mode . eglot-ensure))
#+end_src
*** CMake
@ -1251,8 +1311,8 @@ Add [[https://melpa.org/#/cmake-mode][cmake-mode]]
#+begin_src emacs-lisp
(use-package cmake-mode
:after lsp-mode
:hook (cmake-mode . lsp-deferred))
:after eglot
:hook (cmake-mode . eglot-ensure))
#+end_src
*** YAML
@ -1261,8 +1321,8 @@ Use [[https://github.com/yoshiki/yaml-mode][yaml-mode]] to handle YAML files
#+begin_src emacs-lisp
(use-package yaml-mode
:after lsp-mode
:hook (yaml-mode . lsp-deferred))
:after eglot
:hook (yaml-mode . eglot-ensure))
#+end_src
*** C/C++
@ -1271,10 +1331,10 @@ Enable clangd LSP for C and C++
#+begin_src emacs-lisp
(use-package cc-mode
:ensure nil
:after lsp-mode
:after eglot
:hook
(c-mode . lsp-deferred)
(c++-mode . lsp-deferred))
(c-mode . eglot-ensure)
(c++-mode . eglot-ensure))
#+end_src
Enable and configure =auto-insert-mode= for Horus projects
@ -1306,9 +1366,9 @@ Add [[https://github.com/NixOS/nix-mode][nix-mode]]
#+begin_src emacs-lisp
(use-package nix-mode
:after lsp-mode
:after eglot
:mode "\\.nix\\'"
:hook (nix-mode . lsp-deferred))
:hook (nix-mode . eglot-ensure))
#+end_src
*** Common Lisp
@ -1342,8 +1402,8 @@ Similar to =lisp=, there is [[https://github.com/clojure-emacs/cider][CIDER]] (C
#+begin_src emacs-lisp
(use-package terraform-mode
:after lsp-mode
:hook (terraform-mode . lsp-deferred))
:after eglot
:hook (terraform-mode . eglot-ensure))
#+end_src
*** Fish
@ -1362,8 +1422,8 @@ Similar to =lisp=, there is [[https://github.com/clojure-emacs/cider][CIDER]] (C
#+begin_src emacs-lisp
(use-package zig-mode
:after lsp-mode
:hook (zig-mode . lsp-deferred))
:after eglot
:hook (zig-mode . eglot-ensure))
#+end_src
*** Yuck
@ -1376,8 +1436,8 @@ Similar to =lisp=, there is [[https://github.com/clojure-emacs/cider][CIDER]] (C
#+begin_src emacs-lisp
(use-package racket-mode
:after lsp-mode
:hook (racket-mode . lsp-deferred))
:after eglot
:hook (racket-mode . eglot-ensure))
#+end_src
*** Ruby
@ -1387,8 +1447,8 @@ Let =ruby-mode= handle Ruby files
#+begin_src emacs-lisp
(use-package ruby-mode
:ensure nil
:after lsp-mode
:hook (ruby-mode . lsp-deferred))
:after eglot
:hook (ruby-mode . eglot-ensure))
#+end_src
*** MapServer
@ -1407,8 +1467,8 @@ It's better than nothing.
#+begin_src emacs-lisp
(use-package go-mode
:after lsp-mode
:hook (go-mode . lsp-deferred))
:after eglot
:hook (go-mode . eglot-ensure))
#+end_src
*** Cucumber