forked from satori/dotrc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
;;; lsp-booster.el --- Emacs configuration -*- lexical-binding: t -*- | ||
|
||
(require 'lsp-protocol) | ||
|
||
(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))) | ||
|
||
(defun lsp-booster-install () | ||
(when (executable-find "emacs-lsp-booster") | ||
(advice-add | ||
'lsp-resolve-final-command :around #'lsp-booster--advice-final-command))) | ||
|
||
(provide 'lsp-booster) | ||
;;; lsp-booster.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters