Emacs lsp booster

This commit is contained in:
2024-09-28 08:38:25 -07:00
parent a9cb653949
commit 361eda0412
4 changed files with 57 additions and 1 deletions

21
nix/flake.lock generated
View File

@@ -1,5 +1,25 @@
{ {
"nodes": { "nodes": {
"emacs-lsp-booster": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1716274896,
"narHash": "sha256-WsyEkdt8ReGQ40+yV4Cb99A2MEmV0O/i6rmFQura5ww=",
"owner": "slotThe",
"repo": "emacs-lsp-booster-flake",
"rev": "7d110295988fc9bf7fd43bb0cabfbe58a4a5ecf8",
"type": "github"
},
"original": {
"owner": "slotThe",
"repo": "emacs-lsp-booster-flake",
"type": "github"
}
},
"home-manager": { "home-manager": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@@ -38,6 +58,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"emacs-lsp-booster": "emacs-lsp-booster",
"home-manager": "home-manager", "home-manager": "home-manager",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"utils": "utils" "utils": "utils"

View File

@@ -2,9 +2,11 @@
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils"; utils.url = "github:numtide/flake-utils";
emacs-lsp-booster.url = "github:slotThe/emacs-lsp-booster-flake";
home-manager.url = "github:nix-community/home-manager"; home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs"; home-manager.inputs.nixpkgs.follows = "nixpkgs";
emacs-lsp-booster.inputs.nixpkgs.follows = "nixpkgs";
}; };
outputs = { outputs = {
@@ -12,10 +14,12 @@
nixpkgs, nixpkgs,
utils, utils,
home-manager, home-manager,
emacs-lsp-booster,
...}: let ...}: let
pkgsForSystem = (system: import nixpkgs { pkgsForSystem = (system: import nixpkgs {
inherit system; inherit system;
overlays = [ overlays = [
emacs-lsp-booster.overlays.default
]; ];
config.allowUnfree = true; config.allowUnfree = true;
}); });

View File

@@ -9,7 +9,7 @@ in
programs.emacs.extraPackages = epkgs: [ epkgs.vterm ]; programs.emacs.extraPackages = epkgs: [ epkgs.vterm ];
home.packages = with pkgs; let home.packages = with pkgs; let
basePackages = [ zstd ]; basePackages = [ zstd emacs-lsp-booster ];
macPackages = basePackages ++ [ coreutils ]; macPackages = basePackages ++ [ coreutils ];
in in
if isOnMac then macPackages else basePackages; if isOnMac then macPackages else basePackages;

View File

@@ -719,6 +719,37 @@
(defun my/lsp-mode-setup-completion () (defun my/lsp-mode-setup-completion ()
(setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults)) (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
'(orderless))) '(orderless)))
(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))
orig-result)))
(advice-add 'lsp-resolve-final-command :around #'lsp-booster--advice-final-command)
:hook ((rust-ts-mode . lsp-deferred) :hook ((rust-ts-mode . lsp-deferred)
(lsp-mode . lsp-enable-which-key-integration) (lsp-mode . lsp-enable-which-key-integration)
(lsp-completion-mode . my/lsp-mode-setup-completion))) (lsp-completion-mode . my/lsp-mode-setup-completion)))