diff --git a/ha-programming.org b/ha-programming.org index 54bb4e1..50286a0 100644 --- a/ha-programming.org +++ b/ha-programming.org @@ -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…). Emacs has two LSP projects, and while I have used [[LSP Mode]], but since I don’t have heavy IDE requirements, I am finding that [[eglot]] to be simpler. -*** eglot -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: +*** LSP #+begin_src emacs-lisp - (use-package eglot + (use-package lsp-mode + :commands (lsp lsp-deferred) :init - (setq eglot-connect-timeout 10 - eglot-autoshutdown t) + ;; Let's make lsp-doctor happy with these settings: + (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 + (global-set-key (kbd "s-m") 'lsp) (ha-prog-leader - "w" '(:ignore t :which-key "eglot") - "ws" '("start" . eglot)) + "w" '(:ignore t :which-key "lsp") + "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 - (:states 'normal :keymaps 'eglot-mode-map - "SPC m w r" '("restart" . eglot-reconnect) - "SPC m w b" '("events" . eglot-events-buffer) - "SPC m w e" '("errors" . eglot-stderr-buffer) - "SPC m w q" '("quit" . eglot-shutdown) - "SPC m w Q" '("quit all" . eglot-shutdown-all) + (:states 'normal :keymaps 'lsp-mode-map + "SPC m w r" '("restart" . lsp-reconnect) + "SPC m w b" '("events" . lsp-events-buffer) + "SPC m w e" '("errors" . lsp-stderr-buffer) + "SPC m w q" '("quit" . lsp-shutdown) + "SPC m w Q" '("quit all" . lsp-shutdown-all) - "SPC m l" '(:ignore t :which-key "lsp") - "SPC m l r" '("rename" . eglot-rename) - "SPC m l f" '("format" . eglot-format) - "SPC m l a" '("actions" . eglot-code-actions) - "SPC m l i" '("imports" . eglot-code-action-organize-imports) - "SPC m l d" '("doc" . eglot-lookup-documentation))) + "SPC m l r" '("rename" . lsp-rename) + "SPC m l f" '("format" . lsp-format) + "SPC m l a" '("actions" . lsp-code-actions) + "SPC m l i" '("imports" . lsp-code-action-organize-imports) + "SPC m l d" '("doc" . lsp-lookup-documentation)) + + :hook ((lsp-mode . lsp-enable-which-key-integration))) #+end_src - -The following was stolen from Doom’s configuration: +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. +*** 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 - (defvar eglot--help-buffer nil) - - (defun eglot-lookup-documentation () - "Request documentation for the thing at point." - (interactive) - (eglot--dbind ((Hover) contents range) - (jsonrpc-request (eglot--current-server-or-lose) :textDocument/hover - (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) + (use-package lsp-ui + :commands lsp-ui-mode + :config + (setq lsp-ui-sideline-ignore-duplicate t + lsp-ui-sideline-show-hover t + lsp-ui-sideline-show-diagnostics t) + :hook (lsp-mode . lsp-ui-mode)) #+end_src -*** eglot with Consult -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. +*** Treemacs #+begin_src emacs-lisp - (use-package consult-eglot - :general - (:states 'normal :keymaps 'eglot-mode-map - "g h" '("find apropos" . consult-eglot-symbols) - "SPC m l s" '("find symbol" . consult-eglot-symbols))) + (use-package lsp-treemacs + :commands lsp-treemacs-errors-list + :bind + (:map prog-mode-map + ("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 *** Display Configuration 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 npm installl -g @ansible/ansible-language-server #+end_src - -Let’s 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 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]].