~ruther/emacs.d

787a273a6ed017aa7f639e838f8ca642884ef100 — Rutherther 6 months ago 1c523ab
feat: add lsp-booster
2 files changed, 38 insertions(+), 1 deletions(-)

M early-init.el
M init.el
M early-init.el => early-init.el +4 -0
@@ 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)

M init.el => init.el +34 -1
@@ 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)