Reverting back to LSP instead of eglot

I may change back.
This commit is contained in:
Howard Abrams 2023-01-09 19:52:49 -08:00
parent b3a22bbd39
commit 0f55a368c5

View file

@ -221,69 +221,90 @@ I have two different /jumping/ systems, the [[info:emacs#Xref][Xref interface]]
The [[https://microsoft.github.io/language-server-protocol/][LSP]] is a way to connect /editors/ (like Emacs) to /languages/ (like Lisp)… wait, no. While originally designed for VS Code and probably Python, we can abstract away [[https://github.com/davidhalter/jedi][Jedi]] and the [[http://tkf.github.io/emacs-jedi/latest/][Emacs integration to Jedi]] (and duplicate everything for Ruby, and Clojure, and…). The [[https://microsoft.github.io/language-server-protocol/][LSP]] is a way to connect /editors/ (like Emacs) to /languages/ (like Lisp)… wait, no. While originally designed for VS Code and probably Python, we can abstract away [[https://github.com/davidhalter/jedi][Jedi]] and the [[http://tkf.github.io/emacs-jedi/latest/][Emacs integration to Jedi]] (and duplicate everything for Ruby, and Clojure, and…).
Emacs has two LSP projects, and while I have used [[LSP Mode]], but since I dont have heavy IDE requirements, I am finding that [[eglot]] to be simpler. Emacs has two LSP projects, and while I have used [[LSP Mode]], but since I dont have heavy IDE requirements, I am finding that [[eglot]] to be simpler.
*** eglot *** LSP
The [[https://github.com/joaotavora/eglot][eglot]] package connects to Emacs standard command interface, so the eglot-specific code is connects the [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Xref.html][xref interface]] to controlling backend servers. That said, it has a couple of =eglot-= commands that I want easy access to:
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package eglot (use-package lsp-mode
:commands (lsp lsp-deferred)
:init :init
(setq eglot-connect-timeout 10 ;; Let's make lsp-doctor happy with these settings:
eglot-autoshutdown t) (setq gc-cons-threshold (* 100 1024 1024)
read-process-output-max (* 1024 1024)
company-idle-delay 0.0 ; Are thing fast enough to do this?
lsp-keymap-prefix "s-m")
:config :config
(global-set-key (kbd "s-m") 'lsp)
(ha-prog-leader (ha-prog-leader
"w" '(:ignore t :which-key "eglot") "w" '(:ignore t :which-key "lsp")
"ws" '("start" . eglot)) "l" '(:ignore t :which-key "lsp")
"ws" '("start" . lsp))
;; The following leader-like keys, are only available when I have started LSP: ;; The following leader-like keys, are only available when I have
;; started LSP, and is an alternate to Command-m:
:general :general
(:states 'normal :keymaps 'eglot-mode-map (:states 'normal :keymaps 'lsp-mode-map
"SPC m w r" '("restart" . eglot-reconnect) "SPC m w r" '("restart" . lsp-reconnect)
"SPC m w b" '("events" . eglot-events-buffer) "SPC m w b" '("events" . lsp-events-buffer)
"SPC m w e" '("errors" . eglot-stderr-buffer) "SPC m w e" '("errors" . lsp-stderr-buffer)
"SPC m w q" '("quit" . eglot-shutdown) "SPC m w q" '("quit" . lsp-shutdown)
"SPC m w Q" '("quit all" . eglot-shutdown-all) "SPC m w Q" '("quit all" . lsp-shutdown-all)
"SPC m l" '(:ignore t :which-key "lsp") "SPC m l r" '("rename" . lsp-rename)
"SPC m l r" '("rename" . eglot-rename) "SPC m l f" '("format" . lsp-format)
"SPC m l f" '("format" . eglot-format) "SPC m l a" '("actions" . lsp-code-actions)
"SPC m l a" '("actions" . eglot-code-actions) "SPC m l i" '("imports" . lsp-code-action-organize-imports)
"SPC m l i" '("imports" . eglot-code-action-organize-imports) "SPC m l d" '("doc" . lsp-lookup-documentation))
"SPC m l d" '("doc" . eglot-lookup-documentation)))
:hook ((lsp-mode . lsp-enable-which-key-integration)))
#+end_src #+end_src
I will want to start adding commands under my =SPC m= mode-specific key sequence leader, but in the meantime, all LSP-related keybindings are available under ~⌘-m~. See [[https://emacs-lsp.github.io/lsp-mode/page/keybindings/][this page]] for the default keybindings.
The following was stolen from Dooms configuration: *** UI
The [[https://github.com/emacs-lsp/lsp-ui][lsp-ui]] project offers much of the display and interface to LSP. Seems to make the screen cluttered.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defvar eglot--help-buffer nil) (use-package lsp-ui
:commands lsp-ui-mode
(defun eglot-lookup-documentation () :config
"Request documentation for the thing at point." (setq lsp-ui-sideline-ignore-duplicate t
(interactive) lsp-ui-sideline-show-hover t
(eglot--dbind ((Hover) contents range) lsp-ui-sideline-show-diagnostics t)
(jsonrpc-request (eglot--current-server-or-lose) :textDocument/hover :hook (lsp-mode . lsp-ui-mode))
(eglot--TextDocumentPositionParams))
(let ((blurb (and (not (seq-empty-p contents))
(eglot--hover-info contents range)))
(hint (thing-at-point 'symbol)))
(if blurb
(with-current-buffer
(or (and (buffer-live-p eglot--help-buffer)
eglot--help-buffer)
(setq eglot--help-buffer (generate-new-buffer "*eglot-help*")))
(with-help-window (current-buffer)
(rename-buffer (format "*eglot-help for %s*" hint))
(with-current-buffer standard-output (insert blurb))
(setq-local nobreak-char-display nil)))
(display-local-help))))
'deferred)
#+end_src #+end_src
*** eglot with Consult *** Treemacs
The [[https://github.com/mohkale/consult-eglot][consult-eglot]] project adds a [[file:ha-config.org::*Consult][Consult]] interface to lookup symbols from the LSP server.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package consult-eglot (use-package lsp-treemacs
:general :commands lsp-treemacs-errors-list
(:states 'normal :keymaps 'eglot-mode-map :bind
"g h" '("find apropos" . consult-eglot-symbols) (:map prog-mode-map
"SPC m l s" '("find symbol" . consult-eglot-symbols))) ("s-)" . treemacs))
(:map treemacs-mode-map
("s-)" . treemacs))
:config
(lsp-treemacs-sync-mode 1))
#+end_src
*** Company Completion
The [[https://github.com/tigersoldier/company-lsp][company-lsp]] offers a [[http://company-mode.github.io/][company]] completion backend for [[https://github.com/emacs-lsp/lsp-mode][lsp-mode]]:
#+begin_src emacs-lisp :tangle no
(use-package company-lsp
:config
(push 'company-lsp company-backends))
#+end_src
To options that might be interesting:
- =company-lsp-async=: When set to non-nil, fetch completion candidates asynchronously.
- =company-lsp-enable-snippet=: Set it to non-nil if you want to enable snippet expansion on completion. Set it to nil to disable this feature.
*** iMenu
The [[https://github.com/emacs-lsp/lsp-ui/blob/master/lsp-ui-imenu.el][lsp-imenu]] project offers a =lsp-ui-imenu= function for jumping to functions:
#+begin_src emacs-lisp :tangle no
(use-package lsp-ui-imenu
:straight nil
:after lsp-ui
:config
(ha-prog-leader
"g" '(:ignore t :which-key "goto")
"g m" '("imenu" . lsp-ui-imenu))
(add-hook 'lsp-after-open-hook 'lsp-enable-imenu))
#+end_src #+end_src
*** Display Configuration *** Display Configuration
Using the [[https://github.com/seagle0128/doom-modeline][Doom Modeline]] to add notifications: Using the [[https://github.com/seagle0128/doom-modeline][Doom Modeline]] to add notifications:
@ -595,13 +616,6 @@ First, use =npm= to install the program:
#+begin_src sh #+begin_src sh
npm installl -g @ansible/ansible-language-server npm installl -g @ansible/ansible-language-server
#+end_src #+end_src
Lets assume that all YAML files can have access to this:
#+begin_src emacs-lisp
(use-package eglot
:config
(add-to-list 'eglot-server-programs '(yaml-mode "ansible-language-server" "--stdio")))
#+end_src
** Shell Scripts ** Shell Scripts
While I don't like writing them, I can't get away from them. Check out the goodies in [[https://www.youtube.com/watch?v=LTC6SP7R1hA&t=5s][this video]]. While I don't like writing them, I can't get away from them. Check out the goodies in [[https://www.youtube.com/watch?v=LTC6SP7R1hA&t=5s][this video]].