Refactor LSP segment.

This commit is contained in:
Vincent Zhang 2019-05-06 21:52:36 +08:00
parent de442a1c28
commit 6d80564d4a

View file

@ -1521,21 +1521,23 @@ mouse-3: Describe current input method")
;; LSP ;; LSP
;; ;;
(defun doom-modeline-lsp-icon (text face)
"Display LSP icon (or TEXT in terminal) with FACE."
(if doom-modeline-icon
(doom-modeline-icon-faicon "rocket" :face face :v-adjust -0.0575)
(propertize text 'face face)))
(defvar doom-modeline--lsp nil) (defvar doom-modeline--lsp nil)
(defun doom-modeline-update-lsp (&rest _) (defun doom-modeline-update-lsp (&rest _)
"Update `lsp-mode' status." "Update `lsp-mode' status."
(setq doom-modeline--lsp (setq doom-modeline--lsp
(concat (concat
" " " "
(let ((icon (if doom-modeline-icon (let* ((workspaces (lsp-workspaces))
(doom-modeline-icon-faicon "rocket" :v-adjust -0.0575) (face (if workspaces 'success 'warning))
"LSP")) (icon (doom-modeline-lsp-icon "LSP" face)))
(workspaces (lsp-workspaces)))
(propertize icon (propertize icon
'face (let ((face (if workspaces 'success 'warning))) 'face `(:inherit ,(get-text-property 0 'face icon))
(if doom-modeline-icon
`(:height 1.1 :family ,(all-the-icons-icon-family icon) :inherit ,face)
face))
'help-echo (if workspaces 'help-echo (if workspaces
(concat "LSP Connected " (concat "LSP Connected "
(string-join (--map (format "[%s]\n" (lsp--workspace-print it)) (string-join (--map (format "[%s]\n" (lsp--workspace-print it))
@ -1572,10 +1574,7 @@ mouse-1: Reload to start server")
(defun doom-modeline-update-eglot () (defun doom-modeline-update-eglot ()
"Update `eglot' status." "Update `eglot' status."
(setq doom-modeline--eglot (setq doom-modeline--eglot
(pcase-let* ((icon (if doom-modeline-icon (pcase-let* ((server (eglot--current-server))
(doom-modeline-icon-faicon "rocket" :v-adjust -0.0575)
"EGLOT"))
(server (eglot--current-server))
(nick (and server (eglot--project-nickname server))) (nick (and server (eglot--project-nickname server)))
(pending (and server (hash-table-count (pending (and server (hash-table-count
(jsonrpc--request-continuations server)))) (jsonrpc--request-continuations server))))
@ -1587,49 +1586,45 @@ mouse-1: Reload to start server")
((and pending (cl-plusp pending)) 'warning) ((and pending (cl-plusp pending)) 'warning)
(nick 'success) (nick 'success)
(t 'mode-line))) (t 'mode-line)))
(help-echo (cond (icon (doom-modeline-lsp-icon "EGLOT" face)))
(last-error (concat
(format "EGLOT\nAn error occured: %s " "
(propertize icon
'face `(:inherit ,(get-text-property 0 'face icon))
'help-echo (cond
(last-error
(format "EGLOT\nAn error occured: %s
mouse-3: clear this status" (plist-get last-error :message))) mouse-3: clear this status" (plist-get last-error :message)))
((and doing (not done-p)) ((and doing (not done-p))
(format "EGLOT\n%s%s" doing (format "EGLOT\n%s%s" doing
(if detail (format "%s" detail) ""))) (if detail (format "%s" detail) "")))
((and pending (cl-plusp pending)) ((and pending (cl-plusp pending))
(format "EGLOT\n%d outstanding requests" pending)) (format "EGLOT\n%d outstanding requests" pending))
(nick (format "EGLOT Connected (%s/%s) (nick (format "EGLOT Connected (%s/%s)
C-mouse-1: Disply server errors C-mouse-1: Disply server errors
mouse-1: Display server events mouse-1: Display server events
mouse-2: Quit server mouse-2: Quit server
mouse-3: Reconnect to server" nick (eglot--major-mode server))) mouse-3: Reconnect to server" nick (eglot--major-mode server)))
(t "EGLOT Disconnected"))) (t "EGLOT Disconnected"))
(local-map
(let ((map (make-sparse-keymap)))
(cond
(last-error
(define-key map [mode-line mouse-3]
#'eglot-clear-status))
((and pending (cl-plusp pending))
(define-key map [mode-line mouse-3]
#'eglot-forget-pending-continuations))
(nick
(define-key map [mode-line C-mouse-1]
#'eglot-stderr-buffer)
(define-key map [mode-line mouse-1]
#'eglot-events-buffer)
(define-key map [mode-line mouse-2]
#'eglot-shutdown)
(define-key map [mode-line mouse-3]
#'eglot-reconnect)))
map)))
(concat
" "
(propertize icon
'face (if doom-modeline-icon
`(:height 1.1 :family ,(all-the-icons-icon-family icon) :inherit ,face)
face)
'help-echo help-echo
'mouse-face '(:box 0) 'mouse-face '(:box 0)
'local-map local-map) 'local-map (let ((map (make-sparse-keymap)))
(cond
(last-error
(define-key map [mode-line mouse-3]
#'eglot-clear-status))
((and pending (cl-plusp pending))
(define-key map [mode-line mouse-3]
#'eglot-forget-pending-continuations))
(nick
(define-key map [mode-line C-mouse-1]
#'eglot-stderr-buffer)
(define-key map [mode-line mouse-1]
#'eglot-events-buffer)
(define-key map [mode-line mouse-2]
#'eglot-shutdown)
(define-key map [mode-line mouse-3]
#'eglot-reconnect)))
map))
" ")))) " "))))
(add-hook 'eglot--managed-mode-hook #'doom-modeline-update-eglot) (add-hook 'eglot--managed-mode-hook #'doom-modeline-update-eglot)