mirror of
https://github.com/correl/doom-modeline.git
synced 2024-11-23 19:19:50 +00:00
Refactor LSP segment.
This commit is contained in:
parent
de442a1c28
commit
6d80564d4a
1 changed files with 44 additions and 49 deletions
|
@ -1521,21 +1521,23 @@ mouse-3: Describe current input method")
|
|||
;; 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)
|
||||
(defun doom-modeline-update-lsp (&rest _)
|
||||
"Update `lsp-mode' status."
|
||||
(setq doom-modeline--lsp
|
||||
(concat
|
||||
" "
|
||||
(let ((icon (if doom-modeline-icon
|
||||
(doom-modeline-icon-faicon "rocket" :v-adjust -0.0575)
|
||||
"LSP"))
|
||||
(workspaces (lsp-workspaces)))
|
||||
(let* ((workspaces (lsp-workspaces))
|
||||
(face (if workspaces 'success 'warning))
|
||||
(icon (doom-modeline-lsp-icon "LSP" face)))
|
||||
(propertize icon
|
||||
'face (let ((face (if workspaces 'success 'warning)))
|
||||
(if doom-modeline-icon
|
||||
`(:height 1.1 :family ,(all-the-icons-icon-family icon) :inherit ,face)
|
||||
face))
|
||||
'face `(:inherit ,(get-text-property 0 'face icon))
|
||||
'help-echo (if workspaces
|
||||
(concat "LSP Connected "
|
||||
(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 ()
|
||||
"Update `eglot' status."
|
||||
(setq doom-modeline--eglot
|
||||
(pcase-let* ((icon (if doom-modeline-icon
|
||||
(doom-modeline-icon-faicon "rocket" :v-adjust -0.0575)
|
||||
"EGLOT"))
|
||||
(server (eglot--current-server))
|
||||
(pcase-let* ((server (eglot--current-server))
|
||||
(nick (and server (eglot--project-nickname server)))
|
||||
(pending (and server (hash-table-count
|
||||
(jsonrpc--request-continuations server))))
|
||||
|
@ -1587,7 +1586,12 @@ mouse-1: Reload to start server")
|
|||
((and pending (cl-plusp pending)) 'warning)
|
||||
(nick 'success)
|
||||
(t 'mode-line)))
|
||||
(help-echo (cond
|
||||
(icon (doom-modeline-lsp-icon "EGLOT" face)))
|
||||
(concat
|
||||
" "
|
||||
(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)))
|
||||
|
@ -1601,9 +1605,9 @@ C-mouse-1: Disply server errors
|
|||
mouse-1: Display server events
|
||||
mouse-2: Quit server
|
||||
mouse-3: Reconnect to server" nick (eglot--major-mode server)))
|
||||
(t "EGLOT Disconnected")))
|
||||
(local-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(t "EGLOT Disconnected"))
|
||||
'mouse-face '(:box 0)
|
||||
'local-map (let ((map (make-sparse-keymap)))
|
||||
(cond
|
||||
(last-error
|
||||
(define-key map [mode-line mouse-3]
|
||||
|
@ -1620,16 +1624,7 @@ mouse-3: Reconnect to server" nick (eglot--major-mode server)))
|
|||
#'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)
|
||||
'local-map local-map)
|
||||
map))
|
||||
" "))))
|
||||
(add-hook 'eglot--managed-mode-hook #'doom-modeline-update-eglot)
|
||||
|
||||
|
|
Loading…
Reference in a new issue