Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
Last active February 16, 2024 18:17
Show Gist options
  • Select an option

  • Save jdtsmith/d936801a4d7fd981bedf2e59dacd675e to your computer and use it in GitHub Desktop.

Select an option

Save jdtsmith/d936801a4d7fd981bedf2e59dacd675e to your computer and use it in GitHub Desktop.

Revisions

  1. jdtsmith revised this gist Jan 15, 2024. No changes.
  2. jdtsmith revised this gist Jan 9, 2024. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions eglot-booster.el
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,9 @@

    ;;; Commentary:

    ;; **UPDATE** This has been superseded by the following package:
    ;; https://github.com/jdtsmith/eglot-booster
    ;;
    ;; Boost eglot with emacs-lsp-booster.
    ;; 1. Download a recent emacs-lsp-booster from
    ;; https://github.com/blahgeek/emacs-lsp-booster
  3. jdtsmith revised this gist Jan 6, 2024. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions eglot-booster.el
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    ;;; Commentary:

    ;; Boost eglot with emacs-lsp-booster.
    ;; 1. Download emacs-lsp-booster from
    ;; 1. Download a recent emacs-lsp-booster from
    ;; https://github.com/blahgeek/emacs-lsp-booster
    ;; 2. In the cloned directory, build with cargo (rust):
    ;; cargo build --release
    @@ -39,7 +39,8 @@ be boosted."
    (if (get 'eglot-server-programs 'lsp-booster-p)
    (message "eglot-server-programs already boosted.")
    (let ((cnt 0)
    (orig-read (symbol-function 'jsonrpc--json-read)))
    (orig-read (symbol-function 'jsonrpc--json-read))
    (boost '("emacs-lsp-booster" "--json-false-value" ":json-false" "--")))
    (dolist (entry eglot-server-programs)
    (cond
    ((functionp (cdr entry))
    @@ -48,11 +49,11 @@ be boosted."
    (setcdr entry (lambda (&rest r) ; wrap function
    (let ((res (apply fun r)))
    (if (eglot-booster-plain-command res)
    (cons "emacs-lsp-booster" res)
    (append boost res)
    res))))))
    ((eglot-booster-plain-command (cdr entry))
    (cl-incf cnt)
    (setcdr entry (cons "emacs-lsp-booster" (cdr entry))))))
    (setcdr entry (append boost (cdr entry))))))
    (defalias 'jsonrpc--json-read
    (lambda ()
    (or (and (= (following-char) ?#)
    @@ -63,5 +64,8 @@ be boosted."
    (message "Boosted %d eglot-server-programs" cnt))
    (put 'eglot-server-programs 'lsp-booster-p t)))

    (defun eglot-booster-reset ()
    (put 'eglot-server-programs 'lsp-booster-p nil))

    (provide 'eglot-booster)
    ;;; eglot-booster.el ends here
  4. jdtsmith revised this gist Jan 5, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions eglot-booster.el
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,7 @@

    ;;; Code:
    (eval-when-compile (require 'cl-lib))
    (require 'seq)
    (require 'eglot)
    (require 'jsonrpc)

  5. jdtsmith revised this gist Jan 4, 2024. 1 changed file with 32 additions and 28 deletions.
    60 changes: 32 additions & 28 deletions eglot-booster.el
    Original file line number Diff line number Diff line change
    @@ -21,6 +21,12 @@
    (require 'eglot)
    (require 'jsonrpc)

    (defun eglot-booster-plain-command (com)
    "Test if command COM is a plain eglot server command."
    (and (consp com)
    (not (integerp (cadr com)))
    (not (seq-intersection '(:initializationOptions :autoport) com))))

    (defun eglot-booster ()
    "Boost plain eglot server programs with emacs-lsp-booster.
    The emacs-lsp-booster program must be compiled and available on
    @@ -31,32 +37,30 @@ be boosted."
    (user-error "The emacs-lsp-booster program is not installed"))
    (if (get 'eglot-server-programs 'lsp-booster-p)
    (message "eglot-server-programs already boosted.")
    (cl-labels
    ((plain-command (com)
    (and (consp com)
    (not (integerp (cadr com)))
    (not (seq-intersection '(:initializationOptions :autoport) com)))))
    (let ((cnt 0)
    (orig-read (symbol-function 'jsonrpc--json-read)))
    (dolist (entry eglot-server-programs)
    (cond
    ((functionp (cdr entry))
    (cl-incf cnt)
    (let ((fun (cdr entry)))
    (setcdr entry (lambda (&rest r) ; wrap function
    (let ((res (apply fun r)))
    (if (plain-command res)
    (cons "emacs-lsp-booster" res)
    res))))))
    ((plain-command (cdr entry))
    (cl-incf cnt)
    (setcdr entry (cons "emacs-lsp-booster" (cdr entry))))))
    (defalias 'jsonrpc--json-read
    (lambda ()
    (or (and (= (following-char) ?#)
    (let ((bytecode (read (current-buffer))))
    (when (byte-code-function-p bytecode)
    (funcall bytecode))))
    (funcall orig-read))))
    (message "Boosted %d eglot-server-programs" cnt)))
    (let ((cnt 0)
    (orig-read (symbol-function 'jsonrpc--json-read)))
    (dolist (entry eglot-server-programs)
    (cond
    ((functionp (cdr entry))
    (cl-incf cnt)
    (let ((fun (cdr entry)))
    (setcdr entry (lambda (&rest r) ; wrap function
    (let ((res (apply fun r)))
    (if (eglot-booster-plain-command res)
    (cons "emacs-lsp-booster" res)
    res))))))
    ((eglot-booster-plain-command (cdr entry))
    (cl-incf cnt)
    (setcdr entry (cons "emacs-lsp-booster" (cdr entry))))))
    (defalias 'jsonrpc--json-read
    (lambda ()
    (or (and (= (following-char) ?#)
    (let ((bytecode (read (current-buffer))))
    (when (byte-code-function-p bytecode)
    (funcall bytecode))))
    (funcall orig-read))))
    (message "Boosted %d eglot-server-programs" cnt))
    (put 'eglot-server-programs 'lsp-booster-p t)))

    (provide 'eglot-booster)
    ;;; eglot-booster.el ends here
  6. jdtsmith revised this gist Jan 4, 2024. No changes.
  7. jdtsmith revised this gist Jan 4, 2024. No changes.
  8. jdtsmith revised this gist Jan 4, 2024. No changes.
  9. jdtsmith renamed this gist Jan 4, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. jdtsmith revised this gist Jan 4, 2024. 1 changed file with 8 additions and 6 deletions.
    14 changes: 8 additions & 6 deletions Eglot-booster.el
    Original file line number Diff line number Diff line change
    @@ -4,15 +4,17 @@
    ;;; Commentary:

    ;; Boost eglot with emacs-lsp-booster.
    ;; 1. Download from
    ;; https://github.com/blahgeek/emacs-lsp-booster Build with cargo
    ;; 2. cargo build --release
    ;; 1. Download emacs-lsp-booster from
    ;; https://github.com/blahgeek/emacs-lsp-booster
    ;; 2. In the cloned directory, build with cargo (rust):
    ;; cargo build --release
    ;; 3. place the target/release/emacs-lsp-booster program somewhere on
    ;; exec-path.
    ;; `exec-path'.
    ;; 4. M-x eglot-booster
    ;; 5. Use eglot like normal
    ;;
    ;; Note: works only with local commands via standard input/output, not
    ;; remote LSP servers.
    ;; Note: works only with local lsp servers via standard input/output,
    ;; not remote LSP servers.

    ;;; Code:
    (eval-when-compile (require 'cl-lib))
  11. jdtsmith created this gist Jan 4, 2024.
    60 changes: 60 additions & 0 deletions Eglot-booster.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    ;;; eglot-booster.el --- boost eglot using emacs-lsp-booster -*- lexical-binding: t; -*-
    ;; Copyright (C) 2024 J.D. Smith

    ;;; Commentary:

    ;; Boost eglot with emacs-lsp-booster.
    ;; 1. Download from
    ;; https://github.com/blahgeek/emacs-lsp-booster Build with cargo
    ;; 2. cargo build --release
    ;; 3. place the target/release/emacs-lsp-booster program somewhere on
    ;; exec-path.
    ;; 4. M-x eglot-booster
    ;;
    ;; Note: works only with local commands via standard input/output, not
    ;; remote LSP servers.

    ;;; Code:
    (eval-when-compile (require 'cl-lib))
    (require 'eglot)
    (require 'jsonrpc)

    (defun eglot-booster ()
    "Boost plain eglot server programs with emacs-lsp-booster.
    The emacs-lsp-booster program must be compiled and available on
    variable `exec-path'. Only local stdin/out based lsp servers can
    be boosted."
    (interactive)
    (unless (executable-find "emacs-lsp-booster")
    (user-error "The emacs-lsp-booster program is not installed"))
    (if (get 'eglot-server-programs 'lsp-booster-p)
    (message "eglot-server-programs already boosted.")
    (cl-labels
    ((plain-command (com)
    (and (consp com)
    (not (integerp (cadr com)))
    (not (seq-intersection '(:initializationOptions :autoport) com)))))
    (let ((cnt 0)
    (orig-read (symbol-function 'jsonrpc--json-read)))
    (dolist (entry eglot-server-programs)
    (cond
    ((functionp (cdr entry))
    (cl-incf cnt)
    (let ((fun (cdr entry)))
    (setcdr entry (lambda (&rest r) ; wrap function
    (let ((res (apply fun r)))
    (if (plain-command res)
    (cons "emacs-lsp-booster" res)
    res))))))
    ((plain-command (cdr entry))
    (cl-incf cnt)
    (setcdr entry (cons "emacs-lsp-booster" (cdr entry))))))
    (defalias 'jsonrpc--json-read
    (lambda ()
    (or (and (= (following-char) ?#)
    (let ((bytecode (read (current-buffer))))
    (when (byte-code-function-p bytecode)
    (funcall bytecode))))
    (funcall orig-read))))
    (message "Boosted %d eglot-server-programs" cnt)))
    (put 'eglot-server-programs 'lsp-booster-p t)))