Change to lsp-mode

This commit is contained in:
Alexander Rosenberg 2023-11-03 23:04:36 -07:00
parent d39d3b2d41
commit 3becf805be
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

192
init.el
View File

@ -339,8 +339,8 @@ visual states."
(defun my/consult-setup-minibuffer-completion () (defun my/consult-setup-minibuffer-completion ()
(setq-local completion-in-region-function #'consult-completion-in-region)) (setq-local completion-in-region-function #'consult-completion-in-region))
(evil-declare-motion #'consult-line)) (evil-declare-motion #'consult-line))
(use-package consult-eglot ;; (use-package consult-eglot
:commands consult-eglot-symbols) ;; :commands consult-eglot-symbols)
;; integration for embark and consult ;; integration for embark and consult
(use-package embark-consult (use-package embark-consult
@ -394,32 +394,34 @@ visual states."
;; popup.el ;; popup.el
(use-package popup) (use-package popup)
;; popwin ;; posframe
(use-package posframe) (use-package posframe)
;; flymake ;; flymake
(use-package flymake ;; (use-package flymake
:bind (:map flymake-mode-map ;; :bind (:map flymake-mode-map
("C-c e" . my/flymake-show-diagnostic-at-point) ;; ("C-c e" . my/flymake-show-diagnostic-at-point)
("C-c C-e" . consult-flymake)) ;; ("C-c C-e" . consult-flymake))
:hook (emacs-lisp-mode . flymake-mode) ;; ;; :hook (emacs-lisp-mode . flymake-mode)
:init ;; :init
(defun my/flymake-show-diagnostic-at-point () ;; (defun my/flymake-show-diagnostic-at-point ()
(interactive) ;; (interactive)
(if-let ((pos (point)) ;; (if-let ((pos (point))
(diag (and flymake-mode ;; (diag (and flymake-mode
(get-char-property pos 'flymake-diagnostic))) ;; (get-char-property pos 'flymake-diagnostic)))
(message (flymake--diag-text diag))) ;; (message (flymake--diag-text diag)))
(if (display-graphic-p) ;; (if (display-graphic-p)
(progn ;; (progn
(posframe-show " *flymake-error-posframe*" ;; (posframe-show " *flymake-error-posframe*"
:string message ;; :string message
:position (point) ;; :position (point)
:max-width 80) ;; :max-width 80
(clear-this-command-keys) ;; :border-width 2
(push (read-event) unread-command-events) ;; :border-color "white")
(posframe-hide " *flymake-error-posframe*")) ;; (clear-this-command-keys)
(popup-tip message))))) ;; (push (read-event) unread-command-events)
;; (posframe-hide " *flymake-error-posframe*"))
;; (popup-tip message)))))
;; eldoc ;; eldoc
(use-package eldoc (use-package eldoc
@ -433,54 +435,103 @@ visual states."
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)) (add-hook 'xref-backend-functions #'dumb-jump-xref-activate))
;; eglot ;; eglot
(use-package eglot ;; (use-package eglot
:demand t ;; :demand t
:hook (((c-ts-mode c++-ts-mode java-ts-mode rust-ts-mode python-ts-mode ;; :hook (((c-ts-mode c++-ts-mode java-ts-mode rust-ts-mode python-ts-mode
latex-mode markdown-mode blueprint-ts-mode) . eglot-ensure) ;; latex-mode markdown-mode blueprint-ts-mode) . eglot-ensure)
(eglot-managed-mode . my/-eglot-setup)) ;; (eglot-managed-mode . my/-eglot-setup))
;; :init
;; (defvar my/-eglot-documentation-buffer nil
;; "Buffer for showing documentation for `my/eglot-documentation-at-point'.")
;; (defun my/eglot-documentation-at-point ()
;; "Show documentation for a symbol at point."
;; (interactive)
;; (if-let (server (eglot-current-server))
;; (progn
;; (if-let* (((not (buffer-live-p my/-eglot-documentation-buffer)))
;; (name (generate-new-buffer-name "*eglot documentation*")))
;; (setq my/-eglot-documentation-buffer (generate-new-buffer name)))
;; (eglot-hover-eldoc-function
;; (lambda (info _ _)
;; (if-let (((not (seq-empty-p info)))
;; (buff (current-buffer)))
;; (with-current-buffer my/-eglot-documentation-buffer
;; (read-only-mode -1)
;; (erase-buffer)
;; (insert info)
;; (special-mode)
;; (read-only-mode 1)
;; (when (not (get-buffer-window my/-eglot-documentation-buffer nil))
;; (switch-to-buffer-other-window my/-eglot-documentation-buffer t)
;; (switch-to-buffer-other-window buff t)))))))))
;; (defun my/-eglot-setup ()
;; "Setup eldoc variables for `eglot-managed-mode-hook'."
;; (setq-local eldoc-echo-area-use-multiline-p nil
;; evil-lookup-func #'my/eglot-documentation-at-point)
;; (evil-define-key '(normal motion) 'local
;; "K" #'evil-lookup
;; "gR" #'eglot-rename
;; "gA" #'eglot-code-actions
;; "gs" #'consult-eglot-symbols)
;; (eglot-inlay-hints-mode -1))
;; (setq eglot-autoshutdown t)
;; :config
;; (add-to-list 'eglot-server-programs
;; (cons '(c-mode c-ts-mode c++-mode c++-ts-mode objc-mode)
;; '("clangd" "--all-scopes-completion" "--background-index"
;; "--clang-tidy" "--completion-style=detailed"
;; "--header-insertion=never" "--pch-storage=memory"
;; "--malloc-trim" "--function-arg-placeholders"))))
;; flycheck
(use-package flycheck
:hook (emacs-lisp-mode . flycheck-mode)
:bind (:map flycheck-mode-map
("C-c e" . my/flycheck-show-diagnostic-at-point))
:init :init
(defvar my/-eglot-documentation-buffer nil (setq flycheck-display-errors-function nil)
"Buffer for showing documentation for `my/eglot-documentation-at-point'.") (defun my/flycheck-show-diagnostic-at-point ()
(defun my/eglot-documentation-at-point ()
"Show documentation for a symbol at point."
(interactive) (interactive)
(if-let (server (eglot-current-server)) (if-let ((flycheck-mode)
(errors (flycheck-overlay-errors-at (point)))
(message (apply 'concat
(mapcar
(lambda (error)
(concat "" (flycheck-error-message error) "\n"))
errors))))
(if (display-graphic-p)
(progn (progn
(if-let* (((not (buffer-live-p my/-eglot-documentation-buffer))) (posframe-show " *flycheck-error-posframe*"
(name (generate-new-buffer-name "*eglot documentation*"))) :string message
(setq my/-eglot-documentation-buffer (generate-new-buffer name))) :position (point)
(eglot-hover-eldoc-function :max-width 80
(lambda (info _ _) :border-width 2
(if-let (((not (seq-empty-p info))) :border-color "white")
(buff (current-buffer))) (clear-this-command-keys)
(with-current-buffer my/-eglot-documentation-buffer (push (read-event) unread-command-events)
(read-only-mode -1) (posframe-hide " *flycheck-error-posframe*"))
(erase-buffer) (popup-tip message)))))
(insert info) (use-package consult-flycheck
(special-mode) :bind (:map flycheck-mode-map
(read-only-mode 1) ("C-c C-e" . consult-flycheck)))
(when (not (get-buffer-window my/-eglot-documentation-buffer nil))
(switch-to-buffer-other-window my/-eglot-documentation-buffer t) ;; lsp-mode
(switch-to-buffer-other-window buff t))))))))) (use-package consult-lsp)
(defun my/-eglot-setup () (use-package lsp-mode
"Setup eldoc variables for `eglot-managed-mode-hook'." :hook (((c-ts-mode c++-ts-mode java-ts-mode rust-ts-mode python-ts-mode
(setq-local eldoc-echo-area-use-multiline-p nil latex-mode markdown-mode blueprint-ts-mode) . lsp-mode)
evil-lookup-func #'my/eglot-documentation-at-point) (lsp-mode . my/-setup-lsp-mode-buffer))
(evil-define-key '(normal motion) 'local :init
"K" #'evil-lookup (setq lsp-completion-provider :none)
"gR" #'eglot-rename (defun my/-setup-lsp-mode-buffer ()
"gA" #'eglot-code-actions "Called by `lsp-mode-hook' to setup lsp-mode buffers."
"gs" #'consult-eglot-symbols) (lsp-headerline-breadcrumb-mode -1)
(eglot-inlay-hints-mode -1)) (lsp-inlay-hints-mode -1)
(setq eglot-autoshutdown t) (evil-define-key '(normal visual motion) 'local
:config "gR" #'lsp-rename
(add-to-list 'eglot-server-programs "gA" #'lsp-execute-code-action
(cons '(c-mode c-ts-mode c++-mode c++-ts-mode objc-mode) "gs" #'consult-lsp-symbols)
'("clangd" "--all-scopes-completion" "--background-index" (setq-local evil-lookup-func #'lsp-describe-thing-at-point)))
"--clang-tidy" "--completion-style=detailed"
"--header-insertion=never" "--pch-storage=memory"
"--malloc-trim" "--function-arg-placeholders")))
(advice-add 'eglot-completion-at-point :around #'cape-wrap-buster))
;; yasnippet ;; yasnippet
(use-package yasnippet (use-package yasnippet
@ -652,7 +703,6 @@ COMMAND and COMINT are like `compile'."
;; magit ;; magit
(use-package magit (use-package magit
:bind ("C-x C-y" . magit)
:init :init
(evil-define-key '(normal visual motion) magit-mode-map (evil-define-key '(normal visual motion) magit-mode-map
"s" #'magit-stage-file "s" #'magit-stage-file