Trying emacs-lsp-booster and eglot with zls

This commit is contained in:
Andrew Scott 2024-05-18 13:02:27 -04:00
parent 220e26d91f
commit ada842259c
Signed by: a
GPG key ID: 7CD5A5977E4931C1
2 changed files with 68 additions and 10 deletions

View file

@ -95,5 +95,8 @@
(push '(tool-bar-lines . 0) default-frame-alist) (push '(tool-bar-lines . 0) default-frame-alist)
(push '(vertical-scroll-bars) default-frame-alist) (push '(vertical-scroll-bars) default-frame-alist)
;; Make lsp-mode use plists
(setenv "LSP_USE_PLISTS" "true")
(provide 'early-init) (provide 'early-init)
;;; early-init.el ends here ;;; early-init.el ends here

View file

@ -166,15 +166,25 @@
(use-package display-fill-column-indicator (use-package display-fill-column-indicator
:ensure nil :ensure nil
:init (setq-default fill-column 100)
:hook ((conf-mode :hook ((conf-mode
markdown-mode markdown-mode
prog-mode) . display-fill-column-indicator-mode) prog-mode) . display-fill-column-indicator-mode))
:config (setq-default fill-column 100))
(use-package display-line-numbers (use-package display-line-numbers
:ensure nil :ensure nil
:hook ((conf-mode prog-mode) . display-line-numbers-mode)) :hook ((conf-mode prog-mode) . display-line-numbers-mode))
(use-package eglot
:ensure nil
:hook (zig-mode . eglot-ensure)
:bind (:map
eglot-mode-map
("C-c c a" . eglot-code-actions)
("C-c c o" . eglot-code-actions-organize-imports)
("C-c c r" . eglot-rename)
("C-c c f" . eglot-format)))
(use-package elec-pair (use-package elec-pair
:ensure nil :ensure nil
:defer 3 :defer 3
@ -196,6 +206,15 @@
require-final-newline t require-final-newline t
version-control t)) version-control t))
(use-package flymake
:ensure nil
:bind (:map flymake-mode-map
("C-c ! d" . flymake-show-buffer-diagnostics)
("C-c ! D" . flymake-show-project-diagnostics)
("C-c ! n" . flymake-goto-next-error)
("C-c ! p" . flymake-goto-prev-error))
:config (flymake-mode))
(use-package flyspell (use-package flyspell
:ensure nil :ensure nil
:defer 3 :defer 3
@ -203,7 +222,7 @@
(((git-commit-mode (((git-commit-mode
markdown-mode markdown-mode
text-mode) . flyspell-mode) text-mode) . flyspell-mode)
(lsp-mode . flyspell-prog-mode))) (prog-mode . flyspell-prog-mode)))
(use-package mwheel (use-package mwheel
:ensure nil :ensure nil
@ -243,7 +262,7 @@
(save-place-mode)) (save-place-mode))
(use-package seq (use-package seq
; Unload seq before elpaca build ;; Unload seq before elpaca build
:ensure `(seq :build ,(+elpaca-seq-build-steps))) :ensure `(seq :build ,(+elpaca-seq-build-steps)))
(use-package simple (use-package simple
@ -594,16 +613,22 @@
:after (consult flycheck)) :after (consult flycheck))
;; LSP ;; LSP
(use-package eglot-booster
:ensure (eglot-booster :host github :repo "jdtsmith/eglot-booster")
:after eglot
:config (eglot-booster-mode))
(use-package lsp-mode (use-package lsp-mode
:hook :hook
(((c-ts-mode (((c-ts-mode
c++-ts-mode c++-ts-mode
csharp-ts-mode csharp-ts-mode
go-ts-mode go-ts-mode
python-ts-mode python-ts-mode) . lsp)
zig-mode) . lsp) ;; zig-mode) . lsp)
(lsp-mode . lsp-enable-which-key-integration)) (lsp-mode . lsp-enable-which-key-integration))
:custom :custom
(lsp-use-plists t)
(lsp-idle-delay 0.6) (lsp-idle-delay 0.6)
(lsp-prefer-flymake nil) (lsp-prefer-flymake nil)
(lsp-session-file (concat xdg_cache_home "lsp-session"))) (lsp-session-file (concat xdg_cache_home "lsp-session")))
@ -617,7 +642,7 @@
(lsp-ui-peek-enable t) (lsp-ui-peek-enable t)
(lsp-ui-sideline-delay 0.6) (lsp-ui-sideline-delay 0.6)
(lsp-ui-sideline-show-code-actions t) (lsp-ui-sideline-show-code-actions t)
(lsp-ui-sideline-show-hover t) (lsp-ui-sideline-show-hover nil)
(lsp-ui-sideline-update-mode 'line)) (lsp-ui-sideline-update-mode 'line))
(use-package consult-lsp (use-package consult-lsp
@ -630,6 +655,36 @@
:after (lsp-mode treemacs) :after (lsp-mode treemacs)
:config (lsp-treemacs-sync-mode)) :config (lsp-treemacs-sync-mode))
;; Configure emacs-lsp-booster for lsp-mode
(defun lsp-booster--advice-json-parse (old-fn &rest args)
"Try to parse bytecode instead of json."
(or
(when (equal (following-char) ?#)
(let ((bytecode (read (current-buffer))))
(when (byte-code-function-p bytecode)
(funcall bytecode))))
(apply old-fn args)))
(advice-add (if (progn (require 'json)
(fboundp 'json-parse-buffer))
'json-parse-buffer
'json-read)
:around
#'lsp-booster--advice-json-parse)
(defun lsp-booster--advice-final-command (old-fn cmd &optional test?)
"Prepend emacs-lsp-booster command to lsp CMD."
(let ((orig-result (funcall old-fn cmd test?)))
(if (and (not test?) ;; for check lsp-server-present?
(not (file-remote-p default-directory)) ;; see lsp-resolve-final-command, it would add extra shell wrapper
lsp-use-plists
(not (functionp 'json-rpc-connection)) ;; native json-rpc
(executable-find "emacs-lsp-booster"))
(progn
(message "Using emacs-lsp-booster for %s!" orig-result)
(cons "emacs-lsp-booster" orig-result))
orig-result)))
(advice-add 'lsp-resolve-final-command :around #'lsp-booster--advice-final-command)
;; Debugging ;; Debugging
(use-package dap-mode (use-package dap-mode
:after (lsp-mode) :after (lsp-mode)