From 787a273a6ed017aa7f639e838f8ca642884ef100 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sun, 8 Feb 2026 15:36:15 +0100 Subject: [PATCH] feat: add lsp-booster --- early-init.el | 4 ++++ init.el | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/early-init.el b/early-init.el index 1ae5ce2cb2ac74353fbf705dc307f8b42acc53d5..41aa41836685ba8ed2c502eb00ca0645df008e01 100644 --- a/early-init.el +++ b/early-init.el @@ -84,6 +84,10 @@ ;; End of speed optimizations ;; ------------------------------------------------------------------------------------------ +;; lsp-mode plists +(setenv "LSP_USE_PLISTS" "true") +(setq lsp-use-plists t) + ;; Visual stuff init (menu-bar-mode -1) (tool-bar-mode -1) diff --git a/init.el b/init.el index 5f46479fa6d540952d0a3e536dfbc9adda2caef9..4eaee1848dbc412360d1004015da37aae935c1a4 100644 --- a/init.el +++ b/init.el @@ -1383,7 +1383,40 @@ :config (defun lsp-conditional () "Enable LSP only if already running in project." - (lsp-deferred))) + (lsp-deferred)) + + (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 + (when-let ((command-from-exec-path (executable-find (car orig-result)))) ;; resolve command from exec-path (in case not found in $PATH) + (setcar orig-result command-from-exec-path)) + (message "Using emacs-lsp-booster for %s!" orig-result) + (cons "emacs-lsp-booster" orig-result)) + (progn + (message "Skipping emacs-lsp-booster.") + orig-result)))) + (advice-add 'lsp-resolve-final-command :around #'lsp-booster--advice-final-command)) (my-use-package lsp-treemacs :ensure t)