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
|
;; 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,7 +1586,12 @@ 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)))
|
||||||
|
(concat
|
||||||
|
" "
|
||||||
|
(propertize icon
|
||||||
|
'face `(:inherit ,(get-text-property 0 'face icon))
|
||||||
|
'help-echo (cond
|
||||||
(last-error
|
(last-error
|
||||||
(format "EGLOT\nAn error occured: %s
|
(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)))
|
||||||
|
@ -1601,9 +1605,9 @@ 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
|
'mouse-face '(:box 0)
|
||||||
(let ((map (make-sparse-keymap)))
|
'local-map (let ((map (make-sparse-keymap)))
|
||||||
(cond
|
(cond
|
||||||
(last-error
|
(last-error
|
||||||
(define-key map [mode-line mouse-3]
|
(define-key map [mode-line mouse-3]
|
||||||
|
@ -1620,16 +1624,7 @@ mouse-3: Reconnect to server" nick (eglot--major-mode server)))
|
||||||
#'eglot-shutdown)
|
#'eglot-shutdown)
|
||||||
(define-key map [mode-line mouse-3]
|
(define-key map [mode-line mouse-3]
|
||||||
#'eglot-reconnect)))
|
#'eglot-reconnect)))
|
||||||
map)))
|
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)
|
|
||||||
" "))))
|
" "))))
|
||||||
(add-hook 'eglot--managed-mode-hook #'doom-modeline-update-eglot)
|
(add-hook 'eglot--managed-mode-hook #'doom-modeline-update-eglot)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue