From 053cd3209da1543e3016ab0dd0acb8c517a3e025 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Thu, 8 Dec 2022 03:34:47 +0400 Subject: [PATCH] Emacs LSP with UI are now at a decent place --- .config/emacs/init.org | 226 ++++++++++++++++------------------------- 1 file changed, 89 insertions(+), 137 deletions(-) diff --git a/.config/emacs/init.org b/.config/emacs/init.org index e284538..22c5dca 100644 --- a/.config/emacs/init.org +++ b/.config/emacs/init.org @@ -360,6 +360,7 @@ Emacs is an great operating system, if only it had a good text editor... (evil-set-leader nil (kbd "C-SPC")) (evil-set-leader 'normal (kbd "SPC")) +(evil-global-set-key 'insert (kbd "C-w") #'evil-delete-backward-word) (evil-define-key 'normal 'global (kbd "q") 'avy-goto-word-0) (add-hook 'emacs-startup-hook @@ -538,6 +539,7 @@ The theme of `C-x 4` bindings is that they operate on other windows, so this fun '("\\*compilation\\*" compilation-mode "^\\*vterm\\*" vterm-mode "^\\*Flymake.*" flymake-mode + "^\\*lsp-help\\*" lsp-help-mode ;; "^\\*ansi-term\\*$" term-mode ("^\\*Warnings\\*$" . hide) help-mode @@ -952,93 +954,14 @@ startup. Reason we have to call this is so the vterm fucntion can call `vterm--i #+end_src ** IDE Features -*** LSP/Company +*** Company #+begin_src emacs-lisp -;; (straight-use-package 'yasnippet) -(straight-use-package 'markdown-mode) -;; (straight-use-package 'posframe) - -(straight-use-package 'lsp-mode) -(straight-use-package 'lsp-ui) - -(cl-defmethod lsp-clients-extract-signature-on-hover (contents (_server-id (eql rust-analyzer))) - (-let* (((&hash "value") contents) - (groups (--partition-by (s-blank? it) (s-lines (s-trim value)))) - (sig_group (if (s-equals? "```rust" (car (-third-item groups))) - (-third-item groups) - (car groups))) - (sig (--> sig_group - (--drop-while (s-equals? "```rust" it) it) - (--take-while (not (s-equals? "```" it)) it) - (--map (s-trim it) it) - (s-join " " it)))) - (lsp--render-element (concat "```rust\n" sig "\n```")))) - -;; (setq lsp-ui-peek-always-show t) -;; (setq lsp-ui-sideline-show-hover t) -;; (setq lsp-ui-doc-enable t) -(setq lsp-headerline-breadcrumb-enable nil) -(setq lsp-rust-analyzer-server-display-inlay-hints t) -(setq lsp-rust-analyzer-display-lifetime-elision-hints-enable "skip_trivial") -(setq lsp-rust-analyzer-display-chaining-hints t) -(setq lsp-rust-analyzer-display-lifetime-elision-hints-use-parameter-names nil) -(setq lsp-rust-analyzer-display-closure-return-type-hints t) -(setq lsp-rust-analyzer-display-parameter-hints t) -(setq lsp-rust-analyzer-display-reborrow-hints t) -(setq lsp-rust-analyzer-cargo-watch-command "clippy") -(setq lsp-eldoc-render-all nil) -(setq lsp-eldoc-enable-hover t) -(setq lsp-headerline-breadcrumb-icons-enable t) -(setq lsp-headerline-breadcrumb-segments '(path-up-to-project file symbols)) -;; (setq lsp-idle-delay 0.2) - -;; (defun joe/toggle-linting () -;; (interactive) -;; (if (bound-and-true-p flycheck-mode) -;; () -;; (message "flymake-mode is off"))) - -(straight-use-package 'flycheck) -;; (evil-global-set-key 'normal (kbd "M-e") #'flymake-goto-next-error) -;; (evil-global-set-key 'normal (kbd "M-S-e") #'flymake-goto-prev-error) -;; (evil-global-set-key 'normal (kbd "M-e") ) -;; (evil-global-set-key 'normal (kbd "M-S-e") ) -;; (evil-define-key 'normal 'global (kbd "ee") 'joe/toggle-linting) -(evil-define-key 'normal 'global (kbd "el") #'flycheck-list-errors) -(evil-define-key 'normal 'global (kbd "en") #'flycheck-next-error) -(evil-define-key 'normal 'global (kbd "ep") #'flycheck-previous-error) -(evil-define-key 'normal 'global (kbd "le") 'flycheck-mode) -(evil-define-key 'normal 'global (kbd "lh") 'lsp-headerline-breadcrumb-mode) -(evil-define-key 'normal 'global (kbd "li") 'lsp-rust-analyzer-inlay-hints-mode) -;; (setq doom-modeline-checker-simple-format nil) -;; Define your custom doom-modeline -;; (setq eldoc-echo-area-use-multiline-p t) -;; (setq eldoc-echo-area-prefer-doc-buffer t) -(setq eldoc-idle-delay 0.1) -;; (setq lsp-eldoc-render-all nil) -;; (setq lsp-keymap-prefix "C-c c") -;; (setq eldoc-documentation-strategy ) - -;; (defun joe/eldoc-display-docs (interactive) -;; (interactive (list t)) -;; (with-current-buffer eldoc--doc-buffer -;; (let ((s (buffer-string))) -;; (with-current-buffer (generate-new-buffer "*persisted eldoc*") -;; (insert s) -;; (display-buffer (current-buffer)))))) - -;; (require 'lsp) -;; (lsp-enable-which-key-integration t) ;; (straight-use-package 'eglot) ;; (global-set-key [remap dabbrev-expand] 'hippie-expand) -;; (straight-use-package 'cape) -;; (add-to-list 'completion-at-point-functions #'cape-symbol) -;; (add-to-list 'completion-at-point-functions #'cape-file) -;; (add-to-list 'completion-at-point-functions #'cape-dabbrev) ;; (straight-use-package 'kind-icon) ;; (require 'kind-icon) ;; (setq completion-in-region-function #'consult-completion-in-region) @@ -1048,10 +971,7 @@ startup. Reason we have to call this is so the vterm fucntion can call `vterm--i ;; (lambda (&rest args) ;; (let ((marginalia-classifiers nil)) ;; (apply #'consult-completion-in-region args))))) -;; (setq completion-in-region-function -;; (lambda (&rest args) -;; (let ((marginalia-classifiers nil)) -;; (apply #'consult-completion-in-region args)))) + (setq completion-in-region-function (lambda (&rest args) (apply (if vertico-mode @@ -1063,8 +983,7 @@ startup. Reason we have to call this is so the vterm fucntion can call `vterm--i (require 'company) (setq company-minimum-prefix-length 1) (setq company-tooltip-align-annotations t) - (setq company-minimum-prefix-length 1) -(setq company-transformers '()) +(setq company-minimum-prefix-length 2) (add-to-list 'completion-at-point-functions #'elisp-completion-at-point) (with-eval-after-load 'company @@ -1087,45 +1006,92 @@ startup. Reason we have to call this is so the vterm fucntion can call `vterm--i (setq company-transformers '(company-sort-by-occurrence))) (add-hook 'after-init-hook (lambda () (global-company-mode))) -;; (delete 'elisp-completion-at-point completion-at-point-functions) -;; (delete 'cape-symbol completion-at-point-functions) +#+end_src +*** LSP +#+begin_src emacs-lisp +(straight-use-package 'lsp-mode) +(straight-use-package 'lsp-ui) +(setq lsp-enable-which-key-integration t) +(setq lsp-keymap-prefix "C-c c") -;; (straight-use-package 'corfu) -;; (global-corfu-mode) -;; (setq kind-icon-default-face 'corfu-default) -;; (setq -;; corfu-cycle t ;; Enable cycling for `corfu-next/previous' -;; corfu-auto t ;; Enable auto completion -;; corfu-separator ?\s ;; Orderless field separator -;; corfu-quit-at-boundary nil ;; Never quit at completion boundary -;; corfu-quit-no-match nil ;; Never quit, even if there is no match -;; corfu-preview-current t ;; Disable current candidate preview -;; corfu-preselect-first t ;; Disable candidate preselection -;; corfu-on-exact-match nil ;; Configure handling of exact matches -;; corfu-echo-documentation t ;; Disable documentation in the echo area -;; corfu-scroll-margin 5) ;; Use scroll margin -;; (setq corfu-preview-current t) -;; (add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter) +;; (setq lsp-ui-peek-always-show t) +;; (setq lsp-ui-sideline-show-hover t) +;; (setq lsp-ui-doc-enable t) +(setq lsp-headerline-breadcrumb-enable nil) +(setq lsp-eldoc-enable-hover t) +(setq max-mini-window-height 0.25) +(setq lsp-eldoc-enable-hover t) +(setq lsp-ui-doc-enable nil) +(setq eldoc-echo-area-use-multiline-p 'truncate-sym-name-if-fit) +(setq eldoc-idle-delay 0) +(setq lsp-idle-delay 0.2) -;; (setq-local corfu-auto t -;; corfu-auto-delay 0.1 -;; corfu-auto-prefix 1 -;; completion-styles '(orderless basic)) +;; Signatures +(setq lsp-signature-doc-lines t) +(setq lsp-signature-render-documentation nil) +(setq lsp-eldoc-render-all nil) +(evil-global-set-key 'normal (kbd "M-d") #'lsp-describe-thing-at-point) +(evil-global-set-key 'normal (kbd "le") 'flycheck-mode) +(evil-global-set-key 'normal (kbd "lh") 'lsp-headerline-breadcrumb-mode) +(evil-global-set-key 'normal (kbd "li") 'lsp-rust-analyzer-inlay-hints-mode) +;; (evil-global-set-key 'normal (kbd "ls") 'lsp-) +;; (lsp-request-async "textDocument/hover" (lsp--text-document-position-params) +;; (lambda (docs) (message docs))) -;; (global-set-key (kbd "") -;; (lambda () -;; (interactive) -;; (let ((company-tooltip-idle-delay 0.0)) -;; (company-complete) -;; (and company-candidates -;; (company-call-frontends 'post-command))))) -;; Enable fancy-dabbrev previews everywhere: -;; (global-fancy-dabbrev-mode) -;; (global-set-key [tab] #'fancy-dabbrev-expand-or-indent) -;; (global-set-key (kbd "") 'fancy-dabbrev-backward) -;; (require 'yasnippet) -;; (yas-global-mode 1) +;; This function allows us to extract Rust's true function signature +(cl-defmethod lsp-clients-extract-signature-on-hover (contents (_server-id (eql rust-analyzer))) + (-let* (((&hash "value") contents) + (groups (--partition-by (s-blank? it) (s-lines (s-trim value)))) + (sig_group (if (s-equals? "```rust" (car (-third-item groups))) + (-third-item groups) + (car groups))) + (sig (--> sig_group + (--drop-while (s-equals? "```rust" it) it) + (--take-while (not (s-equals? "```" it)) it) + (--map (s-trim it) it) + (s-join " " it)))) + (lsp--render-element (concat "```rust\n" sig "\n```")))) + +#+end_src +*** Flycheck + +#+begin_src emacs-lisp +(straight-use-package 'flycheck) +;; TODO Add wrapping to these functions +(evil-global-set-key 'normal (kbd "M-e") #'flycheck-next-error) +(evil-global-set-key 'normal (kbd "M-E") #'flycheck-previous-error) +(evil-global-set-key 'normal (kbd "el") #'flycheck-list-errors) +#+end_src +** * Languages +*** Rust +#+begin_src emacs-lisp +(straight-use-package 'rustic) +(straight-use-package 'parsec) ;; Required by evcxr-mode + +(straight-use-package + '(evcxr + :type git + :host github + :repo "serialdev/evcxr-mode")) + +(add-hook 'rust-mode-hook + (lambda () + (evcxr-minor-mode) + (electric-pair-local-mode))) + +(with-eval-after-load 'rustic + ;; Don't autostart + (setq rustic-lsp-setup-p nil) + + (setq lsp-rust-analyzer-server-display-inlay-hints t) + (setq lsp-rust-analyzer-display-lifetime-elision-hints-enable "always") + (setq lsp-rust-analyzer-display-chaining-hints t) + (setq lsp-rust-analyzer-display-lifetime-elision-hints-use-parameter-names t) + (setq lsp-rust-analyzer-display-closure-return-type-hints t) + (setq lsp-rust-analyzer-display-parameter-hints t) + (setq lsp-rust-analyzer-display-reborrow-hints t) + (setq lsp-rust-analyzer-cargo-watch-command "clippy")) #+end_src *** C @@ -1170,24 +1136,10 @@ it doesn't close it. ;; (straight-use-package 'eglot-fsharp) #+end_src -*** Rust -#+begin_src emacs-lisp -(straight-use-package 'rust-mode) -(straight-use-package 'rustic) -(straight-use-package 'parsec) ;; Required by evcxr-mode -(setq rustic-lsp-setup-p nil) -(straight-use-package - '(evcxr - :type git - :host github - :repo "serialdev/evcxr-mode" - :config - (add-hook 'rust-mode-hook #'evcxr-minor-mode))) -;; (straight-use-package 'flycheck) -#+end_src -*** Json +*** Other #+begin_src emacs-lisp (straight-use-package 'json) +(straight-use-package 'markdown-mode) #+end_src ** Magit