Skip to content

Commit 65da2cd

Browse files
committed
perf(emacs): add emacs-lsp-booster
1 parent 994a847 commit 65da2cd

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

flake.lock

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
spicetify-nix.inputs.nixpkgs.follows = "nixpkgs";
3939

4040
nixos-wsl.url = "github:nix-community/NixOS-WSL/main";
41+
42+
emacs-lsp-booster.url = "github:slotThe/emacs-lsp-booster-flake";
43+
emacs-lsp-booster.inputs.nixpkgs.follows = "nixpkgs";
4144
};
4245

4346
outputs =

modules/nixos/programs/emacs/default.nix

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
config,
33
lib,
44
pkgs,
5+
inputs,
56
...
67
}:
78
with lib;
@@ -70,6 +71,8 @@ in
7071
ripgrep
7172
# magit-delta
7273
delta
74+
# LSP
75+
inputs.emacs-lsp-booster.packages.${pkgs.system}.default
7376
# lsp-nix
7477
nil
7578
nixfmt-rfc-style

modules/nixos/programs/emacs/init.el

+32
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,38 @@
791791
#'cape-file
792792
#'cape-dabbrev
793793
#'cape-keyword)))
794+
795+
(defun lsp-booster--advice-json-parse (old-fn &rest args)
796+
"Try to parse bytecode instead of json."
797+
(or
798+
(when (equal (following-char) ?#)
799+
(let ((bytecode (read (current-buffer))))
800+
(when (byte-code-function-p bytecode)
801+
(funcall bytecode))))
802+
(apply old-fn args)))
803+
(advice-add (if (progn (require 'json)
804+
(fboundp 'json-parse-buffer))
805+
'json-parse-buffer
806+
'json-read)
807+
:around
808+
#'lsp-booster--advice-json-parse)
809+
810+
(defun lsp-booster--advice-final-command (old-fn cmd &optional test?)
811+
"Prepend emacs-lsp-booster command to lsp CMD."
812+
(let ((orig-result (funcall old-fn cmd test?)))
813+
(if (and (not test?) ;; for check lsp-server-present?
814+
(not (file-remote-p default-directory)) ;; see lsp-resolve-final-command, it would add extra shell wrapper
815+
lsp-use-plists
816+
(not (functionp 'json-rpc-connection)) ;; native json-rpc
817+
(executable-find "emacs-lsp-booster"))
818+
(progn
819+
(when-let ((command-from-exec-path (executable-find (car orig-result)))) ;; resolve command from exec-path (in case not found in $PATH)
820+
(setcar orig-result command-from-exec-path))
821+
(message "Using emacs-lsp-booster for %s!" orig-result)
822+
(cons "emacs-lsp-booster" orig-result))
823+
orig-result)))
824+
825+
(advice-add 'lsp-resolve-final-command :around #'lsp-booster--advice-final-command)
794826
:hook
795827
(lsp-mode . lsp-enable-which-key-integration)
796828
(lsp-mode . yas-minor-mode)

0 commit comments

Comments
 (0)